package main
import (
"context"
"fmt"
"log"
"os"
"github.com/hastekit/hastekit-sdk-go/pkg/utils"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm/responses"
hastekit "github.com/hastekit/hastekit-sdk-go"
)
func main() {
client, err := hastekit.New(&hastekit.ClientOptions{
ProviderConfigs: []gateway.ProviderConfig{
{
ProviderName: llm.ProviderNameOpenAI,
BaseURL: "",
CustomHeaders: nil,
ApiKeys: []*gateway.APIKeyConfig{
{
Name: "Key 1",
APIKey: os.Getenv("OPENAI_API_KEY"),
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
// 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 := client.NewResponses(context.Background(), &responses.Request{
Model: "OpenAI/gpt-4o",
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)
}
}
}