import (
"context"
"fmt"
"github.com/curaious/uno/pkg/llm/responses"
"github.com/curaious/uno/internal/utils"
)
func main() {
// ... client and model initialization ...
stream, err := model.NewStreamingResponses(context.Background(), &responses.Request{
Instructions: utils.Ptr("You are a personal math tutor. When asked a math question, write and run code using the python tool to answer the question."),
Input: responses.InputUnion{
OfInputMessageList: responses.InputMessageList{
{
OfEasyInput: &responses.EasyMessage{
Role: constants.RoleUser,
Content: responses.EasyInputContentUnion{
OfString: utils.Ptr("I need to solve the equation 3x + 11 = 14. Can you help me?"),
},
},
},
},
},
Tools: []responses.ToolUnion{
{
OfCodeExecution: &responses.CodeExecutionTool{
Container: &responses.CodeExecutionToolContainerUnion{
ContainerConfig: &responses.CodeExecutionToolContainerConfig{
Type: "auto",
MemoryLimit: "4g",
},
},
},
},
},
Parameters: responses.Parameters{
Stream: utils.Ptr(true),
Include: []responses.Includable{
responses.IncludableCodeInterpreterCallOutputs,
},
},
})
if err != nil {
panic(err)
}
for chunk := range stream {
// Check for code execution progress
if chunk.OfCodeInterpreterCallInProgress != nil {
fmt.Println("Code execution started...")
}
// Code is being written incrementally
if chunk.OfCodeInterpreterCallCodeDelta != nil {
delta := chunk.OfCodeInterpreterCallCodeDelta
if delta.Delta != nil {
fmt.Print(*delta.Delta) // Print code as it's being written
}
}
// Code writing is complete
if chunk.OfCodeInterpreterCallCodeDone != nil {
done := chunk.OfCodeInterpreterCallCodeDone
if done.Code != nil {
fmt.Printf("\n\nComplete code:\n%s\n", *done.Code)
}
}
// Code is being executed
if chunk.OfCodeInterpreterCallInterpreting != nil {
fmt.Println("Executing code...")
}
// Code execution is complete
if chunk.OfCodeInterpreterCallCompleted != nil {
fmt.Println("Code execution completed!")
}
// Check for completed output items
if chunk.OfOutputItemDone != nil {
item := chunk.OfOutputItemDone.Item
if item.Type == "code_interpreter_call" {
fmt.Printf("Final code:\n%s\n", item.Code)
fmt.Printf("Outputs:\n%v\n", item.Outputs)
}
}
}
}