-
Notifications
You must be signed in to change notification settings - Fork 11
/
workflow_no_stream.py
29 lines (21 loc) · 1.01 KB
/
workflow_no_stream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
This example describes how to use the workflow interface to chat.
"""
import os
from cozepy import COZE_COM_BASE_URL
# Get an access_token through personal access token or oauth.
coze_api_token = os.getenv("COZE_API_TOKEN")
# The default access is api.coze.com, but if you need to access api.coze.cn,
# please use base_url to configure the api endpoint to access
coze_api_base = os.getenv("COZE_API_BASE") or COZE_COM_BASE_URL
from cozepy import Coze, TokenAuth, Message, ChatStatus, MessageContentType # noqa
# Init the Coze client through the access_token.
coze = Coze(auth=TokenAuth(token=coze_api_token), base_url=coze_api_base)
# Create a workflow instance in Coze, copy the last number from the web link as the workflow's ID.
workflow_id = "workflow id"
# Call the coze.workflows.runs.create method to create a workflow run. The create method
# is a non-streaming chat and will return a WorkflowRunResult class.
workflow = coze.workflows.runs.create(
workflow_id=workflow_id,
)
print("workflow.data", workflow.data)