This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openai): use go-openai client (#295)
Because - Originally, we used `httpclient` to connect directly to OpenAI. Since we are introducing the streaming feature, using the `go-openai` SDK will make the codebase easier to maintain. This commit - Switches to using the `go-openai` client.
- Loading branch information
Showing
20 changed files
with
1,437 additions
and
664 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,57 +1,9 @@ | ||
package openai | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"mime/multipart" | ||
|
||
"github.com/instill-ai/component/internal/util" | ||
) | ||
|
||
const ( | ||
transcriptionsPath = "/v1/audio/transcriptions" | ||
) | ||
|
||
type AudioTranscriptionInput struct { | ||
Audio string `json:"audio"` | ||
Model string `json:"model"` | ||
Prompt *string `json:"prompt,omitempty"` | ||
Temperature *float64 `json:"temperature,omitempty"` | ||
Language *string `json:"language,omitempty"` | ||
} | ||
|
||
type AudioTranscriptionReq struct { | ||
File []byte `json:"file"` | ||
Model string `json:"model"` | ||
Prompt *string `json:"prompt,omitempty"` | ||
Language *string `json:"language,omitempty"` | ||
Temperature *float64 `json:"temperature,omitempty"` | ||
ResponseFormat string `json:"response_format,omitempty"` | ||
} | ||
|
||
type AudioTranscriptionResp struct { | ||
Text string `json:"text"` | ||
Duration float32 `json:"duration"` | ||
} | ||
|
||
func getBytes(req AudioTranscriptionReq) (*bytes.Reader, string, error) { | ||
data := &bytes.Buffer{} | ||
writer := multipart.NewWriter(data) | ||
err := util.WriteFile(writer, "file", req.File) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
util.WriteField(writer, "model", req.Model) | ||
util.WriteField(writer, "response_format", req.ResponseFormat) | ||
if req.Prompt != nil { | ||
util.WriteField(writer, "prompt", *req.Prompt) | ||
} | ||
if req.Language != nil { | ||
util.WriteField(writer, "language", *req.Language) | ||
} | ||
if req.Temperature != nil { | ||
util.WriteField(writer, "temperature", fmt.Sprintf("%f", *req.Temperature)) | ||
} | ||
writer.Close() | ||
return bytes.NewReader(data.Bytes()), writer.FormDataContentType(), nil | ||
Audio string `json:"audio"` | ||
Model string `json:"model"` | ||
Prompt string `json:"prompt,omitempty"` | ||
Temperature float32 `json:"temperature,omitempty"` | ||
Language string `json:"language,omitempty"` | ||
} |
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.