You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coze platform has a substantial user base both internationally and domestically, particularly holding an absolute market share in China. Its workflow encompasses a wide range of aspects with rich functionalities. We look forward to AG2 supporting the Coze workflow API interface.
"""
This example describes how to use the workflow interface to stream chat.
"""
import os
# Our official coze sdk for Python [cozepy](https://github.com/coze-dev/coze-py)
from cozepy import COZE_CN_BASE_URL
# Get an access_token through personal access token or oauth.
coze_api_token = 'cztei_lwnz4drzalMRhIjUhouP4iq8Sae73SOztbEz6GPm88Z6l0Df1pfr5R4I6kYIgEAoL'
# 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 = COZE_CN_BASE_URL
from cozepy import Coze, TokenAuth, Stream, WorkflowEvent, WorkflowEventType # 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 = '7450417915175632930'
# The stream interface will return an iterator of WorkflowEvent. Developers should iterate
# through this iterator to obtain WorkflowEvent and handle them separately according to
# the type of WorkflowEvent.
def handle_workflow_iterator(stream: Stream[WorkflowEvent]):
for event in stream:
if event.event == WorkflowEventType.MESSAGE:
print("got message", event.message)
elif event.event == WorkflowEventType.ERROR:
print("got error", event.error)
elif event.event == WorkflowEventType.INTERRUPT:
handle_workflow_iterator(
coze.workflows.runs.resume(
workflow_id=workflow_id,
event_id=event.interrupt.interrupt_data.event_id,
resume_data="hey",
interrupt_type=event.interrupt.interrupt_data.type,
)
)
handle_workflow_iterator(
coze.workflows.runs.stream(
workflow_id=workflow_id,
)
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Coze platform has a substantial user base both internationally and domestically, particularly holding an absolute market share in China. Its workflow encompasses a wide range of aspects with rich functionalities. We look forward to AG2 supporting the Coze workflow API interface.
Beta Was this translation helpful? Give feedback.
All reactions