- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 python 创建了一个 openAI API,以响应任何类型的提示。
我想让 API 仅响应与产品说明中的广告相关的请求和问候请求,并且如果用户发送的请求与以下内容无关执行此任务时,API 应发送类似我不适合此类任务的消息。
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Completion.create(
model="text-davinci-003",
prompt="Write a creative ad for the following product to run on Facebook aimed at parents:\n\nProduct: Learning Room is a virtual environment to help students from kindergarten to high school excel in school.",
temperature=0.5,
max_tokens=100,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
我想更新代码以生成这样的聊天。 让机器人理解生成广告和问候请求并忽略其他
例如:-
用户:-你好
api:-您好,今天我可以为您的品牌提供什么帮助吗?
用户:- 为以下产品撰写社交媒体帖子,在 Facebook 上针对家长运行:\n\n产品:Learning Room 是一个虚拟环境,可帮助从幼儿园到高中的学生取得优异成绩在学校。
api:- 您是否正在寻找一种让您的 child 在学校取得领先地位的方法?学习室就是您的最佳选择!我们的虚拟环境旨在帮助从幼儿园到高中的学生取得优异的学习成绩。我们独特的平台提供个性化的学习计划、互动事件和实时反馈,以确保您的 child 从教育中获得最大 yield 。通过学习室,为您的 child 提供在学校取得成功的最佳机会!
用户:-美国位于哪里?
api:-我不适合此类任务。
那么,如何更新我的代码?
最佳答案
尝试 gpt3.5-turbo(比 davinci 便宜 10 倍)。
# example in python=3.9 /// openai==0.27.0
import openai
openai.api_key = "YOUR_TOKEN"
messages = []
# be as specific as possible in the behavior it should have
system_content = '''You are a marketing assistant called MarkBot.
You only respond to greetings and marketing-related questions.
For any other question you must answer "I'm not suitable for this type of tasks.".'''
messages.append({"role": "system", "content": system_content})
prompt_text = 'Hi, How can i improve my sellings of cakes?'
messages.append({"role": "user", "content": prompt_text})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
max_tokens=1000,
temperature=0.5)
# In my tests
# Q: 'How many states does Brazil have?'
# A: "I'm not suitable for this type of tasks."
# Q: 'Hi, What can you do? Can you help me sell more cakes?'
# A:
'''"Hello! As a marketing assistant, I can assist you in
developing a marketing plan for your cake business,
including identifying your target audience, creating
advertising materials, and implementing promotional campaigns.
Let me know if you have any specific questions or concerns!"'''
请注意,它不会 100% 准确,但告诉 CHATGPT 应如何表现应该有助于获得您想要的行为。你可以只问一个问题,而不保留上下文。您可能还想降低温度,在文档中您会发现:对于温度,较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定性.
( https://platform.openai.com/docs/guides/chat/instructing-chat-models ).
观察:如果您想保留上下文,据我测试,创建“聊天”功能包括将整个对话添加到“消息”中。因此,如果您希望您的机器人保留对话的上下文(例如chatgpt网站),您需要发送整个对话历史记录+新问题以接收新答案(这在代币方面会更昂贵,但您会得到更好的答案)。
关于python - 如何让openAI API只响应特定类别的请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75744277/
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
OpenAI/chat GPT也支持docx/pdf文件上传吗?。我想上传多个文件到openAI/chatGPT。我在https://platform.openai.com/docs/api-refe
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
如果我们查看环境的预览,它们会在右下角的动画中显示剧集的增加。 https://gym.openai.com/envs/CartPole-v1/ .是否有明确显示的命令? 最佳答案 我认为 Ope
是否有人从使用 text-embedding-ada-002 的 Azure OpenAI 嵌入部署中获得的结果与 OpenAI 的结果不同?相同的文本,相同的模型,结果在向量空间中相差相当远。 对于
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在学习gpt微调 我成功运行了这个命令:pip install --upgrade openai 我无法运行此命令:export OPENAI_API_KEY="sk-xxxxxxxxxxxxxx
如何解决Openai API 不断输出的问题,比如让gpt api 写一篇文章。如果内容中断,可以继续提问,从而继续输出以上内容。这在ChatGPT中很容易做到,但是Openai API加上上面的提示
我是一名优秀的程序员,十分优秀!