|
| 1 | +import { |
| 2 | + createEchoGoogle, |
| 3 | + GeminiModels, |
| 4 | +} from '@merit-systems/echo-typescript-sdk'; |
| 5 | +import { generateText } from 'ai'; |
| 6 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 7 | +import { |
| 8 | + ECHO_APP_ID, |
| 9 | + assertEnv, |
| 10 | + baseRouterUrl, |
| 11 | + getApiErrorDetails, |
| 12 | + getToken, |
| 13 | +} from './test-helpers'; |
| 14 | + |
| 15 | +beforeAll(assertEnv); |
| 16 | + |
| 17 | +const GEMINI_IMAGE_MODELS = [ |
| 18 | + 'gemini-2.5-flash-image', |
| 19 | + 'gemini-2.5-flash-image-preview', |
| 20 | +] as const; |
| 21 | + |
| 22 | +describe.concurrent('Gemini generateText with image generation', () => { |
| 23 | + const google = createEchoGoogle( |
| 24 | + { appId: ECHO_APP_ID!, baseRouterUrl }, |
| 25 | + getToken |
| 26 | + ); |
| 27 | + |
| 28 | + for (const model_id of GEMINI_IMAGE_MODELS) { |
| 29 | + it(`Gemini image ${model_id}`, async () => { |
| 30 | + try { |
| 31 | + const result = await generateText({ |
| 32 | + model: google(model_id), |
| 33 | + prompt: 'Generate a simple blue circle', |
| 34 | + }); |
| 35 | + |
| 36 | + |
| 37 | + expect(result).toBeDefined(); |
| 38 | + |
| 39 | + |
| 40 | + const imageFile = result.files?.find(file => |
| 41 | + file.mediaType?.startsWith('image/') |
| 42 | + ); |
| 43 | + |
| 44 | + expect(imageFile).toBeDefined(); |
| 45 | + expect(imageFile?.mediaType).toMatch(/^image\//); |
| 46 | + expect(imageFile?.base64).toBeDefined(); |
| 47 | + expect(imageFile?.base64?.length).toBeGreaterThan(0); |
| 48 | + } catch (err) { |
| 49 | + const details = getApiErrorDetails(err); |
| 50 | + throw new Error( |
| 51 | + `[generateText with image] Gemini ${model_id} failed: ${details}` |
| 52 | + ); |
| 53 | + } |
| 54 | + }); |
| 55 | + } |
| 56 | +}); |
0 commit comments