Skip to content

Commit

Permalink
refactor(openai): with context
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Dec 17, 2024
1 parent 4c061e4 commit b5a0b3f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/backend/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@ func openai(c echo.Context, options FullOptions) mo.Result[any] {

payload := fo.May(json.Marshal(values))

res, err := http.Post(
req, err := http.NewRequestWithContext(
c.Request().Context(),
http.MethodPost,
"https://openai.com/v1/audio/speech",
"application/json",
bytes.NewBuffer(payload),
)
if err != nil {
return mo.Err[any](apierrors.NewErrBadRequest().WithCaller())
}

// defer res.Body.Close()
// TODO: Bearer Auth
req.Header.Set("Content-Type", "application/json")

res, err := http.DefaultClient.Do(req)

if err != nil {
return mo.Err[any](apierrors.NewErrBadRequest().WithCaller())
}

defer res.Body.Close()

// body, _ := io.ReadAll(res.Body)

Expand Down

0 comments on commit b5a0b3f

Please sign in to comment.