"github.com/volcengine/volcengine-go-sdk/service/arkruntime"
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
"github.com/volcengine/volcengine-go-sdk/volcengine"
client := arkruntime.NewClientWithApiKey(
os.Getenv("ARK_API_KEY"),
arkruntime.WithBaseUrl("https://ark.cn-beijing.volces.com/api/v3"),
ctx := context.Background()
fmt.Println("----- streaming request -----")
req := model.CreateChatCompletionRequest{
Model: "doubao-seed-2-1-pro-260628",
Messages: []*model.ChatCompletionMessage{
Role: model.ChatMessageRoleSystem,
Content: &model.ChatCompletionMessageContent{
StringValue: volcengine.String("你是 AI 人工智能助手"),
Role: model.ChatMessageRoleUser,
Content: &model.ChatCompletionMessageContent{
StringValue: volcengine.String("常见的十字花科植物有哪些?"),
stream, err := client.CreateChatCompletionStream(ctx, req)
apiErr := &model.APIError{}
if errors.As(err, &apiErr) {
fmt.Printf("stream chat error: %v\n", apiErr)
recv, err := stream.Recv()
apiErr := &model.APIError{}
if errors.As(err, &apiErr) {
fmt.Printf("stream chat error: %v\n", apiErr)
if len(recv.Choices) > 0 {
fmt.Print(recv.Choices[0].Delta.Content)