Skip to content

Commit

Permalink
add: openai api client
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 committed Apr 15, 2024
1 parent eb3779c commit f2dd6f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bot/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ LIFF_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=

OPENAI_API_KEY=
36 changes: 36 additions & 0 deletions bot/openai/gpt4v.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package openai

import (
"context"
"errors"
"net/http"
"net/url"
"os"
)

var (
ErrNoApiKey = errors.New("apiKey is required")
)

type Gpt4Vision struct {
httpClient *http.Client
endpoint *url.URL
apiKey string
ctx context.Context
}

func NewGpt4Vision(ctx context.Context) (*Gpt4Vision, error) {
c := &Gpt4Vision{
httpClient: http.DefaultClient,
apiKey: os.Getenv("OPENAI_API_KEY"),
ctx: ctx,
}

u, err := url.ParseRequestURI("https://api.openai.com/v1/chat/completions")
if err != nil {
return nil, err
}
c.endpoint = u

return c, nil
}

0 comments on commit f2dd6f1

Please sign in to comment.