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:
copilot-swe-agent[bot]
2026-03-03 04:45:25 +00:00
parent 0c96baf533
commit fe34d8a519
4 changed files with 96 additions and 15 deletions

View File

@@ -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');