Google Gen AI: Copy messages to avoid changing the trace data (#118745)

This commit is contained in:
Paulus Schoutsen 2024-06-03 16:29:50 -04:00 committed by GitHub
parent 299c0de968
commit 035e19be01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -225,7 +225,7 @@ class GoogleGenerativeAIConversationEntity(
messages = self.history[conversation_id]
else:
conversation_id = ulid.ulid_now()
messages = [{}, {}]
messages = [{}, {"role": "model", "parts": "Ok"}]
if (
user_input.context
@ -272,8 +272,11 @@ class GoogleGenerativeAIConversationEntity(
response=intent_response, conversation_id=conversation_id
)
messages[0] = {"role": "user", "parts": prompt}
messages[1] = {"role": "model", "parts": "Ok"}
# Make a copy, because we attach it to the trace event.
messages = [
{"role": "user", "parts": prompt},
*messages[1:],
]
LOGGER.debug("Input: '%s' with history: %s", user_input.text, messages)
trace.async_conversation_trace_append(