37 lines
943 B
Go
37 lines
943 B
Go
package llm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"eino-project/internal/conf"
|
|
|
|
"github.com/cloudwego/eino-ext/components/model/ollama"
|
|
"github.com/cloudwego/eino/components/model"
|
|
)
|
|
|
|
// newOllamaIntentModel Ollama意图识别模型实例
|
|
func newOllamaIntentModel(c *conf.Bootstrap) (model.ToolCallingChatModel, error) {
|
|
if c == nil || c.Ai == nil || c.Ai.Ollama == nil {
|
|
return nil, fmt.Errorf("AI configuration is missing")
|
|
}
|
|
timeout := 60 * time.Second
|
|
if c.Ai.Ollama.Timeout != nil {
|
|
timeout = c.Ai.Ollama.Timeout.AsDuration()
|
|
}
|
|
modelName := "qwen3:8b"
|
|
if len(c.Ai.Ollama.Models) > 1 && c.Ai.Ollama.Models[1] != "" {
|
|
modelName = c.Ai.Ollama.Models[1]
|
|
}
|
|
model, err := ollama.NewChatModel(context.Background(), &ollama.ChatModelConfig{
|
|
BaseURL: c.Ai.Ollama.Endpoint,
|
|
Timeout: timeout,
|
|
Model: modelName,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create intent model: %w", err)
|
|
}
|
|
return model, nil
|
|
}
|