Skip to content

Fix storing and passing previous messages to API - #449

Open
niquepolice wants to merge 1 commit into
father-bot:mainfrom
niquepolice:main
Open

Fix storing and passing previous messages to API#449
niquepolice wants to merge 1 commit into
father-bot:mainfrom
niquepolice:main

Conversation

@niquepolice

Copy link
Copy Markdown

Critical bug: conversation history is lost, bot remembers only the current message

Current version does not pass chat history to the API correctly: vision_message_handle_fn introduced new format for saving user messages

new_dialog_message = {"user": [{"type": "text", "text": message}], "bot": answer, "date": datetime.now()}

and _generate_prompt_messages has been changed accordingly.
But in message_handle_fn it is still

new_dialog_message = {"user": _message, "bot": answer, "date": datetime.now()}

Call of extend(dialog_message["user"]) for the dialog message saved in message_handle_fn results in splitting dialog_message["user"]= _message of type str into symbols, thus the structure in response is messed and API returns
something like error_code=None error_message="'$.messages[3].content' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference." error_param=None error_type=invalid_request_error message='OpenAI API error received' stream_error=False chatgpt_telegram_bot | 2024-04-09 18:47:58 DEBUG: message='Request to OpenAI API' method=post path=https://api.openai.com/v1/chat/completions
and finally ignores the conversation context.

@niquepolice niquepolice mentioned this pull request Apr 9, 2024
@father-bot
father-bot force-pushed the main branch 4 times, most recently from fd778d9 to 755f0a7 Compare June 14, 2026 09:30
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

Successfully merging this pull request may close these issues.

1 participant