package main
import (
"context"
"fmt"
"log"
"os"
"github.com/curaious/uno/internal/utils"
"github.com/curaious/uno/pkg/gateway"
"github.com/curaious/uno/pkg/llm"
"github.com/curaious/uno/pkg/llm/responses"
"github.com/curaious/uno/pkg/sdk"
)
func main() {
client, err := sdk.New(&sdk.ClientOptions{
LLMConfigs: sdk.NewInMemoryConfigStore([]*gateway.ProviderConfig{
{
ProviderName: llm.ProviderNameOpenAI,
ApiKeys: []*gateway.APIKeyConfig{
{Name: "default", APIKey: os.Getenv("OPENAI_API_KEY")},
},
},
}),
})
if err != nil {
log.Fatal(err)
}
model := client.NewLLM(sdk.LLMOptions{
Provider: llm.ProviderNameOpenAI,
Model: "gpt-4o",
})
// Define web search tool
webSearchTool := responses.ToolUnion{
OfWebSearch: &responses.WebSearchTool{
Type: "web_search",
ExternalWebAccess: utils.Ptr(true),
SearchContextSize: utils.Ptr("medium"),
},
}
// Make request with web search
resp, err := model.NewResponses(context.Background(), &responses.Request{
Input: responses.InputUnion{
OfString: utils.Ptr("What are the latest news about artificial intelligence?"),
},
Tools: []responses.ToolUnion{webSearchTool},
})
if err != nil {
log.Fatal(err)
}
// Process response
for _, output := range resp.Output {
if output.OfWebSearchCall != nil {
fmt.Printf("Web search performed: %s\n", output.OfWebSearchCall.ID)
if output.OfWebSearchCall.Action.OfSearch != nil {
fmt.Printf("Query: %s\n", output.OfWebSearchCall.Action.OfSearch.Query)
}
} else if output.OfOutputMessage != nil {
// Model's response using the search results
fmt.Println(output.OfOutputMessage.Content[0].OfOutputText.Text)
}
}
}