🐛 Bug Report: Whole message history is stringified into a single 'user prompt'
Which component is this bug for?
VertexAI Instrumentation
📜 Description
Passing a list of messages to generate_content combines them all into a single string and stores/presents them as a single user prompt instead of keeping them separate.
👟 Reproduction steps
import vertexai
from traceloop.sdk import Traceloop
from vertexai.generative_models import Content, GenerativeModel, Part
Traceloop.init()
vertexai.init()
model = GenerativeModel('gemini-1.5-flash-002')
response = model.generate_content(
[
Content(
role='user',
parts=[
Part.from_text("What's 2+2?"),
],
),
Content(
role='assistant',
parts=[
Part.from_text('5'),
],
),
Content(
role='user',
parts=[
Part.from_text('really?'),
],
),
]
)
👍 Expected behavior
Attributes look something like:
{
"gen_ai.prompt.0.role": "user",
"gen_ai.prompt.0.content": "What's 2+2?\n",
"gen_ai.prompt.1.role": "assistant",
"gen_ai.prompt.1.content": "5\n",
"gen_ai.prompt.2.role": "user",
"gen_ai.prompt.2.content": "really?\n",
"gen_ai.completion.3.role": "assistant",
"gen_ai.completion.3.content": "Oops! My apologies. 2 + 2 = 4. I'm still under development and learning to perform these calculations correctly.\n"
}
👎 Actual Behavior with Screenshots
Attributes look like:
{
"gen_ai.prompt.0.user": "role: \"user\"\nparts {\n text: \"What\\'s 2+2?\"\n}\n\nrole: \"assistant\"\nparts {\n text: \"5\"\n}\n\nrole: \"user\"\nparts {\n text: \"really?\"\n}\n\n",
"gen_ai.completion.0.role": "assistant",
"gen_ai.completion.0.content": "Oops! My apologies. 2 + 2 = 4. I'm still under development and learning to perform these calculations correctly.\n"
}
🤖 Python Version
No response
📃 Provide any additional context for the Bug.
https://github.com/traceloop/openllmetry/blob/d92a50e9f5662d215e5808c8059ca9732480343e/packages/opentelemetry-instrumentation-vertexai/opentelemetry/instrumentation/vertexai/init.py#L124-L138
👀 Have you spent some time to check if this bug has been raised before?
- [X] I checked and didn't find similar issue
Are you willing to submit PR?
None
Hey there, @alexmojaki! I'm Dosu, a bot here to help you with bug fixes, questions, and contributions. I'll assist you while we wait for a human maintainer.
The issue you're encountering is due to the _set_input_attributes function in the VertexAI Instrumentation, which combines multiple messages into a single string. This function iterates over the args parameter, concatenating each message or sub-message with a newline character, resulting in a single prompt string. This is why the attributes are not separated as expected [1].
To address this, you would need to modify the logic in _set_input_attributes to handle each message separately, ensuring that each message is stored as a distinct attribute rather than being combined into one.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
Thanks for reporting @alexmojaki! We'll prioritize the fix internally.
@galkleinman I have created a PR could you please check?