Skip to content

Commit d20acac

Browse files
committed
chore: refactor chat
1 parent dbd64c2 commit d20acac

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

examples/cmd/chat/main.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78

@@ -19,24 +20,32 @@ func main() {
1920
err := client.Chat(
2021
context.Background(),
2122
&request.Chat{
22-
ChatHistory: []model.ChatMessage{
23+
Message: "Calculate 12345 + 67890",
24+
Tools: []model.Tool{
2325
{
24-
Role: model.ChatMessageRoleUser,
25-
Message: "Hello, how are you?",
26-
},
27-
{
28-
Role: model.ChatMessageRoleChatbot,
29-
Message: "I'm good, how are you?",
26+
Name: "sum",
27+
Description: "Use this tool to sum two numbers",
28+
ParameterDefinitions: map[string]model.ToolParameterDefinition{
29+
"num1": {
30+
Description: "The first number to sum",
31+
Type: "int",
32+
},
33+
"num2": {
34+
Description: "The second number to sum",
35+
Type: "int",
36+
},
37+
},
3038
},
3139
},
32-
Message: "I'm very happy!",
3340
},
3441
resp,
3542
)
3643
if err != nil {
3744
panic(err)
3845
}
3946

40-
fmt.Printf("resp: %#v\n", resp)
47+
b, _ := json.MarshalIndent(resp, "", " ")
48+
49+
fmt.Printf("%s\n", string(b))
4150

4251
}

model/models.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ const (
213213
)
214214

215215
type StreamedChat struct {
216-
EventType EventType `json:"event_type"`
217-
FinishReason FinishReason `json:"finish_reason"`
218-
Response NonStreamedChat `json:"response"`
216+
EventType EventType `json:"event_type"`
217+
Response NonStreamedChat `json:"response"`
219218
}
220219

221220
type FinishReason string
@@ -240,12 +239,17 @@ const (
240239
)
241240

242241
type NonStreamedChat struct {
243-
Text string `json:"text"`
244-
GenerationID string `json:"generation_id"`
245-
Citations []Citation `json:"citations"`
246-
Documents []Document `json:"documents"`
247-
SearchQueries []SearchQuery `json:"search_queries"`
248-
SearchResults []SearchResult `json:"search_results"`
242+
Text string `json:"text"`
243+
GenerationID string `json:"generation_id"`
244+
Citations []Citation `json:"citations"`
245+
Documents []Document `json:"documents"`
246+
IsSearchRequired bool `json:"is_search_required"`
247+
SearchQueries []SearchQuery `json:"search_queries"`
248+
SearchResults []SearchResult `json:"search_results"`
249+
FinishReason FinishReason `json:"finish_reason"`
250+
ToolCalls []ToolCall `json:"tool_calls"`
251+
ChatHistory []ChatMessage `json:"chat_history"`
252+
ForceSingleStep bool `json:"force_single_step,omitempty"`
249253
}
250254

251255
type SearchResult struct {

0 commit comments

Comments
 (0)