-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(llm): redo llm feature and tools #7270
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
Open
perfectra1n
wants to merge
3
commits into
main
Choose a base branch
from
feat/redo-llm-feature-take2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| /** | ||
| * Pipeline Configuration - Phase 1 Implementation | ||
| * | ||
| * Centralized configuration for the LLM pipeline: | ||
| * - Single source of truth for pipeline settings | ||
| * - Type-safe configuration access | ||
| * - Sensible defaults | ||
| * - Backward compatible with existing options | ||
| * | ||
| * Design: Simple, focused configuration without complex validation | ||
| */ | ||
|
|
||
| import options from '../../options.js'; | ||
|
|
||
| /** | ||
| * Pipeline configuration interface | ||
| */ | ||
| export interface PipelineConfig { | ||
| // Tool execution settings | ||
| maxToolIterations: number; | ||
| toolTimeout: number; | ||
| enableTools: boolean; | ||
|
|
||
| // Streaming settings | ||
| enableStreaming: boolean; | ||
| streamChunkSize: number; | ||
|
|
||
| // Debug settings | ||
| enableDebugLogging: boolean; | ||
| enableMetrics: boolean; | ||
|
|
||
| // Context settings | ||
| maxContextLength: number; | ||
| enableAdvancedContext: boolean; | ||
|
|
||
| // Phase 3: Provider-specific settings | ||
| ollamaContextWindow: number; | ||
| ollamaMaxTools: number; | ||
| enableQueryBasedFiltering: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Default pipeline configuration | ||
| */ | ||
| export const DEFAULT_PIPELINE_CONFIG: PipelineConfig = { | ||
| maxToolIterations: 5, | ||
| toolTimeout: 30000, | ||
| enableTools: true, | ||
| enableStreaming: true, | ||
| streamChunkSize: 256, | ||
| enableDebugLogging: false, | ||
| enableMetrics: false, | ||
| maxContextLength: 10000, | ||
| enableAdvancedContext: true, | ||
| // Phase 3: Provider-specific defaults | ||
| ollamaContextWindow: 8192, // 4x increase from 2048 | ||
| ollamaMaxTools: 3, // Local models work best with 3 tools | ||
| enableQueryBasedFiltering: true // Enable intelligent tool selection | ||
| }; | ||
|
|
||
| /** | ||
| * Pipeline Configuration Service | ||
| * Provides centralized access to pipeline configuration | ||
| */ | ||
| export class PipelineConfigService { | ||
| private config: PipelineConfig | null = null; | ||
| private readonly CACHE_DURATION = 60000; // 1 minute cache | ||
| private lastLoadTime: number = 0; | ||
|
|
||
| /** | ||
| * Get pipeline configuration | ||
| * Lazy loads and caches configuration | ||
| * | ||
| * Note: This method has a theoretical race condition where multiple concurrent calls | ||
| * could trigger duplicate loadConfiguration() calls. This is acceptable because: | ||
| * 1. loadConfiguration() is a simple synchronous read from options (no side effects) | ||
| * 2. Both loads will produce identical results | ||
| * 3. The overhead of rare duplicate loads is negligible compared to async locking complexity | ||
| * 4. Config changes are infrequent (typically only during app initialization) | ||
| * | ||
| * If this becomes a performance issue, consider making this async with a mutex. | ||
| */ | ||
| getConfig(): PipelineConfig { | ||
| // Check if we need to reload configuration | ||
| if (!this.config || Date.now() - this.lastLoadTime > this.CACHE_DURATION) { | ||
| this.config = this.loadConfiguration(); | ||
| this.lastLoadTime = Date.now(); | ||
| } | ||
|
|
||
| return this.config; | ||
| } | ||
|
|
||
| /** | ||
| * Load configuration from options | ||
| */ | ||
| private loadConfiguration(): PipelineConfig { | ||
| return { | ||
| // Tool execution settings | ||
| maxToolIterations: this.getIntOption('llmMaxToolIterations', DEFAULT_PIPELINE_CONFIG.maxToolIterations), | ||
| toolTimeout: this.getIntOption('llmToolTimeout', DEFAULT_PIPELINE_CONFIG.toolTimeout), | ||
| enableTools: this.getBoolOption('llmToolsEnabled', DEFAULT_PIPELINE_CONFIG.enableTools), | ||
|
|
||
| // Streaming settings | ||
| enableStreaming: this.getBoolOption('llmStreamingEnabled', DEFAULT_PIPELINE_CONFIG.enableStreaming), | ||
| streamChunkSize: this.getIntOption('llmStreamChunkSize', DEFAULT_PIPELINE_CONFIG.streamChunkSize), | ||
|
|
||
| // Debug settings | ||
| enableDebugLogging: this.getBoolOption('llmDebugEnabled', DEFAULT_PIPELINE_CONFIG.enableDebugLogging), | ||
| enableMetrics: this.getBoolOption('llmMetricsEnabled', DEFAULT_PIPELINE_CONFIG.enableMetrics), | ||
|
|
||
| // Context settings | ||
| maxContextLength: this.getIntOption('llmMaxContextLength', DEFAULT_PIPELINE_CONFIG.maxContextLength), | ||
| enableAdvancedContext: this.getBoolOption('llmAdvancedContext', DEFAULT_PIPELINE_CONFIG.enableAdvancedContext), | ||
|
|
||
| // Phase 3: Provider-specific settings | ||
| ollamaContextWindow: this.getIntOption('llmOllamaContextWindow', DEFAULT_PIPELINE_CONFIG.ollamaContextWindow), | ||
| ollamaMaxTools: this.getIntOption('llmOllamaMaxTools', DEFAULT_PIPELINE_CONFIG.ollamaMaxTools), | ||
| enableQueryBasedFiltering: this.getBoolOption('llmEnableQueryFiltering', DEFAULT_PIPELINE_CONFIG.enableQueryBasedFiltering) | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Get boolean option with default | ||
| */ | ||
| private getBoolOption(key: string, defaultValue: boolean): boolean { | ||
| try { | ||
| const value = (options as any).getOptionBool(key); | ||
| return value !== undefined ? value : defaultValue; | ||
| } catch { | ||
| return defaultValue; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get integer option with default | ||
| */ | ||
| private getIntOption(key: string, defaultValue: number): number { | ||
| try { | ||
| const value = (options as any).getOption(key); | ||
| if (value === null || value === undefined) { | ||
| return defaultValue; | ||
| } | ||
| const parsed = parseInt(value, 10); | ||
| return isNaN(parsed) ? defaultValue : parsed; | ||
| } catch { | ||
| return defaultValue; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get string option with default | ||
| */ | ||
| private getStringOption(key: string, defaultValue: string): string { | ||
| try { | ||
| const value = (options as any).getOption(key); | ||
| return value !== null && value !== undefined ? String(value) : defaultValue; | ||
| } catch { | ||
| return defaultValue; | ||
| } | ||
| } | ||
|
Comment on lines
+153
to
+160
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. |
||
|
|
||
| /** | ||
| * Force reload configuration | ||
| */ | ||
| reload(): void { | ||
| this.config = null; | ||
| this.lastLoadTime = 0; | ||
| } | ||
|
|
||
| /** | ||
| * Get specific configuration values | ||
| */ | ||
| getMaxToolIterations(): number { | ||
| return this.getConfig().maxToolIterations; | ||
| } | ||
|
|
||
| getToolTimeout(): number { | ||
| return this.getConfig().toolTimeout; | ||
| } | ||
|
|
||
| isToolsEnabled(): boolean { | ||
| return this.getConfig().enableTools; | ||
| } | ||
|
|
||
| isStreamingEnabled(): boolean { | ||
| return this.getConfig().enableStreaming; | ||
| } | ||
|
|
||
| getStreamChunkSize(): number { | ||
| return this.getConfig().streamChunkSize; | ||
| } | ||
|
|
||
| isDebugLoggingEnabled(): boolean { | ||
| return this.getConfig().enableDebugLogging; | ||
| } | ||
|
|
||
| isMetricsEnabled(): boolean { | ||
| return this.getConfig().enableMetrics; | ||
| } | ||
|
|
||
| getMaxContextLength(): number { | ||
| return this.getConfig().maxContextLength; | ||
| } | ||
|
|
||
| isAdvancedContextEnabled(): boolean { | ||
| return this.getConfig().enableAdvancedContext; | ||
| } | ||
|
|
||
| // Phase 3: Provider-specific getters | ||
| getOllamaContextWindow(): number { | ||
| return this.getConfig().ollamaContextWindow; | ||
| } | ||
|
|
||
| getOllamaMaxTools(): number { | ||
| return this.getConfig().ollamaMaxTools; | ||
| } | ||
|
|
||
| isQueryBasedFilteringEnabled(): boolean { | ||
| return this.getConfig().enableQueryBasedFiltering; | ||
| } | ||
| } | ||
|
|
||
| // Export singleton instance | ||
| const pipelineConfigService = new PipelineConfigService(); | ||
| export default pipelineConfigService; | ||
|
|
||
| /** | ||
| * Export convenience functions | ||
| */ | ||
| export function getPipelineConfig(): PipelineConfig { | ||
| return pipelineConfigService.getConfig(); | ||
| } | ||
|
|
||
| export function reloadPipelineConfig(): void { | ||
| pipelineConfigService.reload(); | ||
| } | ||
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.
Casting
optionstoanybypasses TypeScript's type safety. While this might be necessary if theoptionsobject is not strongly typed, it's a practice that should be avoided. Consider defining a minimal interface for the parts ofoptionsyou are using, or use a more specific type assertion thananyto improve maintainability and prevent potential runtime errors.