File tree 3 files changed +40
-0
lines changed
langchain-google-common/src
langchain-google-vertexai/src/tests 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,11 @@ export interface GoogleAIModelRequestParams extends GoogleAIModelParams {
308
308
* https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-use
309
309
*/
310
310
cachedContent ?: string ;
311
+
312
+ /**
313
+ * Custom metadata labels to associate with the API call.
314
+ */
315
+ labels ?: Record < string , string > ;
311
316
}
312
317
313
318
export interface GoogleAIBaseLLMInput < AuthOptions >
@@ -585,6 +590,11 @@ export interface GeminiRequest {
585
590
safetySettings ?: GeminiSafetySetting [ ] ;
586
591
generationConfig ?: GeminiGenerationConfig ;
587
592
cachedContent ?: string ;
593
+
594
+ /**
595
+ * Custom metadata labels to associate with the API call.
596
+ */
597
+ labels ?: Record < string , string > ;
588
598
}
589
599
590
600
export interface GeminiResponseCandidate {
Original file line number Diff line number Diff line change @@ -1594,6 +1594,7 @@ export function getGeminiAPI(config?: GeminiAPIConfig): GoogleAIAPI {
1594
1594
const ret : GeminiRequest = {
1595
1595
contents,
1596
1596
generationConfig,
1597
+ labels : parameters . labels ,
1597
1598
} ;
1598
1599
if ( tools && tools . length ) {
1599
1600
ret . tools = tools ;
Original file line number Diff line number Diff line change
1
+ import { test , expect } from "@jest/globals" ;
2
+ import { ChatVertexAI } from "../chat_models.js" ;
3
+ import { MockClient } from "@langchain/google-common/src/tests/mock.ts" ;
4
+
5
+ test ( "ChatVertexAI should pass labels to the API call" , async ( ) => {
6
+ const mockClient = new MockClient ( ) ;
7
+ const chatModel = new ChatVertexAI ( {
8
+ model : "gemini-pro" ,
9
+ // We need to force the client to be the mock client for testing purposes.
10
+ // This is a bit of a hack, ideally there would be a cleaner way to inject mocks.
11
+ // For now, we'll cast the chatModel to access the protected connection property.
12
+ // In a real scenario, testing lower-level components or refactoring for dependency injection would be better.
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ client : mockClient as any ,
15
+ } ) ;
16
+
17
+ const labels = {
18
+ "user-id" : "123" ,
19
+ "session-id" : "abc" ,
20
+ } ;
21
+
22
+ await chatModel . invoke ( "hello" , {
23
+ labels,
24
+ } ) ;
25
+
26
+ // Assert that the mock client's request record contains the labels
27
+ // The request format is based on the Gemini API request structure
28
+ expect ( mockClient . record . opts . data . labels ) . toEqual ( labels ) ;
29
+ } ) ;
You can’t perform that action at this time.
0 commit comments