Compare commits
2 Commits
3058a1e6b9
...
b57ad12a68
Author | SHA1 | Date |
---|---|---|
|
b57ad12a68 | |
|
3b43d2e7b2 |
35
config.yaml
35
config.yaml
|
@ -1,35 +0,0 @@
|
|||
server:
|
||||
port: 8090
|
||||
host: "0.0.0.0"
|
||||
|
||||
ollama:
|
||||
base_url: "http://localhost:11434"
|
||||
model: "qwen3:8b"
|
||||
timeout: 30s
|
||||
|
||||
# 模型参数
|
||||
modelParam:
|
||||
temperature: 0.7
|
||||
max_tokens: 2000
|
||||
|
||||
tools:
|
||||
weather:
|
||||
enabled: true
|
||||
calculator:
|
||||
enabled: true
|
||||
zltxOrderDetail: # 直连天下订单详情
|
||||
enabled: true
|
||||
base_url: https://gateway.dev.cdlsxd.cn
|
||||
biz_system: "zltx"
|
||||
zltxOrderLog: # 直连天下订单日志
|
||||
enabled: true
|
||||
base_url: https://gateway.dev.cdlsxd.cn
|
||||
biz_system: "zltx"
|
||||
knowledge: # 知识库
|
||||
enabled: true
|
||||
base_url: http://117.175.169.61:8080
|
||||
api_key: sk-EfnUANKMj3DUOiEPJZ5xS8SGMsbO6be_qYAg9uZ8T3zyoFM-
|
||||
|
||||
logging:
|
||||
level: "info"
|
||||
format: "json"
|
|
@ -5,11 +5,12 @@ server:
|
|||
|
||||
ollama:
|
||||
base_url: "http://127.0.0.1:11434"
|
||||
model: "qwen3-coder:480b-cloud"
|
||||
model: "qwen3:8b"
|
||||
timeout: "120s"
|
||||
level: "info"
|
||||
format: "json"
|
||||
|
||||
|
||||
|
||||
|
||||
sys:
|
||||
session_len: 6
|
||||
|
|
|
@ -18,6 +18,7 @@ type LangChainService struct {
|
|||
func NewLangChainGenerate(
|
||||
client *utils_langchain.UtilLangChain,
|
||||
) *LangChainService {
|
||||
|
||||
return &LangChainService{
|
||||
client: client,
|
||||
}
|
||||
|
|
|
@ -194,10 +194,12 @@ func (r *AiRouterBiz) recognize(ctx context.Context, requireData *entitys.Requir
|
|||
Content: "意图识别结束",
|
||||
Type: entitys.ResponseLog,
|
||||
}
|
||||
if err = json.Unmarshal([]byte(recognizeMsg), requireData.Match); err != nil {
|
||||
var match entitys.Match
|
||||
if err = json.Unmarshal([]byte(recognizeMsg), &match); err != nil {
|
||||
err = errors.SysErr("数据结构错误:%v", err.Error())
|
||||
return
|
||||
}
|
||||
requireData.Match = &match
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -265,7 +267,7 @@ func (r *AiRouterBiz) handleMatch(ctx context.Context, requireData *entitys.Requ
|
|||
if !requireData.Match.IsMatch {
|
||||
requireData.Ch <- entitys.Response{
|
||||
Index: "",
|
||||
Content: requireData.Match.Reasoning,
|
||||
Content: requireData.Match.Chat,
|
||||
Type: entitys.ResponseText,
|
||||
}
|
||||
return
|
||||
|
|
|
@ -48,9 +48,10 @@ func MsgSet(msgType ResponseType, msg string, done bool) []byte {
|
|||
|
||||
func MsgSend(c *websocket.Conn, msg Response) error {
|
||||
// 检查上下文是否已取消
|
||||
if msg.Type == ResponseText {
|
||||
|
||||
}
|
||||
jsonByte, _ := json.Marshal(msg)
|
||||
|
||||
return c.WriteMessage(websocket.TextMessage, jsonByte)
|
||||
}
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ type Match struct {
|
|||
History []byte `json:"history"`
|
||||
UserInput string `json:"user_input"`
|
||||
Auth string `json:"auth"`
|
||||
Chat string `json:"chat"`
|
||||
}
|
||||
type ChatHis struct {
|
||||
SessionId string `json:"session_id"`
|
||||
|
|
|
@ -45,10 +45,10 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [
|
|||
Model: c.config.Model,
|
||||
Messages: messages,
|
||||
Stream: new(bool), // 设置为false,不使用流式响应
|
||||
Think: &api.ThinkValue{Value: true},
|
||||
//Tools: tools,
|
||||
Think: &api.ThinkValue{Value: false},
|
||||
Tools: tools,
|
||||
}
|
||||
|
||||
c.client.ListRunning()
|
||||
err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error {
|
||||
res = resp
|
||||
return nil
|
||||
|
|
|
@ -69,6 +69,11 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
|||
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
}
|
||||
|
||||
// 普通对话
|
||||
chat := NewNormalChatTool(m.llm)
|
||||
m.tools[chat.Name()] = chat
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/entitys"
|
||||
"ai_scheduler/internal/pkg"
|
||||
"ai_scheduler/internal/pkg/utils_ollama"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/ollama/ollama/api"
|
||||
)
|
||||
|
||||
// NormalChatTool 普通对话
|
||||
type NormalChatTool struct {
|
||||
llm *utils_ollama.Client
|
||||
}
|
||||
|
||||
// NewNormalChatTool 实例普通对话
|
||||
func NewNormalChatTool(llm *utils_ollama.Client) *NormalChatTool {
|
||||
return &NormalChatTool{llm: llm}
|
||||
}
|
||||
|
||||
// Name 返回工具名称
|
||||
func (w *NormalChatTool) Name() string {
|
||||
return "normalChat"
|
||||
}
|
||||
|
||||
// Description 返回工具描述
|
||||
func (w *NormalChatTool) Description() string {
|
||||
return "用户想进行一般性问答"
|
||||
}
|
||||
|
||||
type NormalChat struct {
|
||||
ChatContent string `json:"chat_content"`
|
||||
}
|
||||
|
||||
// Definition 返回工具定义
|
||||
func (w *NormalChatTool) Definition() entitys.ToolDefinition {
|
||||
return entitys.ToolDefinition{}
|
||||
}
|
||||
|
||||
// Execute 执行直连天下订单详情查询
|
||||
func (w *NormalChatTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||
var req NormalChat
|
||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||
return fmt.Errorf("invalid zltxOrderDetail request: %w", err)
|
||||
}
|
||||
if req.ChatContent == "" {
|
||||
req.ChatContent = "介绍一下你能做什么"
|
||||
}
|
||||
|
||||
// 这里可以集成真实的直连天下订单详情API
|
||||
return w.chat(requireData, &req)
|
||||
}
|
||||
|
||||
// getMockZltxOrderDetail 获取模拟直连天下订单详情数据
|
||||
func (w *NormalChatTool) chat(requireData *entitys.RequireData, chat *NormalChat) (err error) {
|
||||
err = w.llm.ChatStream(context.TODO(), requireData.Ch, []api.Message{
|
||||
{
|
||||
Role: "system",
|
||||
Content: "你是一个聊天助手",
|
||||
},
|
||||
{
|
||||
Role: "assistant",
|
||||
Content: fmt.Sprintf("聊天记录:%s", pkg.JsonStringIgonErr(requireData.Histories)),
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
Content: requireData.UserInput,
|
||||
},
|
||||
}, w.Name())
|
||||
if err != nil {
|
||||
return fmt.Errorf(":%s", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue