Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(ollama): added streaming & tool call support for ollama, updated docs#884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { env } from '@/lib/env' | ||
| import { createLogger } from '@/lib/logs/console/logger' | ||
| import type { ModelsObject } from '@/providers/ollama/types' | ||
| const logger = createLogger('OllamaModelsAPI') | ||
| const OLLAMA_HOST = env.OLLAMA_URL || 'http://localhost:11434' | ||
| export const dynamic = 'force-dynamic' | ||
| /** | ||
| * Get available Ollama models | ||
| */ | ||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| logger.info('Fetching Ollama models', { | ||
| host: OLLAMA_HOST, | ||
| }) | ||
| const response = await fetch(`${OLLAMA_HOST}/api/tags`, { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }) | ||
| if (!response.ok) { | ||
| logger.warn('Ollama service is not available', { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| }) | ||
| return NextResponse.json({ models: [] }) | ||
| } | ||
| const data = (await response.json()) as ModelsObject | ||
| const models = data.models.map((model) => model.name) | ||
| logger.info('Successfully fetched Ollama models', { | ||
| count: models.length, | ||
| models, | ||
| }) | ||
| return NextResponse.json({ models }) | ||
| } catch (error) { | ||
| logger.error('Failed to fetch Ollama models', { | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| host: OLLAMA_HOST, | ||
| }) | ||
| // Return empty array instead of error to avoid breaking the UI | ||
| return NextResponse.json({ models: [] }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -12,6 +12,12 @@ import { | ||||||||||||||||||||||||||
| MODELS_WITH_TEMPERATURE_SUPPORT, | ||||||||||||||||||||||||||
| providers, | ||||||||||||||||||||||||||
| } from '@/providers/utils' | ||||||||||||||||||||||||||
| // Get current Ollama models dynamically | ||||||||||||||||||||||||||
| const getCurrentOllamaModels = () => { | ||||||||||||||||||||||||||
| return useOllamaStore.getState().models | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| import { useOllamaStore } from '@/stores/ollama/store' | ||||||||||||||||||||||||||
Comment on lines
+16
to
21
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Move the import statement before the function definition to fix the reference error.
Suggested change
| ||||||||||||||||||||||||||
| import type { ToolResponse } from '@/tools/types' | ||||||||||||||||||||||||||
| @@ -213,14 +219,18 @@ Create a system prompt appropriately detailed for the request, using clear langu | ||||||||||||||||||||||||||
| password: true, | ||||||||||||||||||||||||||
| connectionDroppable: false, | ||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||
| // Hide API key for all hosted models when running on hosted version | ||||||||||||||||||||||||||
| // Hide API key for hosted models and Ollama models | ||||||||||||||||||||||||||
| condition: isHosted | ||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||
| field: 'model', | ||||||||||||||||||||||||||
| value: getHostedModels(), | ||||||||||||||||||||||||||
| not: true, // Show for all models EXCEPT those listed | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| : undefined, // Show for all models in non-hosted environments | ||||||||||||||||||||||||||
| : () => ({ | ||||||||||||||||||||||||||
| field: 'model', | ||||||||||||||||||||||||||
| value: getCurrentOllamaModels(), | ||||||||||||||||||||||||||
| not: true, // Show for all models EXCEPT Ollama models | ||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| id: 'azureEndpoint', | ||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This function references
useOllamaStorebefore it's imported on line 21, which will cause a ReferenceError at runtime.