Skip to content

Commit

Permalink
config,llm: validate llm_base_url and inherit model name from config
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Dec 21, 2024
1 parent a4f4c10 commit f5e3bd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ var (
)

type Config struct {
Token string `json:"token"`
OpenAIBaseURL string `json:"openai_base_url"`
OpenAIKey string `json:"openai_key"`
Token string `json:"token"`
LLMBaseURL string `json:"llm_base_url"`
LLMModelName string `json:"llm_model_name"`
LLMAPIKey string `json:"llm_api_key"`
}

func (c *Config) Save() error {
Expand Down Expand Up @@ -63,5 +64,9 @@ func (c *Config) validate() error {
if c.Token == "" {
return ErrMissingToken
}

if c.LLMBaseURL != "" && c.LLMModelName == "" {
return errors.New("missing or empty llm_model_name")
}
return nil
}
6 changes: 3 additions & 3 deletions llm/service/custom_llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type customSvc struct {
}

func newCustomService(cfg *config.Config) Service {
baseURL := cfg.OpenAIBaseURL
apiKey := cfg.OpenAIKey
baseURL := cfg.LLMBaseURL
apiKey := cfg.LLMAPIKey

clientConfig := openai.DefaultConfig(apiKey)
clientConfig.BaseURL = baseURL
Expand All @@ -38,7 +38,7 @@ func newCustomService(cfg *config.Config) Service {

return &customSvc{
cl: openaiClient,
modelName: "llama3.2:latest",
modelName: cfg.LLMModelName,
}
}

Expand Down
2 changes: 1 addition & 1 deletion llm/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Service interface {
}

func New(cfg *config.Config) Service {
if cfg.OpenAIBaseURL == "" {
if cfg.LLMBaseURL == "" {
return newDefaultService(cfg)
}
return newCustomService(cfg)
Expand Down

0 comments on commit f5e3bd0

Please sign in to comment.