forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add form builder * cover VariImage * test for closing errors * simplify tests * add audio api test coverage * don't leak authToken when printed * rename api->client * fix test
- Loading branch information
1 parent
2f3700f
commit 226ff32
Showing
8 changed files
with
270 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package openai | ||
|
||
import ( | ||
"io" | ||
"mime/multipart" | ||
"os" | ||
) | ||
|
||
type formBuilder interface { | ||
createFormFile(fieldname string, file *os.File) error | ||
writeField(fieldname, value string) error | ||
close() error | ||
formDataContentType() string | ||
} | ||
|
||
type defaultFormBuilder struct { | ||
writer *multipart.Writer | ||
} | ||
|
||
func newFormBuilder(body io.Writer) *defaultFormBuilder { | ||
return &defaultFormBuilder{ | ||
writer: multipart.NewWriter(body), | ||
} | ||
} | ||
|
||
func (fb *defaultFormBuilder) createFormFile(fieldname string, file *os.File) error { | ||
fieldWriter, err := fb.writer.CreateFormFile(fieldname, file.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(fieldWriter, file) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (fb *defaultFormBuilder) writeField(fieldname, value string) error { | ||
return fb.writer.WriteField(fieldname, value) | ||
} | ||
|
||
func (fb *defaultFormBuilder) close() error { | ||
return fb.writer.Close() | ||
} | ||
|
||
func (fb *defaultFormBuilder) formDataContentType() string { | ||
return fb.writer.FormDataContentType() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.