Skip to content

Commit 0e94110

Browse files
committed
fix(vertexai): pass GenerativeModel's BaseParams to ChatSession
1 parent 730f460 commit 0e94110

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/vertexai/src/models/generative-model.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ describe('GenerativeModel', () => {
167167
);
168168
restore();
169169
});
170+
it('passes base model params through to ChatSession when there are no startChatParams', async () => {
171+
const genModel = new GenerativeModel(fakeVertexAI, {
172+
model: 'my-model',
173+
generationConfig: {
174+
topK: 1
175+
}
176+
});
177+
const chatSession = genModel.startChat();
178+
expect(chatSession.params?.generationConfig).to.deep.equal({
179+
topK: 1
180+
});
181+
restore();
182+
});
183+
it('overrides base model params with startChatParams', () => {
184+
const genModel = new GenerativeModel(fakeVertexAI, {
185+
model: 'my-model',
186+
generationConfig: {
187+
topK: 1
188+
}
189+
});
190+
const chatSession = genModel.startChat({
191+
generationConfig: {
192+
topK: 2
193+
}
194+
});
195+
expect(chatSession.params?.generationConfig).to.deep.equal({
196+
topK: 2
197+
});
198+
});
170199
it('passes params through to chat.sendMessage', async () => {
171200
const genModel = new GenerativeModel(fakeAI, {
172201
model: 'my-model',

packages/vertexai/src/models/generative-model.ts

+7
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export class GenerativeModel extends AIModel {
132132
tools: this.tools,
133133
toolConfig: this.toolConfig,
134134
systemInstruction: this.systemInstruction,
135+
generationConfig: this.generationConfig,
136+
safetySettings: this.safetySettings,
137+
/**
138+
* Overrides params inherited from GenerativeModel with those explicitly set in the
139+
* StartChatParams. For example, if startChatParams.generationConfig is set, it'll override
140+
* this.generationConfig.
141+
*/
135142
...startChatParams
136143
},
137144
this.requestOptions

0 commit comments

Comments
 (0)