From d0a3ad7120c2f447a42bf22eb536879c74d06750 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 31 Jan 2025 18:15:00 -0800 Subject: [PATCH] Consolidated common consts into consts.ts --- blocks/blocks/agent.ts | 15 ++------------- blocks/blocks/translate.ts | 13 +++---------- blocks/consts.ts | 13 +++++++++++++ 3 files changed, 18 insertions(+), 23 deletions(-) create mode 100644 blocks/consts.ts diff --git a/blocks/blocks/agent.ts b/blocks/blocks/agent.ts index b7fe2e2ac2..2d908dae7d 100644 --- a/blocks/blocks/agent.ts +++ b/blocks/blocks/agent.ts @@ -1,18 +1,7 @@ import { AgentIcon } from '@/components/icons' import { BlockConfig } from '../types' import { ChatResponse } from '@/tools/openai/chat' - -// Map of models to their tools -const MODEL_TOOLS = { - 'gpt-4o': 'openai.chat', - 'o1': 'openai.chat', - 'o1-mini': 'openai.chat', - 'deepseek-v3': 'deepseek.chat', - 'deepseek-r1': 'deepseek.reasoner', - 'claude-3-5-sonnet-20241022': 'anthropic.chat', - 'gemini-pro': 'google.chat', - 'grok-2-latest': 'xai.chat' -} as const +import { MODEL_TOOLS, ModelType } from '../consts' export const AgentBlock: BlockConfig = { type: 'agent', @@ -33,7 +22,7 @@ export const AgentBlock: BlockConfig = { throw new Error('No model selected') } - const tool = MODEL_TOOLS[model as keyof typeof MODEL_TOOLS] + const tool = MODEL_TOOLS[model as ModelType] if (!tool) { throw new Error(`Invalid model selected: ${model}`) diff --git a/blocks/blocks/translate.ts b/blocks/blocks/translate.ts index 78d3443ef6..f21f59fd9d 100644 --- a/blocks/blocks/translate.ts +++ b/blocks/blocks/translate.ts @@ -1,14 +1,7 @@ import { TranslateIcon } from '@/components/icons' import { BlockConfig } from '../types' import { ChatResponse } from '@/tools/openai/chat' - -const MODEL_TOOLS = { - 'gpt-4o': 'openai.chat', - 'o1': 'openai.chat', - 'o1-mini': 'openai.chat', - 'claude-3-5-sonnet-20241022': 'anthropic.chat', - 'gemini-pro': 'google.chat', -} as const +import { MODEL_TOOLS, ModelType } from '../consts' const getTranslationPrompt = (targetLanguage: string) => `You are a highly skilled translator. Your task is to translate the given text into ${targetLanguage || 'English'} while: 1. Preserving the original meaning and nuance @@ -17,7 +10,7 @@ const getTranslationPrompt = (targetLanguage: string) => `You are a highly skill 4. Preserving formatting and special characters 5. Handling technical terms accurately -Only return the translated text without any explanations or notes. The translation should be natural and fluent in ${targetLanguage || 'English'}.` +Only return the translated text without any explanations or notes. The translation should be natural and fluent in ${targetLanguage || 'English'}.` export const TranslateBlock: BlockConfig = { type: 'translate', @@ -38,7 +31,7 @@ export const TranslateBlock: BlockConfig = { throw new Error('No model selected') } - const tool = MODEL_TOOLS[model as keyof typeof MODEL_TOOLS] + const tool = MODEL_TOOLS[model as ModelType] if (!tool) { throw new Error(`Invalid model selected: ${model}`) diff --git a/blocks/consts.ts b/blocks/consts.ts new file mode 100644 index 0000000000..c67cc63b9b --- /dev/null +++ b/blocks/consts.ts @@ -0,0 +1,13 @@ +export const MODEL_TOOLS = { + 'gpt-4o': 'openai.chat', + 'o1': 'openai.chat', + 'o1-mini': 'openai.chat', + 'deepseek-v3': 'deepseek.chat', + 'deepseek-r1': 'deepseek.reasoner', + 'claude-3-5-sonnet-20241022': 'anthropic.chat', + 'gemini-pro': 'google.chat', + 'grok-2-latest': 'xai.chat' +} as const + +export type ModelType = keyof typeof MODEL_TOOLS +export type ToolType = typeof MODEL_TOOLS[ModelType]