admin 管理员组

文章数量: 1184232

背景

调用cozeAPI后,对流式响应进行处理,参考了网友的文章,并对其进行了优化处理,主要是通过对event,对响应信息进行过滤。过滤出agent的回复内容,以及token使用量。

实现

import requests
import json

BASE_URL = "https://api.coze"

class Coze:
    CONVERSATION_ID = 753798655234154505 # 会话ID
    BOT_ID = "73661703368646435" # 你的bot ID
    USER_ID = "17554977244" # 你的user ID
    HEADERS = {
   
   
        'authorization': 'Bearer 你的token',
        'Content-Type': 'application/json'
    }

    def __init__(self):
        pass

    def updateAuthorization(self, token:str):
        Coze.HEADERS['authorization'] = token

    def Chat(self, message:str):


        url = f"{
     
     BASE_URL}/v3/chat?conversation_id=

本文标签: Coze Chat