Skip to content

Commit

Permalink
Add the API key via a parameter instead of environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxCapacitor2 committed Nov 18, 2024
1 parent 2aaf3b7 commit e7270e1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
} `yaml:"db"`
Embeddings struct {
OpenAIBaseURL string `yaml:"openaiBaseUrl"`
APIKey string `yaml:"apiKey"`
Model string
Dimensions int
ChunkSize int `yaml:"chunkSize"`
Expand Down
4 changes: 2 additions & 2 deletions app/embedding/embedding.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/tmc/langchaingo/llms/openai"
)

func GetEmbeddings(openAIBaseURL string, model string, chunk string) ([]float32, error) {
func GetEmbeddings(openAIBaseURL string, model string, apiKey string, chunk string) ([]float32, error) {

llm, err := openai.New(openai.WithBaseURL(openAIBaseURL), openai.WithEmbeddingModel(model))
llm, err := openai.New(openai.WithBaseURL(openAIBaseURL), openai.WithEmbeddingModel(model), openai.WithToken(apiKey))
if err != nil {
return nil, fmt.Errorf("error setting up LLM for embedding: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/processqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func processEmbedQueue(db database.Database, config *config.Config, src config.S
}
}

vector, err := embedding.GetEmbeddings(config.Embeddings.OpenAIBaseURL, config.Embeddings.Model, item.Content)
vector, err := embedding.GetEmbeddings(config.Embeddings.OpenAIBaseURL, config.Embeddings.Model, config.Embeddings.APIKey, item.Content)
if err != nil {
fmt.Printf("error getting embeddings: %v\n", err)
markFailure()
Expand Down
2 changes: 1 addition & 1 deletion app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func Start(db database.Database, config *config.Config) {

if q != "" && src != nil && len(src) > 0 {

vector, err := embedding.GetEmbeddings(config.Embeddings.OpenAIBaseURL, config.Embeddings.Model, q)
vector, err := embedding.GetEmbeddings(config.Embeddings.OpenAIBaseURL, config.Embeddings.Model, config.Embeddings.APIKey, q)
if err != nil {
response = &httpResponse{
status: 500,
Expand Down
1 change: 1 addition & 0 deletions config-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ embeddings:
# openaiBaseUrl: https://api.openai.com/v1/
# model: text-embedding-3-small
# dimensions: 1536
# apiKey: sk-*************************************

# You can also use any OpenAI-compatible API, like a local Ollama server:
openaiBaseUrl: http://localhost:11434/v1/
Expand Down

0 comments on commit e7270e1

Please sign in to comment.