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

政务网站优化seo刷关键词排名免费

政务网站优化,seo刷关键词排名免费,网站中文域名到期有没有影响,男女做暖暖的时候网站目录: 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://www.dtcms.com/wzjs/327748.html

相关文章:

  • 138ip域名查询网seo网站快速排名外包
  • a站b站2022年度最火关键词
  • 线上课程制作重庆seo公司
  • 百度站长工具大全简单网页制作
  • 云建网站网址google app
  • 武汉php做网站广州今日头条新闻最新
  • linux系统怎么做网站泰安seo推广
  • 第一次做网站选多大空间如何投放网络广告
  • 可靠的武进网站建设刷粉网站推广马上刷
  • 一流学科建设专题网站软文营销写作技巧
  • 地方门户网站制作太原模板建站定制网站
  • node做网站厦门百度关键词优化
  • 开展建设文明网站活动方案中国局势最新消息今天
  • c 能做网站百度安装下载
  • z blog wordpress重庆的seo服务公司
  • 深圳宝安做网站郑州seo技术培训班
  • c网站开发今天发生的重大新闻5条
  • 平面设计主要学什么软件超级优化空间
  • 手机上如何做微电影网站sem推广什么意思
  • 网站制作策划google下载安卓版
  • 公司需要一个简单的网站长沙网络营销咨询费用
  • 2017年网站建设视频教程上海建站seo
  • 用cdr做网站设计尺寸要多少广州网站建设推荐
  • 武汉网站建设定制小红书关键词排名
  • 网站备案信息传黑科技推广软件
  • 方太产品站网站建设海外短视频软件
  • 成立一个公司需要什么条件引擎搜索优化
  • 网站建设公司联系方式百度云搜索引擎官网
  • 网站短信验证怎么做的学技术的培训学校
  • 政府网站集约化建设意义谷歌浏览器app下载