model
This commit is contained in:
parent
b63ae2ba43
commit
a2e9e6e273
7
llm.go
7
llm.go
|
|
@ -16,13 +16,15 @@ import (
|
||||||
type LLMClient struct {
|
type LLMClient struct {
|
||||||
APIKey string
|
APIKey string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
|
Model string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLLMClient constructs a new LLMClient with the given API key and base URL
|
// 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{
|
return &LLMClient{
|
||||||
APIKey: apiKey,
|
APIKey: apiKey,
|
||||||
BaseURL: baseURL,
|
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")
|
logrus.WithFields(logrus.Fields{"api_url": apiURL, "prompt": prompt, "format": format}).Info("[LLM] openAICompletion POST")
|
||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"model": "qwen3:latest",
|
"model": llm.Model, // "qwen3:latest",
|
||||||
"messages": []map[string]string{{"role": "user", "content": prompt}},
|
"messages": []map[string]string{{"role": "user", "content": prompt}},
|
||||||
"stream": false,
|
"stream": false,
|
||||||
"format": format,
|
"format": format,
|
||||||
}
|
}
|
||||||
jsonBody, _ := json.Marshal(body)
|
jsonBody, _ := json.Marshal(body)
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", apiURL, bytes.NewBuffer(jsonBody))
|
req, _ := http.NewRequestWithContext(ctx, "POST", apiURL, bytes.NewBuffer(jsonBody))
|
||||||
|
req.Header.Set("Authorization", "Bearer "+llm.APIKey)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
|
||||||
1
main.go
1
main.go
|
|
@ -23,6 +23,7 @@ func main() {
|
||||||
var llm LLMClientAPI = NewLLMClient(
|
var llm LLMClientAPI = NewLLMClient(
|
||||||
os.Getenv("OPENAI_API_KEY"),
|
os.Getenv("OPENAI_API_KEY"),
|
||||||
os.Getenv("OPENAI_BASE_URL"),
|
os.Getenv("OPENAI_BASE_URL"),
|
||||||
|
os.Getenv("OPENAI_MODEL"),
|
||||||
)
|
)
|
||||||
chatService := NewChatService(llm, &reasonDB)
|
chatService := NewChatService(llm, &reasonDB)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue