@@ -33,10 +33,7 @@ func main() {
3333 ctx := context .Background ()
3434
3535 // Get ARK_API_KEY and ARK_MODEL_ID: https://www.volcengine.com/docs/82379/1399008
36- chatModel , err := ark .NewChatModel (ctx , & ark.ChatModelConfig {
37- APIKey : os .Getenv ("ARK_API_KEY" ),
38- Model : os .Getenv ("ARK_MODEL_ID" ), // the model needs to support image input, such as Doubao-Seed-1.6.
39- })
36+ chatModel , err := NewChatModel (ctx )
4037 if err != nil {
4138 log .Printf ("NewChatModel failed, err=%v" , err )
4239 return
@@ -46,6 +43,15 @@ func main() {
4643 textToolCall (ctx , chatModel )
4744 fmt .Printf ("\n ==========image tool call==========\n " )
4845 imageToolCall (ctx , chatModel )
46+
47+ fmt .Printf ("\n ==========web search tool call==========\n " )
48+ // Generate a ResponsesAPIChatModel that supports tool web search
49+ responsesAPIChatModel , err := NewResponsesAPIChatModel (ctx )
50+ if err != nil {
51+ log .Printf ("NewResponsesAPIChatModel failed, err=%v" , err )
52+ }
53+ toolWebSearchCall (ctx , responsesAPIChatModel )
54+
4955}
5056
5157func textToolCall (ctx context.Context , chatModel model.ToolCallingChatModel ) {
@@ -179,3 +185,41 @@ func imageToolCall(ctx context.Context, chatModel model.ToolCallingChatModel) {
179185 }
180186 fmt .Printf ("output: \n %v" , resp )
181187}
188+
189+ func toolWebSearchCall (ctx context.Context , chatModel model.ToolCallingChatModel ) {
190+ // You can also enable the built-in web search tool by passing Options during Generate or Stream
191+ //limit := int64(1)
192+ //options := make([]model.Option,0)
193+ //options = append(options, ark.WithEnableToolWebSearch(&ark.EnableToolWebSearch{
194+ // Limit: &limit,
195+ // Sources: []ark.Source{ark.SourceOfMoji},
196+ //}))
197+
198+ resp , err := chatModel .Generate (ctx , []* schema.Message {
199+ {Role : schema .User , Content : "What's the weather like today?" },
200+ })
201+ if err != nil {
202+ log .Fatalf ("WithTools failed, err=%v" , err )
203+ }
204+
205+ fmt .Printf ("output: \n %v" , resp )
206+ }
207+
208+ func NewChatModel (ctx context.Context ) (* ark.ChatModel , error ) {
209+ return ark .NewChatModel (ctx , & ark.ChatModelConfig {
210+ APIKey : os .Getenv ("ARK_API_KEY" ),
211+ Model : os .Getenv ("ARK_MODEL_ID" ),
212+ })
213+ }
214+
215+ func NewResponsesAPIChatModel (ctx context.Context ) (* ark.ResponsesAPIChatModel , error ) {
216+ limit := int64 (1 )
217+ return ark .NewResponsesAPIChatModel (ctx , & ark.ResponsesAPIConfig {
218+ APIKey : os .Getenv ("ARK_API_KEY" ),
219+ Model : os .Getenv ("ARK_MODEL_ID" ),
220+ EnableToolWebSearch : & ark.EnableToolWebSearch {
221+ Limit : & limit ,
222+ Sources : []ark.Source {ark .SourceOfMoji },
223+ },
224+ })
225+ }
0 commit comments