openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

request_id is not work

Open tsingyuec opened this issue 3 years ago • 5 comments

Describe the bug

I want to write a simple chatpgt interaction program that can record the history of conversations each time chatgpt talks to the user. According to the suggestion on the web, when chatgpt returns the result, I need to get the request_id of it and pass it to the next conversation. But when I do this, it doesn't work

Here is the result of the run: image

To Reproduce

just run the following code 👇

Code snippets

this is my demo:

import openai
openai.api_key = "sk-......"

contents = [
    "hello, my name is todo",
    "do you know my name in this session"
]
id = None
for content in contents:
    chat = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "user", "content": content}
            ],
            user = "user0001",
            request_id = id
        )
    message = chat.choices[0].message.content
    id = chat.id
    print("message: ", message)


### OS

Linux team317 5.15.90.1-microsoft-standard-WSL2

### Python version

python v3.10

### Library version

openai-python 0.27.2

tsingyuec avatar Mar 30 '23 08:03 tsingyuec

The @try-agaaain, thanks for writing in.

Couple of things:

  1. Never post api key in a repo like this. I would strongly suggest you rotate it if you haven't already
  2. I don't think request_id is a param we had for this API. Where are you seeing that we support that?

hallacy avatar Mar 30 '23 18:03 hallacy

Sorry, I will not expose my api key casually.

I found that the create method of ChatCompletion class will calls super().create(*args, **kwargs), where the super class is EngineAPIResource, and the parameters of this super create method are as follows:

    @classmethod
    def create(
        cls.
        api_key=None.
        api_base=None.
        api_type=None.
        request_id=None.
        api_version=None.
        organization=None.
        **params.
    ).

One of the parameters is request_id, which I mistakenly thought was a supported parameter.

tsingyuec avatar Mar 31 '23 00:03 tsingyuec

If I want to have a continuous conversation via this api, is there a more appropriate way to do it?

tsingyuec avatar Mar 31 '23 01:03 tsingyuec

Ah, interesting. Lemme go look into that request_id field. It's not going to do what you want unfortunately but it would be good for us to have more documentation around the field to avoid confusion

If you want to have a continuous conversation with our models, you'll want to submit all of the previous interactions in the conversation. Our APIs do not currently have a method of retaining the state of a conversation.

hallacy avatar Mar 31 '23 03:03 hallacy

Thank you for your answer.

tsingyuec avatar Mar 31 '23 03:03 tsingyuec