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

+54 -7
View File
@@ -2,6 +2,7 @@ package domain
import (
"context"
"encoding/json"
"time"
)
@@ -33,6 +34,27 @@ type Message struct {
VersionId string `db:"_version" json:"_version"`
}
func (msg *Message) ToolCall2Json() error {
if msg.ToolCalls != nil {
toolCallJson, err := json.Marshal(&msg.ToolCalls)
if err != nil {
return err
}
msg.ToolCallsJson = string(toolCallJson)
}
return nil
}
func (msg *Message) Json2toolCall() error {
if msg.ToolCallsJson != "" {
err := json.Unmarshal([]byte(msg.ToolCallsJson), &msg.ToolCalls)
if err != nil {
return err
}
}
return nil
}
type ChatWithMessages struct {
Chat *Chat `json:"chat"`
Messages []*Message `json:"messages"`
@@ -44,17 +66,42 @@ type ChatParams struct {
OnChunk StreamCallback
}
type Tool struct {
type Tool interface {
Name() string
Description() string
Definition(ctx context.Context) *ToolDefinition
Execute(ctx context.Context, input []byte) ([]byte, error)
}
type ToolDefinition struct {
Type string
Function *ToolFunction
}
type ToolFunction struct {
Name string
Description string
Parameters map[string]any
}
type ToolCall struct {
ID string
Type string
Function ToolCallFunction
Extra map[string]map[string]any
}
type ToolCallFunction struct {
Name string
Arguments string
}
type Chunk struct {
Done bool `json:"done"`
Role string `json:"role"`
Content string `json:"content"`
Reasoning bool
ToolName string `json:"toolName,omitempty"`
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
Reasoning bool `json:"reasoning,omitempty"`
}
type StreamCallback func(chunk *Chunk)
@@ -69,7 +116,7 @@ const (
)
type LLMParams struct {
Tools []*Tool
Tools []*ToolDefinition
OnChunk StreamCallback
ReasoningEffort string
}
@@ -83,7 +130,7 @@ type LLMEngine interface {
modelID string,
params *LLMParams,
messages []*Message,
) (*Message, error)
) *Message
}
type ChatRepository interface {
@@ -92,6 +139,6 @@ type ChatRepository interface {
CreateChat(userID string, chat *Chat) (*Chat, error)
UpdateChat(userID string, chat *Chat) (*Chat, error)
DeleteChat(userID string, teamID string, id string) error
GetChatMessages(userID string, teamID string, id string) ([]*Message, error)
GetChatMessages(userID string, teamID string, id string, withToolCallResponses bool) ([]*Message, error)
CreateChatMessage(userID string, message *Message) (*Message, error)
}