Skip to content

feat(ollama): added streaming & tool call support for ollama, updated docs#884

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/ollama
Aug 5, 2025
Merged

feat(ollama): added streaming & tool call support for ollama, updated docs#884
waleedlatif1 merged 1 commit intostagingfrom
fix/ollama

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

Added streaming & tool call support for ollama, updated docs

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

Screenshot 2025-08-05 at 2 31 30 PM

@vercel
Copy link

vercel bot commented Aug 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2025 10:03pm
sim ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2025 10:03pm

@waleedlatif1 waleedlatif1 merged commit 746b877 into staging Aug 5, 2025
4 checks passed
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR significantly enhances the Ollama provider by adding streaming responses and tool calling capabilities, bringing it to feature parity with other providers in the system. The changes transform Ollama from a basic local model provider into a fully-featured AI integration that supports complex workflows.

The core enhancement is in the Ollama provider (apps/sim/providers/ollama/index.ts), which now implements streaming through a custom createReadableStreamFromOllamaStream helper function and includes a complete tool execution loop with proper timing tracking. The provider integrates with shared utility functions to ensure consistent behavior across all providers.

To support dynamic model management, the Ollama store (apps/sim/stores/ollama/store.ts) has been upgraded with client-side model fetching capabilities, including loading states and auto-initialization. A new API endpoint (apps/sim/app/api/providers/ollama/models/route.ts) provides a bridge between the frontend and local Ollama server for dynamic model discovery.

The UI system has been enhanced to support dynamic conditions through function-based condition evaluation in both the block type definitions and resolver. This enables sub-blocks to show/hide based on runtime state, specifically allowing the API key field to be hidden for Ollama models since they run locally and don't require authentication.

Documentation and deployment have been streamlined with updated README instructions and a comprehensive Docker Compose configuration that includes the full application stack alongside Ollama. The changes also include environment variable configuration and removal of redundant shell scripts in favor of standardized Docker Compose workflows.

Confidence score: 1/5

  • This PR contains a critical runtime error that will cause the application to crash when using Ollama models
  • Score severely lowered due to import-before-use violation in apps/sim/blocks/blocks/agent.ts where getCurrentOllamaModels function uses useOllamaStore before it's imported
  • Pay immediate attention to apps/sim/blocks/blocks/agent.ts - the function definition on lines 16-19 must be moved after the import on line 21

14 files reviewed, 7 comments

Edit Code Review Bot Settings | Greptile

Comment on lines +28 to +29
ollamaStream: any,
onComplete?: (content: string, usage?: any) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider using more specific types instead of any for better type safety

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

// Helper function to check for forced tool usage in responses
const checkForForcedToolUsage = (
response: any,
toolChoice: string | { type: string; function?: { name: string }; name?: string; any?: any }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: union type parameter is quite complex - consider extracting to a dedicated type definition

forcedTools,
usedForcedTools
)
hasUsedForcedTool = result.hasUsedForcedTool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: variable hasUsedForcedTool is accessed before declaration - this will cause a runtime error

Suggested change
hasUsedForcedTool = result.hasUsedForcedTool
// Track if a forced tool has been used
let hasUsedForcedTool = false
// Helper function to check for forced tool usage in responses
const checkForForcedToolUsage = (
response: any,
toolChoice: string | { type: string; function?: { name: string }; name?: string; any?: any }
) => {
if (typeof toolChoice === 'object' && response.choices[0]?.message?.tool_calls) {
const toolCallsResponse = response.choices[0].message.tool_calls
const result = trackForcedToolUsage(
toolCallsResponse,
toolChoice,
logger,
'ollama',
forcedTools,
usedForcedTools
)
hasUsedForcedTool = result.hasUsedForcedTool
usedForcedTools = result.usedForcedTools
}
}


// Create a new error with timing information
const enhancedError = new Error(error instanceof Error ? error.message : String(error))
// @ts-ignore - Adding timing property to the error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: using @ts-ignore bypasses type checking - consider defining a proper error interface with timing property

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

Comment on lines +16 to +19
// Get current Ollama models dynamically
const getCurrentOllamaModels = () => {
return useOllamaStore.getState().models
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This function references useOllamaStore before it's imported on line 21, which will cause a ReferenceError at runtime.

Comment on lines +16 to 21
// Get current Ollama models dynamically
const getCurrentOllamaModels = () => {
return useOllamaStore.getState().models
}

import { useOllamaStore } from '@/stores/ollama/store'
Copy link
Contributor

Choose a reason for hiding this comment

The 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
// Get current Ollama models dynamically
const getCurrentOllamaModels = () => {
return useOllamaStore.getState().models
}
import { useOllamaStore } from '@/stores/ollama/store'
import { useOllamaStore } from '@/stores/ollama/store'
// Get current Ollama models dynamically
const getCurrentOllamaModels = () => {
return useOllamaStore.getState().models
}

const hasUserKey = !!userProvidedKey

// Ollama models don't require API keys - they run locally
const isOllamaModel = provider === 'ollama' || useOllamaStore.getState().models.includes(model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using useOllamaStore.getState().models.includes(model) in server-side code could cause issues if the store is not properly initialized on the server. Consider adding a null check or server-side guard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant