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

标签 openai-api chatgpt-api

目前,似乎没有办法在不检查响应内容的情况下确定来自 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/

相关文章:

react-native - 是否修改了react-native openai-api模块以访问ChatGPT API?

openai-api - 是否有本地版本的 chatgpt 不会将任何数据传播到欧盟之外以遵守 GDPR?

node.js - OpenAI API错误: "OpenAIApi is not a constructor"

javascript - OpenAI Api 的输出延迟且随机

azure - OpenAI 嵌入 API : How embeddings work?

openai-api - 如何用ChatGPT批量汇总文本?

openai-api - 如何记住来自不同 ChatCompletion 实例的消息

openai-api - 如何将LangChain Vector Store加上整个文档传递给OpenAI?

openai-api - OpenAI API GPT-3.5 翻译问题 : Incorrect Output for Turkish to Japanese Translation

python - FrozenLake-v1 环境中的渲染问题