Added support for Gemini models

This commit is contained in:
Badri Narayanan S
2025-12-27 14:09:20 +05:30
parent 9b7dcf3a6c
commit c1e1dbb0ef
13 changed files with 641 additions and 176 deletions

View File

@@ -3,34 +3,40 @@
*
* Tests that images can be sent to the API with thinking models.
* Simulates Claude Code sending screenshots or images for analysis.
*
* Runs for both Claude and Gemini model families.
*/
const fs = require('fs');
const path = require('path');
const { streamRequest } = require('./helpers/http-client.cjs');
const { streamRequest, analyzeContent } = require('./helpers/http-client.cjs');
const { getTestModels, getModelConfig, familySupportsThinking } = require('./helpers/test-models.cjs');
// Load test image from disk
const TEST_IMAGE_PATH = path.join(__dirname, 'utils', 'test_image.jpeg');
const TEST_IMAGE_BASE64 = fs.readFileSync(TEST_IMAGE_PATH).toString('base64');
async function runTests() {
async function runTestsForModel(family, model) {
console.log('='.repeat(60));
console.log('IMAGE SUPPORT TEST');
console.log(`IMAGE SUPPORT TEST [${family.toUpperCase()}]`);
console.log(`Model: ${model}`);
console.log('Tests image processing with thinking models');
console.log('='.repeat(60));
console.log('');
let allPassed = true;
const results = [];
const modelConfig = getModelConfig(family);
const expectThinking = familySupportsThinking(family);
// ===== TEST 1: Single image with question =====
console.log('TEST 1: Single image with question');
console.log('-'.repeat(40));
const result1 = await streamRequest({
model: 'claude-sonnet-4-5-thinking',
max_tokens: 16000,
model,
max_tokens: modelConfig.max_tokens,
stream: true,
thinking: { type: 'enabled', budget_tokens: 8000 },
thinking: modelConfig.thinking,
messages: [{
role: 'user',
content: [
@@ -55,20 +61,22 @@ async function runTests() {
allPassed = false;
results.push({ name: 'Single image processing', passed: false });
} else {
const thinking = result1.content.filter(b => b.type === 'thinking');
const text = result1.content.filter(b => b.type === 'text');
const content = analyzeContent(result1.content);
console.log(` Thinking: ${thinking.length > 0 ? 'YES' : 'NO'}`);
console.log(` Text response: ${text.length > 0 ? 'YES' : 'NO'}`);
console.log(` Thinking: ${content.hasThinking ? 'YES' : 'NO'}`);
console.log(` Text response: ${content.hasText ? 'YES' : 'NO'}`);
if (thinking.length > 0) {
console.log(` Thinking: "${thinking[0].thinking?.substring(0, 60)}..."`);
if (content.hasThinking && content.thinking[0].thinking) {
console.log(` Thinking: "${content.thinking[0].thinking.substring(0, 60)}..."`);
}
if (text.length > 0) {
console.log(` Response: "${text[0].text?.substring(0, 100)}..."`);
if (content.hasText && content.text[0].text) {
console.log(` Response: "${content.text[0].text.substring(0, 100)}..."`);
}
const passed = thinking.length > 0 && text.length > 0;
// For thinking models, expect thinking + text. For others, just text.
const passed = expectThinking
? (content.hasThinking && content.hasText)
: content.hasText;
results.push({ name: 'Single image processing', passed });
if (!passed) allPassed = false;
}
@@ -78,10 +86,10 @@ async function runTests() {
console.log('-'.repeat(40));
const result2 = await streamRequest({
model: 'claude-sonnet-4-5-thinking',
max_tokens: 16000,
model,
max_tokens: modelConfig.max_tokens,
stream: true,
thinking: { type: 'enabled', budget_tokens: 8000 },
thinking: modelConfig.thinking,
messages: [
{
role: 'user',
@@ -119,24 +127,23 @@ async function runTests() {
allPassed = false;
results.push({ name: 'Image in multi-turn', passed: false });
} else {
const thinking = result2.content.filter(b => b.type === 'thinking');
const text = result2.content.filter(b => b.type === 'text');
const content = analyzeContent(result2.content);
console.log(` Thinking: ${thinking.length > 0 ? 'YES' : 'NO'}`);
console.log(` Text response: ${text.length > 0 ? 'YES' : 'NO'}`);
console.log(` Thinking: ${content.hasThinking ? 'YES' : 'NO'}`);
console.log(` Text response: ${content.hasText ? 'YES' : 'NO'}`);
if (text.length > 0) {
console.log(` Response: "${text[0].text?.substring(0, 80)}..."`);
if (content.hasText && content.text[0].text) {
console.log(` Response: "${content.text[0].text.substring(0, 80)}..."`);
}
const passed = text.length > 0;
const passed = content.hasText;
results.push({ name: 'Image in multi-turn', passed });
if (!passed) allPassed = false;
}
// ===== Summary =====
console.log('\n' + '='.repeat(60));
console.log('SUMMARY');
console.log(`SUMMARY [${family.toUpperCase()}]`);
console.log('='.repeat(60));
for (const result of results) {
@@ -145,7 +152,26 @@ async function runTests() {
}
console.log('\n' + '='.repeat(60));
console.log(`OVERALL: ${allPassed ? 'ALL TESTS PASSED' : 'SOME TESTS FAILED'}`);
console.log(`[${family.toUpperCase()}] ${allPassed ? 'ALL TESTS PASSED' : 'SOME TESTS FAILED'}`);
console.log('='.repeat(60));
return allPassed;
}
async function runTests() {
const models = getTestModels();
let allPassed = true;
for (const { family, model } of models) {
console.log('\n');
const passed = await runTestsForModel(family, model);
if (!passed) allPassed = false;
}
console.log('\n' + '='.repeat(60));
console.log('FINAL RESULT');
console.log('='.repeat(60));
console.log(`Overall: ${allPassed ? 'ALL MODEL FAMILIES PASSED' : 'SOME MODEL FAMILIES FAILED'}`);
console.log('='.repeat(60));
process.exit(allPassed ? 0 : 1);