-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: [] }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.