mirror of
https://github.com/blackboxprogramming/blackroad.io.git
synced 2026-03-18 06:34:01 -05:00
Route all chat requests to local Ollama; support @copilot, @lucidia, @blackboxprogramming, @ollama mentions
Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
@@ -97,6 +97,8 @@ class BlackRoadAPI {
|
||||
}
|
||||
|
||||
// AI Chat: Send message
|
||||
// Messages containing @copilot, @lucidia, @blackboxprogramming, or @ollama
|
||||
// are routed directly to the local Ollama instance, bypassing external providers.
|
||||
async chat(message, conversationId = null) {
|
||||
return this.request('/api/ai-chat/chat', {
|
||||
method: 'POST',
|
||||
@@ -104,6 +106,22 @@ class BlackRoadAPI {
|
||||
});
|
||||
}
|
||||
|
||||
// Direct Ollama chat (bypasses the backend entirely, calls Ollama from the browser)
|
||||
async ollamaChat(message, model = 'llama3', history = []) {
|
||||
const ollamaBase = 'http://localhost:11434';
|
||||
const messages = [...history, { role: 'user', content: message }];
|
||||
const response = await fetch(`${ollamaBase}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ model, messages, stream: false })
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ollama responded with ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data.message?.content || '';
|
||||
}
|
||||
|
||||
// AI Chat: List conversations
|
||||
async listConversations() {
|
||||
return this.request('/api/ai-chat/conversations');
|
||||
|
||||
Reference in New Issue
Block a user