Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33bd257

Browse files
committed
Add integration test
1 parent 2fddba2 commit 33bd257

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/ai/integration/generate-content.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import {
2121
GenerationConfig,
2222
HarmBlockThreshold,
2323
HarmCategory,
24+
Language,
2425
Modality,
26+
Outcome,
2527
SafetySetting,
2628
getGenerativeModel
2729
} from '../src';
@@ -188,6 +190,32 @@ describe('Generate Content', () => {
188190
});
189191
});
190192

193+
it('generateContent: code execution', async () => {
194+
const model = getGenerativeModel(testConfig.ai, {
195+
model: testConfig.model,
196+
generationConfig: commonGenerationConfig,
197+
safetySettings: commonSafetySettings,
198+
tools: [{ codeExecution: {} }]
199+
});
200+
const prompt =
201+
'What is the sum of the first 50 prime numbers? ' +
202+
'Generate and run code for the calculation, and make sure you get all 50.';
203+
204+
const result = await model.generateContent(prompt);
205+
const parts = result.response.candidates?.[0].content.parts;
206+
expect(
207+
parts?.some(part => part.executableCode?.language === Language.PYTHON)
208+
).to.be.true;
209+
expect(
210+
parts?.some(part => part.codeExecutionResult?.outcome === Outcome.OK)
211+
).to.be.true;
212+
// Expect these to be truthy (!= null)
213+
expect(parts?.some(part => part.executableCode?.code != null)).to.be
214+
.true;
215+
expect(parts?.some(part => part.codeExecutionResult?.output != null)).to
216+
.be.true;
217+
});
218+
191219
it('generateContentStream: text input, text output', async () => {
192220
const model = getGenerativeModel(testConfig.ai, {
193221
model: testConfig.model,

packages/ai/src/methods/generate-content.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ describe('generateContent()', () => {
262262
fakeRequestParams
263263
);
264264
const parts = result.response.candidates?.[0].content.parts;
265-
parts?.forEach(part => console.log(Object.keys(part)));
266265
expect(
267266
parts?.some(part => part.codeExecutionResult?.outcome === Outcome.OK)
268267
).to.be.true;

0 commit comments

Comments
 (0)