AI Q&A Assistant SDK
Updated: 2025-11-27 23:11:32
Overview
The AI Q&A Assistant SDK is a JavaScript SDK based on the Polyv AI Knowledge Base Q&A Assistant. It provides a Q&A assistant component that can be embedded into web pages. Users can integrate this component into their own web pages to ask questions and get answers from the knowledge base built in the Polyv AI Knowledge Base.
Quick Integration
JS Demo
<script src="https://websdk.videocc.net/ai-chat-bot/latest/polyv-ai-chat-bot.umd.js"></script>
<script>
// AI聊天组件初始化
PolyvAIChatBot.polyvAIChat.init({
aiId: '1159',
getToken: async (viewerId) => {
const response = await fetch(`https://domain/token?viewerId=${viewerId}`); // 替换为实际的获取token的接口
const data = await response.json();
return data.data;
},
customText: {
title: '保利威直播 - 引领直播行业',
placeholder: '输入消息...',
sendButtonText: '发送',
},
customUi: {
themeColor: '#0067C8'
}
});
</script>
- The endpoint for obtaining the token needs to be implemented by the customer and passed as a parameter to the constructed object.
Below is an example code for obtaining a token using Python FastAPI:
Python Example for Obtaining a Token
from fastapi import FastAPI
app = FastAPI()
@app.get("/api/token")
async def get_chat_token(viewerId: str):
"""获取AI答疑助手Token的接口"""
form_data = {
"appId": "# 客户在保利威的appId",
"timestamp": int(time.time() * 1000),
"viewerId": viewerId
}
form_data["sign"] = create_api_sign("# 客户在保利威的secret_key", form_data)
# 发送请求到保利威获取
response = requests.post(
"https://api.polyv.net/live/v3/common/token/get-ai-token",
data=form_data
)
result = response.json()
# 只返回token值
if result.get("code") == 200:
return {
"code": 200,
"message": "success",
"data": result.get('data')
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8002)
- The
appIdandsecret_keyneed to be applied for from Polyv by the customer. For details, please contact Polyv technical support. - For the signature generation rules of the
create_api_signmethod, refer to Signature Generation Rules. - The above code is for reference only. Please adjust the implementation according to the actual situation.
Parameter Description
| Parameter | Type | Description | Required | Default Value |
|---|---|---|---|---|
| aiId | string | AI Q&A Assistant ID. Obtain the corresponding aiId from the Polyv backend -> AI Applications -> AI Q&A Assistant | Yes | None |
| getToken | function | Method to obtain the token, needs to be implemented by the customer | Yes | None |
| position | string | Widget position, supports left and right |
No | right |
| width | string | Widget width | No | 400px |
| height | string | Widget height | No | 600px |
| customText | object | Customizable text content | No | None |
| customText.title | string | Chat window title | No | Polyv AI Assistant |
| customText.placeholder | string | Input box placeholder | No | Enter a message... |
| customText.sendButtonText | string | Send button text | No | Send |
| customUi | object | No | None | |
| customUi.themeColor | string | Theme color | No | #1890ff |
| customUi.widgetIcon | string | Widget icon style | No | Default image |
| customUi.userAvatar | string | User avatar | No | Default image |
| customUi.assistantAvatar | string | AI assistant avatar | No | Default image |
A complete configuration example:
{
aiId: '1159',
getToken: async (viewerId) => {
const response = await fetch(`https://domain/token?viewerId=${viewerId}`); // 替换为实际的获取token的接口
const data = await response.json();
return data.data;
},
position: 'right',
width: '400px',
height: '600px',
customText: {
title: '保利威AI视频 - 引领视频新时代',
placeholder: '输入消息...',
sendButtonText: '发送',
},
customUi: {
themeColor: '#0067C8',
widgetIcon: 'https://domain/widgetIcon.png',
userAvatar: 'https://domain/userAvatar.png',
assistantAvatar: 'https://domain/assistantAvatar.png',
}
}
