Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions components/model/ark/examples/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ func main() {
ctx := context.Background()

// Get ARK_API_KEY and ARK_MODEL_ID: https://www.volcengine.com/docs/82379/1399008
chatModel, err := ark.NewChatModel(ctx, &ark.ChatModelConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"),
})

chatModel, err := NewChatModel(ctx)
if err != nil {
log.Fatalf("NewChatModel failed, err=%v", err)
}

// You can also use ResponsesAPIChatModel
//chatModel, err := NewResponsesAPIChatModel(ctx)
//if err != nil {
// log.Fatalf("NewResponsesAPIChatModel failed, err=%v", err)
//}

inMsgs := []*schema.Message{
{
Role: schema.User,
Expand Down Expand Up @@ -87,3 +89,17 @@ func main() {
respBody, _ = json.MarshalIndent(msg, " ", " ")
log.Printf(" body: %s\n", string(respBody))
}

func NewChatModel(ctx context.Context) (*ark.ChatModel, error) {
return ark.NewChatModel(ctx, &ark.ChatModelConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"),
})
}

func NewResponsesAPIChatModel(ctx context.Context) (*ark.ResponsesAPIChatModel, error) {
return ark.NewResponsesAPIChatModel(ctx, &ark.ResponsesAPIConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"),
})
}
52 changes: 48 additions & 4 deletions components/model/ark/examples/intent_tool/intent_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
ctx := context.Background()

// Get ARK_API_KEY and ARK_MODEL_ID: https://www.volcengine.com/docs/82379/1399008
chatModel, err := ark.NewChatModel(ctx, &ark.ChatModelConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"), // the model needs to support image input, such as Doubao-Seed-1.6.
})
chatModel, err := NewChatModel(ctx)
if err != nil {
log.Printf("NewChatModel failed, err=%v", err)
return
Expand All @@ -46,6 +43,15 @@
textToolCall(ctx, chatModel)
fmt.Printf("\n==========image tool call==========\n")
imageToolCall(ctx, chatModel)

fmt.Printf("\n==========web search tool call==========\n")
// Generate a ResponsesAPIChatModel that supports tool web search
responsesAPIChatModel, err := NewResponsesAPIChatModel(ctx)
if err != nil {
log.Printf("NewResponsesAPIChatModel failed, err=%v", err)
}
toolWebSearchCall(ctx, responsesAPIChatModel)

}

func textToolCall(ctx context.Context, chatModel model.ToolCallingChatModel) {
Expand Down Expand Up @@ -179,3 +185,41 @@
}
fmt.Printf("output: \n%v", resp)
}

func toolWebSearchCall(ctx context.Context, chatModel model.ToolCallingChatModel) {
// You can also enable the built-in web search tool by passing Options during Generate or Stream
//limit := int64(1)
//options := make([]model.Option,0)
//options = append(options, ark.WithEnableToolWebSearch(&ark.EnableToolWebSearch{
// Limit: &limit,
// Sources: []ark.Source{ark.SourceOfMoji},
//}))

resp, err := chatModel.Generate(ctx, []*schema.Message{
{Role: schema.User, Content: "What's the weather like today?"},
})
if err != nil {
log.Fatalf("WithTools failed, err=%v", err)
}

fmt.Printf("output: \n%v", resp)
}

func NewChatModel(ctx context.Context) (*ark.ChatModel, error) {
return ark.NewChatModel(ctx, &ark.ChatModelConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"),
})
}

func NewResponsesAPIChatModel(ctx context.Context) (*ark.ResponsesAPIChatModel, error) {
limit := int64(1)
return ark.NewResponsesAPIChatModel(ctx, &ark.ResponsesAPIConfig{
APIKey: os.Getenv("ARK_API_KEY"),
Model: os.Getenv("ARK_MODEL_ID"),
EnableToolWebSearch: &ark.EnableToolWebSearch{

Check failure on line 220 in components/model/ark/examples/intent_tool/intent_tool.go

View workflow job for this annotation

GitHub Actions / unit-benchmark-test

undefined: ark.EnableToolWebSearch

Check failure on line 220 in components/model/ark/examples/intent_tool/intent_tool.go

View workflow job for this annotation

GitHub Actions / unit-test

undefined: ark.EnableToolWebSearch
Limit: &limit,
Sources: []ark.Source{ark.SourceOfMoji},
},
})
}
Loading