Skip to content

Commit 75a2373

Browse files
committed
Refactor response handling to use 'any' type for improved type safety
Signed-off-by: MyMirelHub <[email protected]>
1 parent 7197978 commit 75a2373

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

conversation/go/http/conversation/conversation.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ func main() {
8181
}
8282

8383
// Unmarshal the response
84-
var data map[string]interface{}
84+
var data map[string]any
8585
if err := json.Unmarshal(bodyBytes, &data); err != nil {
8686
log.Fatal(err)
8787
}
8888

8989
// Navigate the new response structure: outputs[0].choices[0].message.content
90-
outputs := data["outputs"].([]interface{})
91-
output := outputs[0].(map[string]interface{})
92-
choices := output["choices"].([]interface{})
93-
choice := choices[0].(map[string]interface{})
94-
message := choice["message"].(map[string]interface{})
90+
outputs := data["outputs"].([]any)
91+
output := outputs[0].(map[string]any)
92+
choices := output["choices"].([]any)
93+
choice := choices[0].(map[string]any)
94+
message := choice["message"].(map[string]any)
9595
result := message["content"].(string)
9696

9797
fmt.Println("Output response:", result)
@@ -155,23 +155,23 @@ func main() {
155155
log.Fatal(err)
156156
}
157157

158-
var data2 map[string]interface{}
158+
var data2 map[string]any
159159
if err := json.Unmarshal(bodyBytes2, &data2); err != nil {
160160
log.Fatal(err)
161161
}
162162

163163
// Parse tool calling response
164-
outputs2 := data2["outputs"].([]interface{})
165-
output2 := outputs2[0].(map[string]interface{})
166-
choices2 := output2["choices"].([]interface{})
167-
choice2 := choices2[0].(map[string]interface{})
168-
message2 := choice2["message"].(map[string]interface{})
164+
outputs2 := data2["outputs"].([]any)
165+
output2 := outputs2[0].(map[string]any)
166+
choices2 := output2["choices"].([]any)
167+
choice2 := choices2[0].(map[string]any)
168+
message2 := choice2["message"].(map[string]any)
169169

170170
if content, ok := message2["content"].(string); ok && content != "" {
171171
fmt.Println("Output message:", content)
172172
}
173173

174-
if toolCalls, ok := message2["toolCalls"].([]interface{}); ok && len(toolCalls) > 0 {
174+
if toolCalls, ok := message2["toolCalls"].([]any); ok && len(toolCalls) > 0 {
175175
fmt.Println("Tool calls detected:")
176176
for _, tc := range toolCalls {
177177
fmt.Printf("Tool call: %v\n", tc)

0 commit comments

Comments
 (0)