Skip to content

Issue with maintaining conversation_id for continuing the same chat session in OpenaiChat #2897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kimkibom opened this issue Apr 7, 2025 · 4 comments

Comments

@kimkibom
Copy link

kimkibom commented Apr 7, 2025

I'm using the g4f.ChatCompletion.create method to interact with OpenaiChat with model gpt-4o in a conversational context. However, every time I run the script, a new conversation is created instead of continuing with the same conversation_id.

Here's the code I'm using:

response = g4f.ChatCompletion.create(
    model="gpt-4o",
    provider=OpenaiChat,
    messages=messages,
    history_disabled=False,
    conversation_id="your-conversation-id"
)

I want to continue the conversation with the same conversation_id, but the debug logs show a new conversation being created each time. For example, the log shows:

OpenaiChat: New conversation: 67f40fb7-ea08-8005-ae7e-7XXXXXXXXXX1

This happens every time I run the Python script, even though I pass the same conversation_id. I'm unsure whether I missed something or if there’s a specific way I need to handle session persistence or conversation_id reuse to keep the conversation context intact.

Could someone point out what I might be missing or doing wrong?

@hlohaus
Copy link
Collaborator

hlohaus commented Apr 8, 2025

Please include the conversation ID in the conversation field. Enable return_conversation=True and include it in the "conversation" field of your subsequent request. A parent message ID is also required. @kimkibom

@kimkibom
Copy link
Author

kimkibom commented Apr 8, 2025

Based on your answer, here is the format that you expected, right?

response = g4f.ChatCompletion.create(
    model="gpt-4o",
    provider=OpenaiChat,
    messages=messages,
    return_conversation=True,
    conversation_id="your-conversation-id",
    parent_message_id="your-parent-message-id"
)

However, is there an alternative way to keep the conversation context intact without manually specifying the conversation_id and parent_message_id every time? Or is this a limitation that requires specific configuration or setup?"

@hlohaus
Copy link
Collaborator

hlohaus commented Apr 8, 2025

@kimkibom the API do it automatically, when you pass everytime a self generated conversation_id.

  1. The internal conversation should be a JsonConversation object, when you are using python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@hlohaus @kimkibom and others