微信小程序流式调用扣子智能体

  1. 定义一个 支持SSE请求方法chat_requestTask
function chat_requestTask(authorization, conversation_id, data) {
   
	let header = {
   }
	header['Authorization'] = `Bearer ${
     authorization}`
	header['Content-Type'] = "application/json"
	return uni.request({
   
		url: `https://api.coze.cn/v3/chat?conversation_id=${
     conversation_id}`,
		method: "POST",
		data,
		responseType: 'text',
		header,
		enableChunked: true
	});
}
  1. 定义一个方法,getAnswerByCoze并使用chat_requestTask请求获取答案
export interface paramsType {
   
	authorization: string
	conversation_id: string
	bot_id: string
	user_id: string
}

export interface payloadType {
   
	text: string
	file_url?: string
}
// 通过扣子获取答案
export function getAnswerByCoze(params: paramsType, payload: payloadType, callBack: Function) {
   
	// coze接口参数
	let {
    authorization, conversation_id, bot_id

你可能感兴趣的:(小程序,微信小程序,小程序,ai)