forked from tmc/langchaingo
/
llm.go
35 lines (27 loc) · 904 Bytes
/
llm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gemini
import (
"errors"
"os"
"github.com/tyloafer/langchaingo/llms/gemini/internal/geminiclient"
)
var (
ErrEmptyResponse = errors.New("no response")
ErrMissingToken = errors.New("missing the OpenAI API key, set it in the OPENAI_API_KEY environment variable") //nolint:lll
ErrMissingAzureEmbeddingModel = errors.New("embeddings model needs to be provided when using Azure API")
ErrUnexpectedResponseLength = errors.New("unexpected length of response")
)
// newClient is wrapper for openaiclient internal package.
func newClient(opts ...Option) (*geminiclient.Client, error) {
options := &options{
token: os.Getenv(tokenEnvVarName),
model: "",
baseURL: "",
}
for _, opt := range opts {
opt(options)
}
if len(options.token) == 0 {
return nil, ErrMissingToken
}
return geminiclient.New(options.token, options.model, options.baseURL)
}