Skip to content

Commit 0bc9ab3

Browse files
authored
tests(google): update google snapshots (#120)
1 parent 93feb9a commit 0bc9ab3

File tree

3 files changed

+59
-159
lines changed

3 files changed

+59
-159
lines changed

gateway/test/providers/google.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ describe('google', () => {
6868
{ method: 'POST', headers: { ...headers, 'x-vcr-filename': 'stream' }, body },
6969
)
7070

71-
const chunks: object[] = []
71+
const chunks: string[] = []
72+
const decoder = new TextDecoder()
7273
for await (const chunk of response.body!) {
73-
chunks.push(chunk)
74+
// This is in Uint8Array format, so we need to convert it to a string.
75+
chunks.push(decoder.decode(chunk))
7476
}
7577

7678
expect(chunks).toMatchSnapshot('chunks')

gateway/test/providers/google.spec.ts.snap

Lines changed: 53 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`google > google-vertex/default > llm 1`] = `"Path /gemini/v1beta1/projects/pydantic-ai/locations/global/publishers/google/models/gemini-2.5-flash:generateContent not supported"`;
3+
exports[`google > google-vertex/default > llm 1`] = `
4+
"data: {"candidates": [{"content": {"role": "model","parts": [{"functionCall": {"name": "final_result","args": {"name": "Samuel","city": "London","dob": "1987-01-28"}},"thoughtSignature": "CswDAePx/15lDrSIcIjN85FpyyOl3oASu2R23QD4Z3cj5XRUKOD/3/mMqcHv5AeXc/L+P1eVNpq5C3xM9/8zil6gOOZI91F/r1kmKvxmCECD1SW+p1dtzG6eljHd51vd2Gx7eqtEek1ORzeLP4zSWY2GDlZA9fZIs/uIfhLyOlkiiB1P/GAAUmBPT/TZqdOpQZXBt8MAUrbTOQfbhQ1qbxdrYRveZRMzXS898K6NmjrN5quNiaUgwEbc2J6NAoDOl5jdK8tIt7m25qdpjSYMpAGYD0c0Le2yPf8eO6A9J6zYp1lqVCTifby4/nP5RkVM2e1L4pH6oYisgQsyDUSEDCSG2GXhGO9WU5wFYwkjlhB8ghLU92kVgr/Rq54K/0GaYGBgzKi+YrD8c6QKSTZWTw/46D8lQ1goL1Y1YdtRiRGNFRJqKmSbkxjIOQoIk4glxcsm7L2lucL4miz4yZioBe7HEPDtmQY0FEKM5DQhwuj+AF1bBl5WE/9NYUsuGY3DxSi0lVd2v8+zd0op9U8z3PX4cmdKVkf/kA9TuQSPXBZpYgj7CssoMBT4ssLVoUgetOrNvJL99liSvsPOBZaLDKpNTXQA9GdZvQltoSolOg=="}]},"finishReason": "STOP","avgLogprobs": -0.48033348719278973}],"usageMetadata": {"promptTokenCount": 79,"candidatesTokenCount": 18,"totalTokenCount": 240,"trafficType": "ON_DEMAND","promptTokensDetails": [{"modality": "TEXT","tokenCount": 79}],"candidatesTokensDetails": [{"modality": "TEXT","tokenCount": 18}],"thoughtsTokenCount": 143},"modelVersion": "gemini-2.5-flash","createTime": "2025-11-04T15:31:56.289691Z","responseId": "bBwKaZvXEemDn9kP56mN8QI"}
5+
6+
"
7+
`;
48

59
exports[`google > google-vertex/default > span 1`] = `
610
[
711
{
812
"attributes": {
913
"gen_ai.operation.name": "chat",
10-
"gen_ai.request.model": "gemini-2.5-flash",
14+
"gen_ai.response.model": "gemini-2.5-flash",
1115
"gen_ai.system": "google-vertex",
12-
"http.request.body.text": "{"contents":[{"parts":[{"text":"Samuel lived in London and was born on Jan 28th '87"}],"role":"user"}],"systemInstruction":{"parts":[{"text":"Extract information about the person"}],"role":"user"},"tools":[{"functionDeclarations":[{"description":"The final response which ends this conversation","name":"final_result","parameters":{"properties":{"name":{"description":"The name of the person.","type":"STRING"},"dob":{"description":"The date of birth of the person. MUST BE A VALID ISO 8601 date. (format: date)","type":"STRING"},"city":{"description":"The city where the person lives.","type":"STRING"}},"required":["name","dob","city"],"type":"OBJECT"}}]}],"toolConfig":{"functionCallingConfig":{"mode":"ANY","allowedFunctionNames":["final_result"]}},"generationConfig":{"temperature":0.5,"topP":0.9,"stopSequences":["potato"]}}",
13-
"http.response.body.text": "Path /gemini/v1beta1/projects/pydantic-ai/locations/global/publishers/google/models/gemini-2.5-flash:generateContent not supported",
14-
"http.response.status_code": 404,
15-
"logfire.json_schema": "{"type":"object","properties":{"gen_ai.operation.name":{"type":"string"},"gen_ai.request.model":{"type":"string"},"gen_ai.system":{"type":"string"},"http.response.status_code":{"type":"number"},"http.request.body.text":{"type":"string"},"http.response.body.text":{"type":"string"}}}",
16-
"logfire.level_num": 13,
17-
"logfire.msg": "chat gemini-2.5-flash, unexpected response: 404",
16+
"gen_ai.usage.input_tokens": 79,
17+
"gen_ai.usage.output_tokens": 161,
18+
"http.request.header.accept": "*/*",
19+
"http.request.header.accept-encoding": "deflate",
20+
"http.request.header.authorization": "healthy",
21+
"http.request.header.content-length": "830",
22+
"http.request.header.content-type": "application/json",
23+
"http.request.header.traceparent": "00-019a4effa21047ac31372f093cb8e712-8b60768281864a49-01",
24+
"http.request.header.user-agent": "pydantic-ai/1.0.19.dev5+b3b34f9, google-genai-sdk/1.36.0 gl-python/3.13.0 via Pydantic AI Gateway unknown, contact engineering@pydantic.dev",
25+
"http.request.header.x-goog-api-client": "google-genai-sdk/1.36.0 gl-python/3.13.0",
26+
"http.request.header.x-goog-api-key": "unset",
27+
"http.request.method": "POST",
28+
"http.response.header.content-type": "text/event-stream",
29+
"http.response.header.server": "uvicorn",
30+
"http.response.header.transfer-encoding": "chunked",
31+
"http.response.status_code": 200,
32+
"logfire.json_schema": "{"type":"object","properties":{"gen_ai.system":{"type":"string"},"gen_ai.operation.name":{"type":"string"},"gen_ai.response.model":{"type":"string"},"gen_ai.usage.input_tokens":{"type":"number"},"gen_ai.usage.output_tokens":{"type":"number"},"http.request.method":{"type":"string"},"url.full":{"type":"string"},"http.request.header.accept":{"type":"string"},"http.request.header.accept-encoding":{"type":"string"},"http.request.header.authorization":{"type":"string"},"http.request.header.content-length":{"type":"string"},"http.request.header.content-type":{"type":"string"},"http.request.header.traceparent":{"type":"string"},"http.request.header.user-agent":{"type":"string"},"http.request.header.x-goog-api-client":{"type":"string"},"http.request.header.x-goog-api-key":{"type":"string"},"http.response.status_code":{"type":"number"},"http.response.header.content-type":{"type":"string"},"http.response.header.server":{"type":"string"},"http.response.header.transfer-encoding":{"type":"string"}}}",
33+
"logfire.level_num": 9,
34+
"logfire.msg": "chat streaming",
35+
"url.full": "https://example.com/gemini/v1beta1/projects/pydantic-ai/locations/global/publishers/google/models/gemini-2.5-flash:generateContent?alt=sse",
1836
},
1937
"events": [],
2038
"kind": 1,
2139
"links": [],
22-
"name": "chat gemini-2.5-flash, unexpected response: {http.response.status_code}",
40+
"name": "chat streaming",
2341
"parentSpanId": undefined,
2442
"resource": {
2543
"service.name": "PAIG",
@@ -35,144 +53,9 @@ exports[`google > google-vertex/default > span 1`] = `
3553

3654
exports[`google > google-vertex/stream > chunks 1`] = `
3755
[
38-
Uint8Array [
39-
80,
40-
97,
41-
116,
42-
104,
43-
32,
44-
47,
45-
103,
46-
101,
47-
109,
48-
105,
49-
110,
50-
105,
51-
47,
52-
118,
53-
49,
54-
98,
55-
101,
56-
116,
57-
97,
58-
49,
59-
47,
60-
112,
61-
114,
62-
111,
63-
106,
64-
101,
65-
99,
66-
116,
67-
115,
68-
47,
69-
112,
70-
121,
71-
100,
72-
97,
73-
110,
74-
116,
75-
105,
76-
99,
77-
45,
78-
97,
79-
105,
80-
47,
81-
108,
82-
111,
83-
99,
84-
97,
85-
116,
86-
105,
87-
111,
88-
110,
89-
115,
90-
47,
91-
103,
92-
108,
93-
111,
94-
98,
95-
97,
96-
108,
97-
47,
98-
112,
99-
117,
100-
98,
101-
108,
102-
105,
103-
115,
104-
104,
105-
101,
106-
114,
107-
115,
108-
47,
109-
103,
110-
111,
111-
111,
112-
103,
113-
108,
114-
101,
115-
47,
116-
109,
117-
111,
118-
100,
119-
101,
120-
108,
121-
115,
122-
47,
123-
103,
124-
101,
125-
109,
126-
105,
127-
110,
128-
105,
129-
45,
130-
50,
131-
46,
132-
53,
133-
45,
134-
102,
135-
108,
136-
97,
137-
115,
138-
104,
139-
58,
140-
115,
141-
116,
142-
114,
143-
101,
144-
97,
145-
109,
146-
71,
147-
101,
148-
110,
149-
101,
150-
114,
151-
97,
152-
116,
153-
101,
154-
67,
155-
111,
156-
110,
157-
116,
158-
101,
159-
110,
160-
116,
161-
32,
162-
110,
163-
111,
164-
116,
165-
32,
166-
115,
167-
117,
168-
112,
169-
112,
170-
111,
171-
114,
172-
116,
173-
101,
174-
100,
175-
],
56+
"data: {"candidates": [{"content": {"role": "model","parts": [{"functionCall": {"name": "final_result","args": {"name": "Samuel","dob": "1987-01-28","city": "London"}},"thoughtSignature": "CiwB4/H/XrFHcqJ5pwIEMQnBhQBHazYmUb7XC1cZhL68mxASIIbmWyFjuzXxawqAAQHj8f9epXxVjCDy0/oGNXN1LFyOtdAaqPjsycM5BxCYAPEwlGkiTMVUtJaGnZOZVjMCA1E7jjwjyaUnLi0JXUn/kHHpNZIKHHFz26Uo5OUNYt8CanXEsbfLY6i+5wIMvLYURSxBeWq814uEwV+Sif6z37WfaNvU5KrR9ek41rCRCmkB4/H/XlhR1HkHgmKGkNZnCbzL4aLYVnnA39p5YFaZvsOvv8OTwed/arFcVREVegT9jIusC+BHbxQL6jxAi/r+7Yxo4D6LFkh68j/dbGz/Y1kVy+dwqrQHJ4+c9UuPOZnMKzts+eIip6gKewHj8f9eDAdCB1AcgaXceQTctqq0PeycbHisSqLKqb0bktTud5S11F2l6iB2agdWl6J/4Lrx7Xg0mDpvJmIZbmDGGr9zAy+PyXTDpca8XwEPDOCbOaosDGofqvAcfIlCSph5m56vwlIfn8QD6HfLsUCuG8XQZF13bc3rkAp1AePx/17HSA1oMLywdmQx6jXY5g+3iBVcskBePcXaL4Jd4FeSUSqD63zVuVSuoh3QJlU0zOYyrfZL+f3Lt5VgUgLG0si8OvoDXAzPn9pu4XRRoLBKJqgB26LPWU0XI/vv11L8eXREncg46Z5AUbs2vGJ1sQMnCqUBAePx/14DiPsegv86CHeOTaMg8p7dwzDDSOfDmLXycjtGqZKMytXUXiWcBs3mtNi0rx4D4yQihmPQClBfTkpPx4pT9+wGi86Nf97CCKADwIfDPJBQF4LTUvA24v1ay9REpdaI22jadcHlE2sTvD28im63HsQ5vmoV0YYLiaj82jd52vyYLKDzb7+LgkWl2V4UhJBHyTFk+wMgkPiRuftpgAkjDlmuCkgB4/H/XtKR+rJrbrTPrKAdaDts8M1WzGEpscucnYFpeqIOkQ7GeadukWQec5GBsJVTQ6rsmaRzp6n42BAlrLmoIUIacMt2fE8="}]},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 79,"candidatesTokenCount": 18,"totalTokenCount": 267,"trafficType": "ON_DEMAND","promptTokensDetails": [{"modality": "TEXT","tokenCount": 79}],"candidatesTokensDetails": [{"modality": "TEXT","tokenCount": 18}],"thoughtsTokenCount": 170},"modelVersion": "gemini-2.5-flash","createTime": "2025-11-04T16:00:09.183509Z","responseId": "CSMKadWZC7G36MEP1Yfl-Ag"}
57+
58+
",
17659
]
17760
`;
17861

@@ -181,19 +64,34 @@ exports[`google > google-vertex/stream > span 1`] = `
18164
{
18265
"attributes": {
18366
"gen_ai.operation.name": "chat",
184-
"gen_ai.request.model": "gemini-2.5-flash",
67+
"gen_ai.response.model": "gemini-2.5-flash",
18568
"gen_ai.system": "google-vertex",
186-
"http.request.body.text": "{"contents":[{"parts":[{"text":"Samuel lived in London and was born on Jan 28th '87"}],"role":"user"}],"systemInstruction":{"parts":[{"text":"Extract information about the person"}],"role":"user"},"tools":[{"functionDeclarations":[{"description":"The final response which ends this conversation","name":"final_result","parameters":{"properties":{"name":{"description":"The name of the person.","type":"STRING"},"dob":{"description":"The date of birth of the person. MUST BE A VALID ISO 8601 date. (format: date)","type":"STRING"},"city":{"description":"The city where the person lives.","type":"STRING"}},"required":["name","dob","city"],"type":"OBJECT"}}]}],"toolConfig":{"functionCallingConfig":{"mode":"ANY","allowedFunctionNames":["final_result"]}},"generationConfig":{"temperature":0.5,"topP":0.9,"stopSequences":["potato"]}}",
187-
"http.response.body.text": "Path /gemini/v1beta1/projects/pydantic-ai/locations/global/publishers/google/models/gemini-2.5-flash:streamGenerateContent not supported",
188-
"http.response.status_code": 404,
189-
"logfire.json_schema": "{"type":"object","properties":{"gen_ai.operation.name":{"type":"string"},"gen_ai.request.model":{"type":"string"},"gen_ai.system":{"type":"string"},"http.response.status_code":{"type":"number"},"http.request.body.text":{"type":"string"},"http.response.body.text":{"type":"string"}}}",
190-
"logfire.level_num": 13,
191-
"logfire.msg": "chat gemini-2.5-flash, unexpected response: 404",
69+
"gen_ai.usage.input_tokens": 79,
70+
"gen_ai.usage.output_tokens": 188,
71+
"http.request.header.accept": "*/*",
72+
"http.request.header.accept-encoding": "deflate",
73+
"http.request.header.authorization": "healthy",
74+
"http.request.header.content-length": "830",
75+
"http.request.header.content-type": "application/json",
76+
"http.request.header.traceparent": "00-019a4effa21047ac31372f093cb8e712-8b60768281864a49-01",
77+
"http.request.header.user-agent": "pydantic-ai/1.0.19.dev5+b3b34f9, google-genai-sdk/1.36.0 gl-python/3.13.0 via Pydantic AI Gateway unknown, contact engineering@pydantic.dev",
78+
"http.request.header.x-goog-api-client": "google-genai-sdk/1.36.0 gl-python/3.13.0",
79+
"http.request.header.x-goog-api-key": "unset",
80+
"http.request.header.x-vcr-filename": "stream",
81+
"http.request.method": "POST",
82+
"http.response.header.content-type": "text/event-stream",
83+
"http.response.header.server": "uvicorn",
84+
"http.response.header.transfer-encoding": "chunked",
85+
"http.response.status_code": 200,
86+
"logfire.json_schema": "{"type":"object","properties":{"gen_ai.system":{"type":"string"},"gen_ai.operation.name":{"type":"string"},"gen_ai.response.model":{"type":"string"},"gen_ai.usage.input_tokens":{"type":"number"},"gen_ai.usage.output_tokens":{"type":"number"},"http.request.method":{"type":"string"},"url.full":{"type":"string"},"http.request.header.accept":{"type":"string"},"http.request.header.accept-encoding":{"type":"string"},"http.request.header.authorization":{"type":"string"},"http.request.header.content-length":{"type":"string"},"http.request.header.content-type":{"type":"string"},"http.request.header.traceparent":{"type":"string"},"http.request.header.user-agent":{"type":"string"},"http.request.header.x-goog-api-client":{"type":"string"},"http.request.header.x-goog-api-key":{"type":"string"},"http.request.header.x-vcr-filename":{"type":"string"},"http.response.status_code":{"type":"number"},"http.response.header.content-type":{"type":"string"},"http.response.header.server":{"type":"string"},"http.response.header.transfer-encoding":{"type":"string"}}}",
87+
"logfire.level_num": 9,
88+
"logfire.msg": "chat streaming",
89+
"url.full": "https://example.com/gemini/v1beta1/projects/pydantic-ai/locations/global/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse",
19290
},
19391
"events": [],
19492
"kind": 1,
19593
"links": [],
196-
"name": "chat gemini-2.5-flash, unexpected response: {http.response.status_code}",
94+
"name": "chat streaming",
19795
"parentSpanId": undefined,
19896
"resource": {
19997
"service.name": "PAIG",

proxy-vcr/proxy_vcr/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ async def proxy(request: Request) -> Response:
8585
**anthropic_beta_headers,
8686
}
8787
response = await client.post(url, content=body, headers=headers)
88-
elif request.url.path.startswith('/google-vertex'):
88+
elif request.url.path.startswith('/gemini'):
8989
client = cast(httpx.AsyncClient, request.scope['state']['httpx_client'])
90-
url = GOOGLE_BASE_URL + request.url.path[len('/google-vertex') :] + '?' + request.url.query
90+
url = GOOGLE_BASE_URL + request.url.path[len('/gemini') :] + '?' + request.url.query
9191
headers = {'Authorization': auth_header, 'host': 'aiplatform.googleapis.com'}
9292
# It's a bit weird, but if we don't set the host header, it will fail. This seems very weird from Google's side.
9393
with vcr.use_cassette(cassette_name('google-vertex', vcr_suffix)): # type: ignore[reportUnknownReturnType]

0 commit comments

Comments
 (0)