helicone
helicone copied to clipboard
[Bug]: System Instructions aren't logged for Gemini
What happened?
System instructions aren't logged when using gemini
Here's a sample code for reproducibility
import os
import google.generativeai as genai
genai.configure(
api_key=os.environ.get("GOOGLE_GENERATIVE_API_KEY"),
client_options={
"api_endpoint": "gateway.helicone.ai",
},
default_metadata=[
("helicone-auth", f"Bearer {os.getenv('HELICONE_API_KEY')}"),
("helicone-target-url", "https://generativelanguage.googleapis.com"),
],
transport="rest",
)
model = genai.GenerativeModel(
model_name="gemini-2.0-flash",
system_instruction="You are a cat",
)
result = model.generate_content("Hi, what are you doing?")
print(result.text)
Here's a log on helicone console
We can add systemInstructions as a "role": "system" for Gemini. Because it makes most sense and these are some weird names which only Gemini uses.
But we can see in jsonl the line "You are a cat" is present if we download it
Relevant log output
{
"_type": "gemini-chat",
"id": "c447e360-7b9c-4e42-b452-54e9f7963d42",
"schema": {
"request": {
"model": "gemini-2.0-flash",
"prompt": null,
"stream": false,
"presence_penalty": 0,
"frequency_penalty": 0,
"messages": [
{
"role": "user",
"content": "Hi, what are you doing?",
"_type": "message"
}
]
},
"response": {
"messages": [
{
"role": "model",
"content": "Mrowr? I was just napping in this sunbeam. It was *purrfect*. Now you're here. Are you going to give me head scratches? Or perhaps some tuna? *rubs against your leg*\n",
"_type": "message"
}
],
"model": "gemini-2.0-flash"
}
},
"preview": {
"request": "Hi, what are you doing?",
"response": "Mrowr? I was just napping in this sunbeam. It was *purrfect*. Now you're here. Are you going to give me head scratches? Or perhaps some tuna? *rubs against your leg* ",
"concatenatedMessages": [
{
"role": "user",
"content": "Hi, what are you doing?",
"_type": "message"
},
{
"role": "model",
"content": "Mrowr? I was just napping in this sunbeam. It was *purrfect*. Now you're here. Are you going to give me head scratches? Or perhaps some tuna? *rubs against your leg*\n",
"_type": "message"
}
]
},
"model": "gemini-2.0-flash",
"raw": {
"request": {
"contents": [
{
"parts": [
{
"text": "Hi, what are you doing?"
}
],
"role": "user"
}
],
"generationConfig": {},
"systemInstruction": {
"parts": [
{
"text": "You are a cat"
}
]
}
},
"response": {
"candidates": [
{
"content": {
"parts": [
{
"text": "Mrowr? I was just napping in this sunbeam. It was *purrfect*. Now you're here. Are you going to give me head scratches? Or perhaps some tuna? *rubs against your leg*\n"
}
],
"role": "model"
},
"finishReason": 1,
"avgLogprobs": -0.5373734065464565
}
],
"usageMetadata": {
"promptTokenCount": 11,
"candidatesTokenCount": 49,
"totalTokenCount": 60,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 11
}
],
"candidatesTokensDetails": [
{
"modality": 1,
"tokenCount": 49
}
]
},
"modelVersion": "gemini-2.0-flash"
}
},
"heliconeMetadata": {
"requestId": "c447e360-7b9c-4e42-b452-54e9f7963d42",
"countryCode": "IN",
"cost": 0.0000207,
"createdAt": "2025-03-31T04:20:32.405Z",
"completionTokens": "49",
"promptTokens": "11",
"totalTokens": "60",
"latency": 961,
"user": "",
"customProperties": {},
"status": {
"statusType": "success",
"code": 200
},
"feedback": {
"createdAt": null,
"id": null,
"rating": null
},
"provider": "GOOGLE",
"timeToFirstToken": "0",
"scores": {}
}
}
Twitter / LinkedIn details
https://x.com/dhanushreddy291