Files
langchaingo/llms/googleai/testdata/TestGoogleAIWithStreaming.httprr
Travis Cline 99951bca92 httprr: improve test recording stability and add utilities (#1368)
* build: add examples-updater tool and update examples to v0.1.14-pre.1

Add a new tool to automate updating langchaingo version references in example
projects and use it to update all examples to v0.1.14-pre.1. The tool also
removes temporary replace directives that are no longer needed.

- Add update-examples Makefile target that runs the new tool
- Create internal/devtools/examples-updater implementation
- Update all example go.mod files to reference v0.1.14-pre.1
- Remove replace directives in googleai and vertex examples
- Update dependencies in main go.mod/go.sum

* httprr: improve header normalization and test container setup

Add header normalization to make HTTP recordings more stable:
- Add normalizeGoogleAPIClientHeader and normalizeVersionHeader functions
- Normalize User-Agent, x-goog-api-client and other version headers
- Remove OpenAI-Project header for consistency
- Preserve body for both replay lookup and recording
- Add comprehensive tests for header normalization

Improve testcontainer environment detection:
- Better handling of non-standard Docker socket paths
- Disable Ryuk reaper by default for resource efficiency
- Add verbose logging option via environment variable

* httputil: add ApiKeyTransport for query parameter API keys

Add a reusable ApiKeyTransport that adds API keys to URL query parameters:
- Create ApiKeyTransport implementation in httputil package
- Add comprehensive tests for the new transport
- Refactor googleai_test.go to use the shared transport
- Update chains/llm_test.go to use ApiKeyTransport with proper key scrubbing

This improves how API keys are handled with client libraries that don't
properly set keys when using custom HTTP clients, particularly useful
with httprr for testing Google API integrations.

* openai: remove duplicate MaxTokens field assignment

Remove redundant assignment where both MaxTokens and MaxCompletionTokens
were being set to the same value. MaxCompletionTokens is the preferred
field name that reflects OpenAI's API changes, while MaxTokens was
previously kept for backward compatibility.

* vectorstores/maridadb: add test infrastructure for MariaDB vectorstore

Add TestMain function for MariaDB vectorstore tests that ensures the proper
test environment is set up using the testctr package. This enables consistent
test container setup and teardown for MariaDB integration tests.

* all: normalize all httprr recordings for consistency

Update test recordings across all packages to use normalized headers:
- Standardize User-Agent to 'langchaingo-httprr'
- Normalize version information in x-goog-api-client headers
- Remove OpenAI-Project headers for consistency
- Fix deprecated Anthropic completion API tests
- Update HuggingFace test recordings with valid responses

These changes make test recordings stable across dependency updates
and different environments, preventing test failures from version changes.

* devtools: add utility tool for normalizing httprr test recordings

Add a command-line tool that standardizes version information in httprr recordings:
- Normalizes x-goog-api-client headers to use placeholder versions
- Standardizes x-amz-user-agent headers for consistency
- Replaces Go version strings with generic placeholders
- Supports dry-run mode to preview changes without modifying files
- Includes verbose output option for detailed change reporting

This tool helps maintain consistent test recordings across different environments
and dependency versions, preventing test failures from version changes.

* llms/openai: update OpenAI embedding test to use text-embedding-3-small model

Update the embedding test to use the current text-embedding-3-small model:
- Change model from text-embedding-ada-002 to text-embedding-3-small
- Adjust dimensions parameter from 1234 to 256 to match model capabilities
- Update test recording with appropriate response data

This change ensures tests remain compatible with OpenAI's current embedding
models and prevents test failures from API version changes.
2025-08-18 19:41:52 +02:00

599 lines
13 KiB
Plaintext
Generated

httprr trace v1
782 12612
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent?%24alt=json%3Benum-encoding%3Dint HTTP/1.1
Host: generativelanguage.googleapis.com
User-Agent: langchaingo-httprr
Content-Length: 357
Content-Type: application/json
x-goog-api-client: gl-go/X.XX.X gccl/vX.XX.X genai-go/X.XX.X gapic/X.X.X gax/X.XX.X rest/UNKNOWN
x-goog-request-params: model=models%2Fgemini-2.0-flash
{"model":"models/gemini-2.0-flash","contents":[{"parts":[{"text":"Tell me a short story about a cat"}],"role":"user"}],"safetySettings":[{"category":10,"threshold":3},{"category":7,"threshold":3},{"category":8,"threshold":3},{"category":9,"threshold":3}],"generationConfig":{"candidateCount":1,"maxOutputTokens":2048,"temperature":0.5,"topP":0.95,"topK":3}}HTTP/2.0 200 OK
Content-Length: 12232
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Content-Type: application/json; charset=UTF-8
Date: Mon, 18 Aug 2025 12:40:52 GMT
Server: scaffolding on HTTPServer2
Server-Timing: gfet4t7; dur=434
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0
[{
"candidates": [
{
"content": {
"parts": [
{
"text": "C"
}
],
"role": "model"
}
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": "lementine, a calico with a perpetually grumpy face, considered herself the queen of Willow"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " Creek. Her kingdom consisted of Mrs. Higgins' sun-drenched porch, the"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " neighbor's meticulously manicured rose bushes (perfect for napping), and the occasional unsuspecting mouse that dared to cross her path.\n\nClementine wasn't fond"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " of people. They were loud, clumsy, and often smelled of citrus, a scent she found deeply offensive. Mrs. Higgins, however, was tolerated. She provided food"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": ", a warm bed, and understood the sacredness of Clementine's naps.\n\nOne blustery autumn afternoon, a small, shivering creature appeared on Mrs. Higgins' porch. It was a kitten, a scrawny, grey"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " thing with wide, pleading eyes. Clementine, usually quick to chase away any interloper, found herself frozen. The kitten was pathetic.\n\nShe sniffed it cautiously. It smelled of rain and something faintly…milky. Clementine"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " wrinkled her nose. Disgusting. But the kitten, instead of running, rubbed against her leg, purring weakly.\n\nClementine hissed. A reflex. But the hiss lacked its usual venom.\n\nDays turned into weeks. The kitten, whom Mrs. Higgins had named \"Dusty,\" followed Clementine everywhere,"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " a tiny, grey shadow. Clementine, despite her best efforts to maintain her regal aloofness, found herself grooming Dusty, sharing her food, and even, on particularly cold nights, allowing the kitten to snuggle against her for warmth.\n\nOne morning, Dusty was gone. Clementine searched the porch, the rose"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " bushes, even the dreaded citrus-scented neighbor's yard. Panic, a foreign and unpleasant sensation, clawed at her chest.\n\nJust as despair began to set in, she heard a faint meow. Dusty was perched precariously on the highest branch of the ancient oak tree in Mrs. Higgins' yard, looking"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " down with wide, frightened eyes.\n\nClementine, ignoring her own fear of heights, began to climb. She scrambled up the rough bark, her claws digging in, fueled by a primal need to protect the small, grey creature that had somehow, inexplicably, wormed its way into her grumpy heart.\n\nRe"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": "aching Dusty, she nudged him gently. He nestled against her, trembling. Together, they slowly, carefully, descended.\n\nBack on solid ground, Clementine licked Dusty's head, a rare display of affection. He purred, loud and strong. Clementine, queen of Willow Creek, felt a warmth spread through"
}
],
"role": "model"
},
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 9,
"totalTokenCount": 9,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 9
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
,
{
"candidates": [
{
"content": {
"parts": [
{
"text": " her, a feeling far more satisfying than any sunbeam or mouse. Perhaps, she thought, a queen could use a loyal subject, especially one who smelled faintly of milk. And perhaps, just perhaps, she wasn't quite as grumpy as she thought she was.\n"
}
],
"role": "model"
},
"finishReason": 1,
"safetyRatings": [
{
"category": 8,
"probability": 1
},
{
"category": 10,
"probability": 1
},
{
"category": 7,
"probability": 1
},
{
"category": 9,
"probability": 1
}
]
}
],
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 578,
"totalTokenCount": 586,
"promptTokensDetails": [
{
"modality": 1,
"tokenCount": 8
}
],
"candidatesTokensDetails": [
{
"modality": 1,
"tokenCount": 578
}
]
},
"modelVersion": "gemini-2.0-flash",
"responseId": "VB-jaN_BCZuThMIPnryvyAg"
}
]