结构修改
This commit is contained in:
parent
3058a1e6b9
commit
3b43d2e7b2
|
@ -9,7 +9,8 @@ ollama:
|
||||||
timeout: "120s"
|
timeout: "120s"
|
||||||
level: "info"
|
level: "info"
|
||||||
format: "json"
|
format: "json"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sys:
|
sys:
|
||||||
session_len: 6
|
session_len: 6
|
||||||
|
|
|
@ -18,6 +18,7 @@ type LangChainService struct {
|
||||||
func NewLangChainGenerate(
|
func NewLangChainGenerate(
|
||||||
client *utils_langchain.UtilLangChain,
|
client *utils_langchain.UtilLangChain,
|
||||||
) *LangChainService {
|
) *LangChainService {
|
||||||
|
|
||||||
return &LangChainService{
|
return &LangChainService{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,10 +194,12 @@ func (r *AiRouterBiz) recognize(ctx context.Context, requireData *entitys.Requir
|
||||||
Content: "意图识别结束",
|
Content: "意图识别结束",
|
||||||
Type: entitys.ResponseLog,
|
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())
|
err = errors.SysErr("数据结构错误:%v", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
requireData.Match = &match
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +267,7 @@ func (r *AiRouterBiz) handleMatch(ctx context.Context, requireData *entitys.Requ
|
||||||
if !requireData.Match.IsMatch {
|
if !requireData.Match.IsMatch {
|
||||||
requireData.Ch <- entitys.Response{
|
requireData.Ch <- entitys.Response{
|
||||||
Index: "",
|
Index: "",
|
||||||
Content: requireData.Match.Reasoning,
|
Content: requireData.Match.Chat,
|
||||||
Type: entitys.ResponseText,
|
Type: entitys.ResponseText,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -48,9 +48,10 @@ func MsgSet(msgType ResponseType, msg string, done bool) []byte {
|
||||||
|
|
||||||
func MsgSend(c *websocket.Conn, msg Response) error {
|
func MsgSend(c *websocket.Conn, msg Response) error {
|
||||||
// 检查上下文是否已取消
|
// 检查上下文是否已取消
|
||||||
|
if msg.Type == ResponseText {
|
||||||
|
|
||||||
|
}
|
||||||
jsonByte, _ := json.Marshal(msg)
|
jsonByte, _ := json.Marshal(msg)
|
||||||
|
|
||||||
return c.WriteMessage(websocket.TextMessage, jsonByte)
|
return c.WriteMessage(websocket.TextMessage, jsonByte)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@ type Match struct {
|
||||||
History []byte `json:"history"`
|
History []byte `json:"history"`
|
||||||
UserInput string `json:"user_input"`
|
UserInput string `json:"user_input"`
|
||||||
Auth string `json:"auth"`
|
Auth string `json:"auth"`
|
||||||
|
Chat string `json:"chat"`
|
||||||
}
|
}
|
||||||
type ChatHis struct {
|
type ChatHis struct {
|
||||||
SessionId string `json:"session_id"`
|
SessionId string `json:"session_id"`
|
||||||
|
|
|
@ -45,10 +45,10 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [
|
||||||
Model: c.config.Model,
|
Model: c.config.Model,
|
||||||
Messages: messages,
|
Messages: messages,
|
||||||
Stream: new(bool), // 设置为false,不使用流式响应
|
Stream: new(bool), // 设置为false,不使用流式响应
|
||||||
Think: &api.ThinkValue{Value: true},
|
Think: &api.ThinkValue{Value: false},
|
||||||
//Tools: tools,
|
Tools: tools,
|
||||||
}
|
}
|
||||||
|
c.client.ListRunning()
|
||||||
err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error {
|
err = c.client.Chat(ctx, req, func(resp api.ChatResponse) error {
|
||||||
res = resp
|
res = resp
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -69,6 +69,11 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
||||||
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 普通对话
|
||||||
|
chat := NewNormalChatTool(m.llm)
|
||||||
|
m.tools[chat.Name()] = chat
|
||||||
|
|
||||||
return m
|
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