This commit is contained in:
lehel 2025-09-30 22:34:22 +02:00
parent b63ae2ba43
commit a2e9e6e273
No known key found for this signature in database
GPG Key ID: 9C4F9D6111EE5CFA
2 changed files with 6 additions and 2 deletions

7
llm.go
View File

@ -16,13 +16,15 @@ import (
type LLMClient struct {
APIKey string
BaseURL string
Model string
}
// NewLLMClient constructs a new LLMClient with the given API key and base URL
func NewLLMClient(apiKey, baseURL string) *LLMClient {
func NewLLMClient(apiKey, baseURL string, model string) *LLMClient {
return &LLMClient{
APIKey: apiKey,
BaseURL: baseURL,
Model: model,
}
}
@ -110,13 +112,14 @@ func (llm *LLMClient) openAICompletion(ctx context.Context, prompt string, forma
}
logrus.WithFields(logrus.Fields{"api_url": apiURL, "prompt": prompt, "format": format}).Info("[LLM] openAICompletion POST")
body := map[string]interface{}{
"model": "qwen3:latest",
"model": llm.Model, // "qwen3:latest",
"messages": []map[string]string{{"role": "user", "content": prompt}},
"stream": false,
"format": format,
}
jsonBody, _ := json.Marshal(body)
req, _ := http.NewRequestWithContext(ctx, "POST", apiURL, bytes.NewBuffer(jsonBody))
req.Header.Set("Authorization", "Bearer "+llm.APIKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)

View File

@ -23,6 +23,7 @@ func main() {
var llm LLMClientAPI = NewLLMClient(
os.Getenv("OPENAI_API_KEY"),
os.Getenv("OPENAI_BASE_URL"),
os.Getenv("OPENAI_MODEL"),
)
chatService := NewChatService(llm, &reasonDB)
r := gin.Default()