Add list typing to the updated_messages temporary variable

This commit is contained in:
sabaimran
2025-01-29 14:19:57 -08:00
parent 5ea056f03e
commit c3cb6086e0

View File

@@ -1,7 +1,7 @@
import logging import logging
import os import os
from threading import Thread from threading import Thread
from typing import Dict from typing import Dict, List
import openai import openai
from openai.types.chat.chat_completion import ChatCompletion from openai.types.chat.chat_completion import ChatCompletion
@@ -184,7 +184,7 @@ def llm_thread(
elif model_name.startswith("deepseek-reasoner"): elif model_name.startswith("deepseek-reasoner"):
# Two successive messages cannot be from the same role. Should merge any back-to-back messages from the same role. # Two successive messages cannot be from the same role. Should merge any back-to-back messages from the same role.
# The first message should always be a user message (except system message). # The first message should always be a user message (except system message).
updated_messages = [] updated_messages: List[dict] = []
for i, message in enumerate(formatted_messages): for i, message in enumerate(formatted_messages):
if i > 0 and message["role"] == formatted_messages[i - 1]["role"]: if i > 0 and message["role"] == formatted_messages[i - 1]["role"]:
updated_messages[-1]["content"] += " " + message["content"] updated_messages[-1]["content"] += " " + message["content"]