Initial commit: deardiary project setup

This commit is contained in:
lotherk
2026-03-26 19:57:20 +00:00
commit 3f9bc1f484
73 changed files with 8627 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import type { AIProvider, AIProviderConfig } from './provider';
export class OllamaProvider implements AIProvider {
provider = 'ollama' as const;
private baseUrl: string;
private model: string;
constructor(config: AIProviderConfig) {
this.baseUrl = config.baseUrl || 'http://localhost:11434';
this.model = config.model || 'llama3.2';
}
async generate(prompt: string, systemPrompt?: string): Promise<string> {
const response = await fetch(`${this.baseUrl}/api/chat`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: this.model,
stream: false,
messages: [
...(systemPrompt ? [{ role: 'system', content: systemPrompt }] : []),
{ role: 'user', content: prompt },
],
}),
});
if (!response.ok) {
const error = await response.text();
throw new Error(`Ollama API error: ${response.status} ${error}`);
}
const data = await response.json() as { message: { content: string } };
return data.message?.content || '';
}
async validate(): Promise<boolean> {
try {
const response = await fetch(`${this.baseUrl}/api/tags`);
return response.ok;
} catch {
return false;
}
}
}