mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Revert "Enable AI to see images when using the read tool"
This reverts commit 2641252c6a.
This commit is contained in:
3 files changed
+3
-38
No files matched your search
@@ -4,7 +4,7 @@ import type { JSRuntimeFS } from './JSRuntime';
|
|||||||
import { DotAI } from './DotAI';
|
import { DotAI } from './DotAI';
|
||||||
import { parseProviderModel } from './parseProviderModel';
|
import { parseProviderModel } from './parseProviderModel';
|
||||||
import { createAIClient } from './ai-client';
|
import { createAIClient } from './ai-client';
|
||||||
import type { Tool, ToolResultImage } from './tools/Tool';
|
import type { Tool } from './tools/Tool';
|
||||||
import type { NUser } from '@nostrify/react/login';
|
import type { NUser } from '@nostrify/react/login';
|
||||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||||
import { makeSystemPrompt } from './system';
|
import { makeSystemPrompt } from './system';
|
||||||
@@ -656,11 +656,6 @@ export class SessionManager {
|
|||||||
const result = await tool.execute(toolArgs);
|
const result = await tool.execute(toolArgs);
|
||||||
await this.addToolMessage(projectId, functionToolCall.id, result.content);
|
await this.addToolMessage(projectId, functionToolCall.id, result.content);
|
||||||
|
|
||||||
// If tool returned images, inject a user message so the AI can "see" them
|
|
||||||
if (result.images?.length) {
|
|
||||||
await this.addToolImageMessage(projectId, result.images);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update session cost if tool returned a cost
|
// Update session cost if tool returned a cost
|
||||||
if (result.cost !== undefined) {
|
if (result.cost !== undefined) {
|
||||||
const updatedSession = this.sessions.get(projectId);
|
const updatedSession = this.sessions.get(projectId);
|
||||||
@@ -804,25 +799,6 @@ export class SessionManager {
|
|||||||
await this.addMessage(projectId, toolMessage);
|
await this.addMessage(projectId, toolMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper to inject a user message with images from tool results.
|
|
||||||
* Since tool messages only support text content, images are sent
|
|
||||||
* as a follow-up user message so vision models can actually see them.
|
|
||||||
*/
|
|
||||||
private async addToolImageMessage(projectId: string, images: ToolResultImage[]): Promise<void> {
|
|
||||||
const content: OpenAI.Chat.Completions.ChatCompletionContentPart[] = images.map((img) => ({
|
|
||||||
type: 'image_url' as const,
|
|
||||||
image_url: { url: img.url },
|
|
||||||
}));
|
|
||||||
|
|
||||||
const imageMessage: AIMessage = {
|
|
||||||
role: 'user',
|
|
||||||
content,
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.addMessage(projectId, imageMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update session cost and context usage based on usage data
|
* Update session cost and context usage based on usage data
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -86,15 +86,10 @@ Usage:
|
|||||||
const base64 = this.arrayBufferToBase64(bytes);
|
const base64 = this.arrayBufferToBase64(bytes);
|
||||||
const ext = this.getFileExtension(filepath).toLowerCase();
|
const ext = this.getFileExtension(filepath).toLowerCase();
|
||||||
const mimeType = this.getMimeType(ext);
|
const mimeType = this.getMimeType(ext);
|
||||||
const dataUrl = `data:${mimeType};base64,${base64}`;
|
|
||||||
|
|
||||||
// For vision-supported formats (JPG/PNG), return as a structured image
|
|
||||||
// so the AI can actually "see" the image
|
|
||||||
const isVisionSupported = ['jpg', 'jpeg', 'png'].includes(ext);
|
|
||||||
|
|
||||||
|
// Return base64 data URL in the content
|
||||||
return {
|
return {
|
||||||
content: `[Image file: ${ext.toUpperCase()} file]\n\nImage read successfully.${!isVisionSupported ? `\n\nData URL: ${dataUrl}` : ''}`,
|
content: `[Image file: ${ext.toUpperCase()} file]\n\nImage read successfully.\n\nData URL: data:${mimeType};base64,${base64}`,
|
||||||
images: isVisionSupported ? [{ type: 'image' as const, url: dataUrl }] : undefined,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import type z from "zod";
|
import type z from "zod";
|
||||||
|
|
||||||
export interface ToolResultImage {
|
|
||||||
type: 'image';
|
|
||||||
url: string; // data URL (e.g. data:image/png;base64,...)
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ToolResult {
|
export interface ToolResult {
|
||||||
content: string;
|
content: string;
|
||||||
cost?: number;
|
cost?: number;
|
||||||
images?: ToolResultImage[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tool<TParams> {
|
export interface Tool<TParams> {
|
||||||
|
|||||||
Reference in new issue
Block a user