Skip to content

Commit 9c57dd7

Browse files
committed
chore: migrate examples
1 parent 9239f06 commit 9c57dd7

File tree

3 files changed

+42
-49
lines changed
  • examples

3 files changed

+42
-49
lines changed

examples/chat-completion-accumulating/main.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,40 @@ func main() {
7070
}
7171
}
7272

73-
var tools = []openai.ChatCompletionToolParam{
74-
{
75-
Function: openai.FunctionDefinitionParam{
76-
Name: "get_live_weather",
77-
Description: openai.String("Get weather at the given location"),
78-
Parameters: openai.FunctionParameters{
79-
"type": "object",
80-
"properties": map[string]interface{}{
81-
"location": map[string]string{
82-
"type": "string",
83-
},
73+
var tools = []openai.ChatCompletionToolUnionParam{
74+
openai.ChatCompletionFunctionTool(openai.FunctionDefinitionParam{
75+
Name: "get_live_weather",
76+
Description: openai.String("Get weather at the given location"),
77+
Parameters: openai.FunctionParameters{
78+
"type": "object",
79+
"properties": map[string]any{
80+
"location": map[string]string{
81+
"type": "string",
8482
},
85-
"required": []string{"location"},
8683
},
84+
"required": []string{"location"},
8785
},
88-
},
89-
{
90-
Function: openai.FunctionDefinitionParam{
91-
Name: "get_population",
92-
Description: openai.String("Get population of a given town"),
93-
Parameters: openai.FunctionParameters{
94-
"type": "object",
95-
"properties": map[string]interface{}{
96-
"town": map[string]string{
97-
"type": "string",
98-
},
99-
"nation": map[string]string{
100-
"type": "string",
101-
},
102-
"rounding": map[string]string{
103-
"type": "integer",
104-
"description": "Nearest base 10 to round to, e.g. 1000 or 1000000",
105-
},
86+
}),
87+
openai.ChatCompletionFunctionTool(openai.FunctionDefinitionParam{
88+
Name: "get_population",
89+
Description: openai.String("Get population of a given town"),
90+
Parameters: openai.FunctionParameters{
91+
"type": "object",
92+
"properties": map[string]any{
93+
"town": map[string]string{
94+
"type": "string",
95+
},
96+
"nation": map[string]string{
97+
"type": "string",
98+
},
99+
"rounding": map[string]string{
100+
"type": "integer",
101+
"description": "Nearest base 10 to round to, e.g. 1000 or 1000000",
106102
},
107-
"required": []string{"town", "nation"},
108103
},
104+
"required": []string{"town", "nation"},
109105
},
110-
},
106+
}),
111107
}
112108

113109
// Mock function to simulate weather data retrieval

examples/chat-completion-tool-calling/main.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ func main() {
2222
Messages: []openai.ChatCompletionMessageParamUnion{
2323
openai.UserMessage(question),
2424
},
25-
Tools: []openai.ChatCompletionToolParam{
26-
{
27-
Function: openai.FunctionDefinitionParam{
28-
Name: "get_weather",
29-
Description: openai.String("Get weather at the given location"),
30-
Parameters: openai.FunctionParameters{
31-
"type": "object",
32-
"properties": map[string]interface{}{
33-
"location": map[string]string{
34-
"type": "string",
35-
},
25+
Tools: []openai.ChatCompletionToolUnionParam{
26+
openai.ChatCompletionFunctionTool(openai.FunctionDefinitionParam{
27+
Name: "get_weather",
28+
Description: openai.String("Get weather at the given location"),
29+
Parameters: openai.FunctionParameters{
30+
"type": "object",
31+
"properties": map[string]any{
32+
"location": map[string]string{
33+
"type": "string",
3634
},
37-
"required": []string{"location"},
3835
},
36+
"required": []string{"location"},
3937
},
40-
},
38+
}),
4139
},
4240
Seed: openai.Int(0),
4341
Model: openai.ChatModelGPT4o,

examples/vectorstorefilebatch/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func main() {
1919
for _, arg := range os.Args[2:] {
2020
println("File to upload:", arg)
2121
rdr, err := os.Open(arg)
22-
defer rdr.Close()
2322
if err != nil {
2423
panic("file open failed:" + err.Error())
2524
}
25+
defer rdr.Close()
2626

2727
fileParams = append(fileParams, openai.FileNewParams{
2828
File: rdr,
@@ -60,14 +60,13 @@ func main() {
6060
println("Listing the files from the vector store")
6161

6262
vector := openai.VectorStoreFileBatchListFilesParams{
63-
Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
64-
VectorStoreID: vectorStore.ID,
63+
Order: openai.VectorStoreFileBatchListFilesParamsOrderAsc,
6564
}
6665

6766
q, _ := vector.URLQuery()
6867
println("Vector JSON:", q)
6968

70-
filesCursor, err := client.VectorStores.FileBatches.ListFiles(ctx, batch.ID, vector)
69+
filesCursor, err := client.VectorStores.FileBatches.ListFiles(ctx, vectorStore.ID, batch.ID, vector)
7170

7271
if err != nil {
7372
panic(err)

0 commit comments

Comments
 (0)