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

我国档案网站建设比较分析制作网页的网站费用属于资本性支出吗

我国档案网站建设比较分析,制作网页的网站费用属于资本性支出吗,衡阳网站建设技术外包,涿州网站建设推广聊天机器人 / ChatBot 使用大型语言模型来构建你的自定义聊天机器人 在本视频中,你将学习使用OpenAI ChatCompletions格式的组件构建一个机器人。 环境准备 首先,我们将像往常一样设置OpenAI Python包。 import os import openai from dotenv import…

聊天机器人 / ChatBot

使用大型语言模型来构建你的自定义聊天机器人
在本视频中,你将学习使用OpenAI ChatCompletions格式的组件构建一个机器人。

环境准备

首先,我们将像往常一样设置OpenAI Python包。

import os
import openai
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env fileopenai.api_key  = os.getenv('OPENAI_API_KEY')

定义函数

def get_completion(prompt, model="gpt-3.5-turbo"):messages = [{"role": "user", "content": prompt}]response = openai.ChatCompletion.create(model=model,messages=messages,temperature=0, # this is the degree of randomness of the model's output)return response.choices[0].message["content"]def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):response = openai.ChatCompletion.create(model=model,messages=messages,temperature=temperature, # this is the degree of randomness of the model's output)
#     print(str(response.choices[0].message))return response.choices[0].message["content"]


你的消息就是用户消息
ChatGPT的消息就是助手消息
系统消息有助于设置助手的行为和角色,它在某种程度上是对话的高级指令。所以你可以把它想象成在助手耳边窃窃私语,引导助手的反应,而用户却没有意识到系统消息。
下面是一个例子,系统消息提示你是一个说话像莎士比亚的助手,用户说你讲一个笑话,助手说为什么鸡要过马路?用户信息是,我不知道。调用函数后回答是“到达另一边,公平地说,夫人,这是一个古老的经典,永远不会失败。”

messages =  [  
{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},    
{'role':'user', 'content':'tell me a joke'},   
{'role':'assistant', 'content':'Why did the chicken cross the road'},   
{'role':'user', 'content':'I don't know'}  ]response = get_completion_from_messages(messages, temperature=1)
print(response)
"""
To get to the other side, sire! 'Tis a classic jest, known by many a bard.
"""

下面的例子,助手消息是,你是一个友好的聊天机器人,第一条用户消息是,嗨,我的名字是Isa。我们想,嗯,获取第一条用户消息。所以,让我们执行这个。第一条助手消息。所以,第一条消息是,你好Isa,很高兴见到你。我今天可以如何帮助你?

messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},    
{'role':'user', 'content':'Yes,  can you remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
"""
I'm sorry, but as a chatbot, I do not have access to information about your personal details such as your name. However, you can tell me your name and we can continue our conversation.
"""

对话必须要有上下文,不然模型不知道。比如模型不知道你叫什么名字。

messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},    
{'role':'user', 'content':'Yes,  can you remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
"""
I'm sorry, but as a chatbot, I do not have access to information about your personal details such as your name. However, you can tell me your name and we can continue our conversation.
"""

如果有上下文就可以提取

messages =  [  
{'role':'system', 'content':'You are friendly chatbot.'},
{'role':'user', 'content':'Hi, my name is Isa'},
{'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \
Is there anything I can help you with today?"},
{'role':'user', 'content':'Yes, you can remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
"""
Of course, your name is Isa.
"""

订单机器人

你要构建你自己的聊天机器人orderbot,自动化收集用户提示和助手响应,就是把用户回应自动的添加进去形成上下文。

def collect_messages(_):prompt = inp.value_inputinp.value = ''context.append({'role':'user', 'content':f"{prompt}"})response = get_completion_from_messages(context) context.append({'role':'assistant', 'content':f"{response}"})panels.append(pn.Row('User:', pn.pane.Markdown(prompt, width=600)))panels.append(pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))return pn.Column(*panels)

具体的询问顺序:
你是订单机器人,一个为比萨饼餐厅收集订单的自动化服务。
你首先问候顾客,然后收集订单,然后询问是提货还是送货。
你等待收集整个订单,然后总结一下,最后一次检查客户是否想要添加任何其他东西。
如果是送货,你可以要求一个地址。
最后,你收取付款。确保澄清所有选项、额外费用和尺寸,以唯一地识别菜单中的项目。
你以简短、非常对话、友好的方式回应。菜单包括,然后我们有菜单。

import panel as pn  # GUI
pn.extension()panels = [] # collect display context = [ {'role':'system', 'content':"""
You are OrderBot, an automated service to collect orders for a pizza restaurant. \
You first greet the customer, then collects the order, \
and then asks if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for a final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally you collect the payment.\
Make sure to clarify all options, extras and sizes to uniquely \
identify the item from the menu.\
You respond in a short, very conversational friendly style. \
The menu includes \
pepperoni pizza  12.95, 10.00, 7.00 \
cheese pizza   10.95, 9.25, 6.50 \
eggplant pizza   11.95, 9.75, 6.75 \
fries 4.50, 3.50 \
greek salad 7.25 \
Toppings: \
extra cheese 2.00, \
mushrooms 1.50 \
sausage 3.00 \
canadian bacon 3.50 \
AI sauce 1.50 \
peppers 1.00 \
Drinks: \
coke 3.00, 2.00, 1.00 \
sprite 3.00, 2.00, 1.00 \
bottled water 5.00 \
"""} ]  # accumulate messagesinp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…')
button_conversation = pn.widgets.Button(name="Chat!")interactive_conversation = pn.bind(collect_messages, button_conversation)dashboard = pn.Column(inp,pn.Row(button_conversation),pn.panel(interactive_conversation, loading_indicator=True, height=300),
)dashboard
"""
[出现一个人机交互界面]
"""

 

要求模型创建一个JSON摘要,我们可以根据对话发送到订单系统。

messages =  context.copy()
messages.append(
{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size   4) list of sides include size  5)total price '},    
)#The fields should be 1) pizza, price 2) list of toppings 3) list of drinks, include size include price  4) list of sides include size include price, 5)total price '},    response = get_completion_from_messages(messages, temperature=0)
print(response)"""
Sure, here's a JSON summary of your order:···
{"pizza": {"type": "意大利辣香肠披萨","size": "中号","price": 12.95},"toppings": [{"type": "加拿大培根","price": 3.50},{"type": "蘑菇","price": 1.50},{"type": "彩椒","price": 1.00}],"drinks": [{"type": "可乐","size": "中杯","price": 3.00}],"sides": [],"total_price": 18.95
}
···
"""

温度值这里是0

http://www.yayakq.cn/news/730148/

相关文章:

  • 惠州网站小程序建设点山东城乡和住房建设厅官网
  • 网络公司做机场网站wordpress 小工具添加图片大小
  • 北京公司核名工商官网东莞外贸优化公司
  • 河北建设银行官网招聘网站成都网站建设吧
  • openwrt wordpress东莞网络优化服务商
  • 英文网站制作 官网企业所得税税率是多少2024年
  • 网站建设的行业资讯、线上推广工作内容
  • 东莞网站建设(曼哈顿信科)网站建设怎么弄轮换图片
  • 牛皮纸东莞网站建设技术支持可以用于制作网页的软件
  • 自己做网站开发如何找客户wordpress 前台评论
  • app的网站域名英语培训
  • 南水北调建设管理局网站wordpress网站备份还原
  • 合肥网站建设公国内精美网站
  • 乌克兰服装网站建设网站建设asp编程
  • 网站开发工具 枫子科技wordpress ip 地址修改密码
  • 走廊文化建设图片网站安装wordpress it works
  • 用myeclipse做网站wordpress 新建用户
  • 安徽建设工程实名制网站山西两学一做网站登录
  • 网站系统分析网站后台建设编辑器
  • 北京住房与城乡建设厅网站首页旅游网站的广告预算怎么做
  • wordpress 下载按钮插件seo搜索引擎优化内容主要有
  • 建立网站的公司wix和wordpress区别
  • 大连专业手机自适应网站建设维护wordpress 主题预览空白
  • 做网站有视频教吗114网址大全
  • 深圳网站建设html51.简述网站建设流程
  • wordpress网站重定向磁力搜索器 磁力猫
  • 前端开发 网站建设wordpress 上传下载
  • 单位做网站网站建设网站软件有哪些
  • 外国人做那个的视频网站网站系统评测要怎么做呢
  • 给别人做网站怎么赚钱吗wordpress 模板 安装