开发者

Openai API continuing conversation

开发者 https://www.devze.com 2022-12-07 21:43 出处:网络
I am playing around with the openAi API and I am trying to continue a conversation. For example: import openai

I am playing around with the openAi API and I am trying to continue a conversation. For example:

import openai
openai.api_key = mykey

prompt= "write me a haiku"


response = openai.Completion.create(engine="text-davinci-001",prompt=prompt
        ,max_tokens=50)
print(response)

This produc开发者_StackOverflow中文版es a Haiku in the following format:

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "text": "\n\n\n\nThis world is\nfull of wonders\nSo much to see and do"
    }
  ],
  "created": 1670379922,
  "id": "cmpl-6KePalYQFhm1cXmwOOJdyKiygSMUq",
  "model": "text-davinci-001",
  "object": "text_completion",
  "usage": {
    "completion_tokens": 17,
    "prompt_tokens": 5,
    "total_tokens": 22
  }
}

Which is great, however, what if I now want to ask openai to "write me another"? If I use the the openai playground chat or chatGPT, I am able to continue a conversation on. I would like to do this via my python script. I notice I receive an id in response. Can I use this somehow to continue my conversation?

Thanks in advance!


The ID in the response is used to identify the particular query that the response is for. The user field as per your identity suggestion in the request body is specifically used by OpenAI to monitor and detect abuse, as outlined in their documentation.

If you want to generate a different result, you can increase the temperature field in the request and simply run it again. Some of the work needs to go to how you engineered your prompts. For more information, please refer to the OpenAI documentation.OpenAI Documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消