prise en charge des outils + weather

This commit is contained in:
fabien committed 2026-10-04 21:03:51 +02:00
1 parent a36f1231cd
commit 0a6ffab050
14 files changed
+623 -113

No files matched your search

+68 -15
View File
@@ -21,10 +21,16 @@ type ChatSession struct {
mu sync.Mutex
}
func (s *ChatSession) run(ctx context.Context) (*domain.Message, error) {
func (s *ChatSession) run(ctx context.Context) error {
params := &domain.LLMParams{}
tools := make([]*domain.ToolDefinition, 0)
for _, t := range allTools {
tools = append(tools, t.Definition(ctx))
}
params.Tools = tools
s.mu.Lock()
if len(s.subscribers) > 0 {
params.OnChunk = func(chunk *domain.Chunk) {
@@ -40,19 +46,66 @@ func (s *ChatSession) run(ctx context.Context) (*domain.Message, error) {
Content: s.agent.SystemPrompt,
}
// TODO : loop with tools
msg, err := s.llmEngine.Stream(
ctx,
s.provider,
s.modelID,
params,
append([]*domain.Message{systemPrompt}, s.messages...),
)
if err != nil {
return nil, err
}
msg.ChatID = s.chatID
msg.TeamID = s.teamID
continue_loop := true
return s.repoChat.CreateChatMessage(s.userID, msg)
// LOOP on TOOLS
for continue_loop {
msg := s.llmEngine.Stream(
ctx,
s.provider,
s.modelID,
params,
append([]*domain.Message{systemPrompt}, s.messages...),
)
msg.ChatID = s.chatID
msg.TeamID = s.teamID
msg, err := s.repoChat.CreateChatMessage(s.userID, msg)
if err != nil {
return err
}
s.messages = append(s.messages, msg)
// TOOL
if len(msg.ToolCalls) > 0 {
continue_loop = true
for _, tc := range msg.ToolCalls {
tool := GetTool(tc.Function.Name)
output, err := tool.Execute(ctx, []byte(tc.Function.Arguments))
var toolResponse *domain.Message
if err != nil {
toolResponse = &domain.Message{
ChatID: s.chatID,
TeamID: s.teamID,
ToolCallID: tc.ID,
Role: string(domain.RoleTool),
Content: "ERROR: " + err.Error(),
}
} else {
toolResponse = &domain.Message{
ChatID: s.chatID,
TeamID: s.teamID,
ToolCallID: tc.ID,
Role: string(domain.RoleTool),
Content: string(output),
}
}
toolResponse, err = s.repoChat.CreateChatMessage(s.userID, toolResponse)
if err != nil {
return err
}
s.messages = append(s.messages, toolResponse)
}
} else {
continue_loop = false
}
// END TOOL
}
// END LOOP
return nil
}