gpt4 book ai didi

openai-api - ChatGPT - 确定响应是否为 "not unknown"的方法?

转载 作者:行者123 更新时间:2023-12-02 05:48:57 25 4
gpt4 key购买 nike

目前,似乎没有办法在不检查响应内容的情况下确定来自 chatgpt 的响应是否模糊/未知。

    import openai

# Set up OpenAI API client
openai.api_key = 'YOUR_API_KEY'

# Define your prompt and additional messages
prompt = '...'
messages = [{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'What is the capital of France?'}]

# Generate the API response
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
...
)

# Retrieve the generated message
generated_message = response['choices'][0]['message']['content']

# Check if the response is empty or vague
if not generated_message.strip():
print("ChatGPT couldn't generate a suitable response.")
elif "I'm not sure" in generated_message or "I don't know" in generated_message:
print("ChatGPT is uncertain about the answer.")
else:
print("ChatGPT provided a response.")

是否有更好的方法来检查 chatgpt API 是否基本上回答“我不知道”?

最佳答案

您可以指定您希望 ChatGPT 说“我不知道”。在 role: system 部分,然后相应地解析答案。

通过指定我的意思是就像这些例子一样; https://platform.openai.com/examples/default-factual-answering

关于openai-api - ChatGPT - 确定响应是否为 "not unknown"的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76685545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com