-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create and org types for different LLM models and sizes
- Loading branch information
Showing
7 changed files
with
172 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,8 +1,32 @@ | ||
import { LLMNodeConfiguration, LLMSize, LLMProvider, llmModels } from '../services/llm/types.js'; | ||
|
||
export const llmConfig = { | ||
DECISION_LLM_PROVIDER: 'anthropic', | ||
ANALYZE_LLM_PROVIDER: 'anthropic', | ||
GENERATION_LLM_PROVIDER: 'anthropic', | ||
RESPONSE_LLM_PROVIDER: 'anthropic', | ||
LARGE_LLM_MODEL: 'claude-3-opus-20240229', | ||
SMALL_LLM_MODEL: 'claude-3-5-sonnet-20240620', | ||
configuration: { | ||
large: { | ||
provider: LLMProvider.ANTHROPIC, | ||
model: llmModels.large.anthropic.claude3sonnet, | ||
}, | ||
small: { | ||
provider: LLMProvider.OPENAI, | ||
model: llmModels.small.openai.gpt_4o_mini, | ||
}, | ||
}, | ||
nodes: { | ||
decision: { | ||
size: LLMSize.SMALL, | ||
temperature: 0.2, | ||
} as LLMNodeConfiguration, | ||
analyze: { | ||
size: LLMSize.LARGE, | ||
temperature: 0.5, | ||
} as LLMNodeConfiguration, | ||
generation: { | ||
size: LLMSize.LARGE, | ||
temperature: 0.8, | ||
} as LLMNodeConfiguration, | ||
response: { | ||
size: LLMSize.SMALL, | ||
temperature: 0.8, | ||
} as LLMNodeConfiguration, | ||
}, | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,41 +1,38 @@ | ||
import { LLMProvider } from './types.js'; | ||
import { ChatOpenAI } from '@langchain/openai'; | ||
import { ChatAnthropic } from '@langchain/anthropic'; | ||
import { ChatOllama } from '@langchain/ollama'; | ||
import { config } from '../../config/index.js'; | ||
import { LLMProvider, LLMConfiguration, LLMNodeConfiguration } from './types.js'; | ||
import { llmConfig } from '../../config/llm.js'; | ||
import { config as appConfig } from '../../config/index.js'; | ||
|
||
export class LLMFactory { | ||
static createModel( | ||
provider: LLMProvider, | ||
model: string, | ||
temperature: number, | ||
): ChatOpenAI | ChatAnthropic | ChatOllama { | ||
switch (provider) { | ||
case 'openai': | ||
static createModel(node: LLMNodeConfiguration) { | ||
const cfg = llmConfig.configuration[node.size]; | ||
return this.createModelFromConfig(cfg, node.temperature); | ||
} | ||
|
||
static createModelFromConfig(config: LLMConfiguration, temperature: number) { | ||
switch (config.provider) { | ||
case LLMProvider.OPENAI: | ||
return new ChatOpenAI({ | ||
apiKey: config.llmConfig.OPENAI_API_KEY, | ||
model, | ||
apiKey: appConfig.llmConfig.OPENAI_API_KEY, | ||
model: config.model, | ||
temperature, | ||
}); | ||
|
||
case 'anthropic': | ||
case LLMProvider.ANTHROPIC: | ||
return new ChatAnthropic({ | ||
apiKey: config.llmConfig.ANTHROPIC_API_KEY, | ||
model, | ||
apiKey: appConfig.llmConfig.ANTHROPIC_API_KEY, | ||
model: config.model, | ||
temperature, | ||
}); | ||
|
||
case 'llama': | ||
case LLMProvider.OLLAMA: | ||
return new ChatOllama({ | ||
baseUrl: config.llmConfig.LLAMA_API_URL || '', | ||
model, | ||
baseUrl: appConfig.llmConfig.LLAMA_API_URL, | ||
model: config.model, | ||
temperature, | ||
format: 'json', | ||
maxRetries: 3, | ||
}); | ||
|
||
default: | ||
throw new Error(`Unsupported LLM provider: ${provider}`); | ||
throw new Error(`Unsupported LLM provider: ${config.provider}`); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,50 @@ | ||
export type LLMProvider = 'openai' | 'anthropic' | 'llama'; | ||
export enum LLMProvider { | ||
OPENAI = 'openai', | ||
ANTHROPIC = 'anthropic', | ||
OLLAMA = 'ollama', | ||
} | ||
|
||
export type LLMConfiguration = { | ||
provider: LLMProvider; | ||
model: string; | ||
}; | ||
|
||
export enum LLMSize { | ||
SMALL = 'small', | ||
LARGE = 'large', | ||
} | ||
|
||
export type LLMNodeConfiguration = { | ||
size: LLMSize; | ||
temperature: number; | ||
}; | ||
|
||
export const llmModels = { | ||
large: { | ||
anthropic: { | ||
claude3opus: 'claude-3-opus-20240229', | ||
claude3sonnet: 'claude-3-sonnet-20240229', | ||
}, | ||
openai: { | ||
gpt4turbo: 'gpt-4-turbo', | ||
gpt4: 'gpt-4', | ||
}, | ||
//placeholder | ||
ollama: { | ||
llama3: 'llama3.1', | ||
}, | ||
}, | ||
small: { | ||
openai: { | ||
gpt_4o_mini: 'gpt-4o-mini', | ||
gpt35turbo: 'gpt-3.5-turbo', | ||
}, | ||
anthropic: { | ||
claude3haiku: 'claude-3-haiku-20240307', | ||
}, | ||
//placeholder | ||
ollama: { | ||
llama3: 'llama3.1', | ||
}, | ||
}, | ||
}; |