目录
背景:
一、模型选择
二、操作流程
三、核心代码展示
背景:
成功设置自己的知识库,语音交互问答会优先选择自己的知识库的答案进行回答,减少了耗时
一、模型选择
商汤 商量日日新
二、操作流程
文档中心 | 日日新开放平台 (sensenova.cn)
按照这个走就没事
三、核心代码展示
import sensenovaclass SimpleChatBot:def __init__(self, access_key_id, secret_access_key):# 设置访问密钥sensenova.access_key_id = access_key_idsensenova.secret_access_key = secret_access_key# 创建会话resp = sensenova.ChatSession.create(system_prompt=[{"role": "system","content": "You are a translation expert."}])self.session_id = resp["session_id"]def get_response(self, text):# 生成对话resp = sensenova.ChatConversation.create(action="next",max_new_tokens=10,content=text,model="SenseChat",stream=False, # 非流式输出session_id=self.session_id,knowledge_config={"control_level": "normal","knowledge_base_result": True,"knowledge_base_configs": []},plugins={"associated_knowledge": {"content": " string","mode": "concatenate"},"web_search": {"search_enable": True,"result_enable": True},})if __name__ == "__main__":access_key_id = ""secret_access_key = ""bot = SimpleChatBot(access_key_id, secret_access_key)# 提示用户输入文本并获取回答while True:user_input = input("User: ")if user_input.lower() == "exit": # 输入exit退出对话print("Conversation ended.")breakresponse = bot.get_response(user_input)print("Assistant:", response)