You need to set the context for QA by using /api/v1/streaming-avatar/set-qa-context. We provide basic QA function by prompt engineering. For more advanced QA capabilities, such as Retrieval-Augmented Generation (RAG), you will need to implement the QA logic yourself. In this case, you can use the Speak/api/v1/streaming-avatar/speak API to directly control what the avatar says. If you want to get the avatar says from /api/v1/streaming-avatar/ask, please use
type StreamData = {
type: 'QA';
message: string;
pos?: 'start' | 'middle' | 'end';
};
rtcClient.on('stream-message', onStreamMessage);
const onStreamMessage = (uid, message) => {
let data: Record<string, any>;
try {
message = new TextDecoder().decode(message);
console.log(`receice ${message} from ${uid}`);
data = JSON.parse(message);
} catch (e) {
console.error('invalid json string:', message);
return;
}
if (data.type === 'QA') {
// todo Logic for handling reply messages
}
};
Request
Authorization
Provide your bearer token in the
Authorization
header when making requests to protected resources.