当前位置: 首页 > wzjs >正文

新浪云sae免费wordpress网站vue网页模板免费

新浪云sae免费wordpress网站,vue网页模板免费,wordpress微信分享网页带图,谷歌ads目录: 1、使用背景2、实现代码3、Gradio 的 yield 机制 1、使用背景 比如所有易建联是什么时候退役的?使用大模型对这种实事回答不准确,需要通过联网搜索处理。 正确答案应该是2023年8月29日退役。 2、实现代码 # import gradio as gr# d…

目录:

    • 1、使用背景
    • 2、实现代码
    • 3、Gradio 的 yield 机制

1、使用背景

比如所有易建联是什么时候退役的?使用大模型对这种实事回答不准确,需要通过联网搜索处理。
在这里插入图片描述
正确答案应该是2023年8月29日退役。
在这里插入图片描述

2、实现代码

在这里插入图片描述
在这里插入图片描述

# import gradio as gr# def reverse_text(text):
#     return text[::-1]# demo=gr.Interface(fn=reverse_text,inputs="text",outputs="text")# demo.launch(share="True")import gradio as gr
import openai
from typing import List, Any, Iterator# 配置DeepSeek API
api_key = "xxxxxxxxxxxxxxxxxxxxxx"
api_base = "xxxxxxxxxxxxxxxxxxxxxx"client = openai.OpenAI(api_key=api_key, base_url=api_base)search_results = "易建联于2023年8月29日深夜通过个人社交媒体宣布正式退役‌,结束了他21年的职业篮球生涯。‌‌"
#这里我是预设的答案,具体可以调用谷歌搜索引擎api或者通过python去爬取网页获取;我这里图简单对于这种实事不准确的优先返回人工验证的正确答案
preset_answer = "易建联于2023年8月29日深夜通过个人社交媒体宣布正式退役。"def chat_stream(message: str, #用户输入的问题history: List[List[str]], temperature: float = 0.7,top_k: int = 40,system_prompt: str = "你是一个有帮助的助手。") -> Iterator[Any]:"""流式输出DeepSeek响应"""# 检查是否是特定问题if message.strip() == "易建联什么时候退役的":yield preset_answerreturnmessages = [{"role": "system", "content": system_prompt}]# 添加历史记录for human_msg, ai_msg in history:messages.append({"role": "user", "content": human_msg})messages.append({"role": "assistant", "content": ai_msg})# 添加当前消息messages.append({"role": "user", "content": message})# 调用API进行流式输出response = client.chat.completions.create(model="Qwen/Qwen2.5-VL-72B-Instruct",messages=messages,# 包含系统提示+历史对话+当前问题temperature=temperature,top_p=1-(1.0/top_k) if top_k > 1 else 1.0,stream=True# 启用流式输出)full_response = ""for chunk in response:if chunk.choices and len(chunk.choices) > 0:content = chunk.choices[0].delta.contentif content:full_response += contentyield full_response# 每次迭代更新聊天窗口# 自定义CSS样式
custom_css = """
#chatbot {height: 600px !important;border-radius: 10px;border: 1px solid #e0e0e0;font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
}
.message {padding: 10px;border-radius: 5px;margin: 5px 0;font-size: 15px;line-height: 1.6;
}
.user-message {background-color: #e3f2fd;
}
.bot-message {background-color: #f5f5f5;
}
.gradio-container {font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
}
"""# 创建Gradio界面
with gr.Blocks(title="DeepSeek 智能助手", css=custom_css, theme=gr.themes.Soft()) as demo:gr.Markdown("""# 🤖 DeepSeek 智能助手欢迎使用 DeepSeek 智能助手!您可以通过右侧的设置来调整 AI 的行为。""")with gr.Row():with gr.Column(scale=4):chatbot = gr.Chatbot(height=600,bubble_full_width=False,show_copy_button=True,elem_id="chatbot")with gr.Row():msg = gr.Textbox(label="输入消息",placeholder="在这里输入您的问题...",scale=8,container=False)submit_btn = gr.Button("发送", variant="primary", scale=1)with gr.Row():clear = gr.Button("清除历史", variant="secondary")with gr.Column(scale=1):system_prompt = gr.Textbox(label="系统提示词",value="你是一个有帮助的助手。",lines=3)temperature = gr.Slider(minimum=0.1,maximum=1.0,value=0.7,step=0.1,label="温度",info="较高的值会使输出更加随机,较低的值会使输出更加确定")top_k = gr.Slider(minimum=1,maximum=100,value=40,step=1,label="Top K",info="控制输出词汇的多样性")#user函数清空输入框,更新聊天历史def user(user_message, history):return "", history + [[user_message, None]]def bot(history, temp, top_k_val, sys_prompt):history[-1][1] = ""# 初始化助手回复为空字符串for response in chat_stream(history[-1][0], history[:-1], temp, top_k_val, sys_prompt):#调用大模型的回答history[-1][1] = response# 逐步更新回答yield history# 流式返回msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, [chatbot, temperature, top_k, system_prompt], chatbot)#点击发送时触发此方法调用user函数,user处理完成后调用bot函数submit_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, [chatbot, temperature, top_k, system_prompt], chatbot)clear.click(lambda: None, None, chatbot, queue=False)if __name__ == "__main__":demo.launch()

3、Gradio 的 yield 机制

  • Gradio 的 yield 机制:

每次 yield full_response 会实时更新 chatbot 组件的当前回复部分(history[-1][1])。

  • 最终状态:

当流式结束时,chatbot 中会显示完整的对话记录,例如:

[[“易建联什么时候退役的”, “易建联于2023年8月29日深夜通过个人社交媒体宣布正式退役。”]]


文章转载自:

http://jgFfU7MY.zsLtw.cn
http://LFOr06hP.zsLtw.cn
http://OYY53vPW.zsLtw.cn
http://pGsauJin.zsLtw.cn
http://pI4R7w3Z.zsLtw.cn
http://1tFkvxaE.zsLtw.cn
http://vOWBHDm3.zsLtw.cn
http://uyP3WHj1.zsLtw.cn
http://IomHIENx.zsLtw.cn
http://dbSy2zbo.zsLtw.cn
http://h1tDiJWq.zsLtw.cn
http://cvsYh80T.zsLtw.cn
http://JA4XxUHT.zsLtw.cn
http://1Kz0sozi.zsLtw.cn
http://QGBtNQVH.zsLtw.cn
http://D5vjGU8e.zsLtw.cn
http://piJ5PKUl.zsLtw.cn
http://I3gw8Xi6.zsLtw.cn
http://w6PLRVq2.zsLtw.cn
http://hwPkB0YS.zsLtw.cn
http://EFhZpmSw.zsLtw.cn
http://XTTGsCF5.zsLtw.cn
http://b4TCGtj4.zsLtw.cn
http://ZTVRJkHB.zsLtw.cn
http://WCWs1uXo.zsLtw.cn
http://QWoOm991.zsLtw.cn
http://NHAmM78o.zsLtw.cn
http://V2cEjAnW.zsLtw.cn
http://4WCirovT.zsLtw.cn
http://5vJ8XZqN.zsLtw.cn
http://www.dtcms.com/wzjs/638799.html

相关文章:

  • 女生做网站后期维护工作好吗高端公司网站
  • 怎么做网站优化排名到前面中国500强排名完整版
  • 指定关键字 网站有更新就提醒食品经营许可网站增项怎么做
  • 盐城专业做网站的公司哪家好互联网装修公司排名
  • 福州免费做网站网上免费自己设计商标
  • wordpress私人建站主题代码素材网站
  • 做网站点子帝国cms网站搬家教程
  • 企业为何要做网站公司邮箱一般用哪种
  • 如何查询网站是谁做的宁波seo排名方案优化
  • 网站怎么做rss订阅功能四川省德阳市建设招投标网站
  • 建购物网站 资质中职国示范建设网站
  • linux做网站教程网站编程基础
  • 网站开发定制合同seo指的是
  • wordpress主题图片怎么换快速优化排名公司推荐
  • 南昌网站seo费用电脑课程培训零基础
  • 网站开发方法简答题十堰网站开发培训
  • 现在个人做网站还能盈利吗管理咨询公司起名大气上口的
  • 午夜资源站如何搭建aspx网站
  • 哈尔滨网站建设学校长城建设投资有限公司网站
  • 做跨境电商网站的意义建设银行打印回单网站
  • 南京网站微信建设消防器材厂家东莞网站建设
  • 衡水商城网站建设公司网站点击量如何看
  • 做爰全过程网站免费的视频vue做的博客网站
  • 沧州高端网站建设企业域名如何申请
  • seo网站推广专员招聘惠州市企业网站seo营销工具
  • 视频收费网站怎么做上海jsp网站建设
  • 旅游电网站建设目标企业类网站有哪些例子
  • .asp网站怎么做网上做ps赚钱的网站
  • 比特币交易网站开发深圳百度推广
  • 新乡网站建设找哪家深圳网站建设公司是