59df2f6856
Update error handling and improve streaming capabilities in the Ollama client and related components. Key changes include: - Simplify error types and improve error handling - Refactor streaming logic to use async generators - Update tool execution and vault indexing - Improve utility functions and types - Update test files to reflect changes
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
// Mock for ollama-client for testing
|
|
import { OllamaMessage, ToolCall } from '../src/types';
|
|
import type { APIError } from '../src/error-handler';
|
|
|
|
export class OllamaClient {
|
|
private url: string;
|
|
private model: string;
|
|
|
|
// Mock fetch function for testing
|
|
private fetchFn: jest.Mock<Promise<Response>, [string, RequestInit?]>> = jest.fn();
|
|
|
|
constructor(url: string, model: string, fetchFn?: typeof fetch) {
|
|
this.url = url;
|
|
this.model = model;
|
|
if (fetchFn) this.fetchFn = jest.fn(fetchFn);
|
|
}
|
|
|
|
async *streamChatMessages(
|
|
prompt: string,
|
|
options: { abortSignal?: AbortSignal } = {}
|
|
): AsyncGenerator<OllamaMessage, void, unknown> {
|
|
// Mock implementation - simulate streaming response
|
|
const mockResponse = [
|
|
{ role: 'assistant', content: 'Part 1' },
|
|
{ role: 'assistant', content: 'Part 2' }
|
|
];
|
|
|
|
for (const message of mockResponse) {
|
|
yield message;
|
|
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate delay
|
|
}
|
|
}
|
|
|
|
async *streamToolMessages(
|
|
toolCall: ToolCall,
|
|
options: { abortSignal?: AbortSignal } = {}
|
|
): AsyncGenerator<OllamaMessage, void, unknown> {
|
|
// Mock implementation - simulate streaming response for tool
|
|
const mockResponse = [
|
|
{ role: 'assistant', content: `Tool ${toolCall.tool_name} Part 1` },
|
|
{ role: 'assistant', content: `Tool ${toolCall.tool_name} Part 2` }
|
|
];
|
|
|
|
for (const message of mockResponse) {
|
|
yield message;
|
|
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate delay
|
|
}
|
|
}
|
|
}
|