diff --git a/src/LLMProviders/chatModelManager.ts b/src/LLMProviders/chatModelManager.ts index f46b0c66..6de1f099 100644 --- a/src/LLMProviders/chatModelManager.ts +++ b/src/LLMProviders/chatModelManager.ts @@ -57,6 +57,7 @@ export default class ChatModelManager { const providerConfig = { [ModelProviders.OPENAI]: { + modelName: params.openAIProxyModelName || params.model, openAIApiKey: params.openAIApiKey, maxTokens: params.maxTokens, openAIProxyBaseUrl: params.openAIProxyBaseUrl, diff --git a/src/LLMProviders/embeddingManager.ts b/src/LLMProviders/embeddingManager.ts index e9a4561a..cc95eed4 100644 --- a/src/LLMProviders/embeddingManager.ts +++ b/src/LLMProviders/embeddingManager.ts @@ -28,23 +28,22 @@ export default class EmbeddingManager { azureOpenAIApiInstanceName, azureOpenAIApiVersion, azureOpenAIApiEmbeddingDeploymentName, - openAIProxyBaseUrl, + openAIEmbeddingProxyBaseUrl, + openAIEmbeddingProxyModelName, } = this.langChainParams; - // Note that openAIProxyBaseUrl has the highest priority. - // If openAIProxyBaseUrl is set, it overrides both chat and embedding models. const OpenAIEmbeddingsAPI = openAIApiKey ? ( - openAIProxyBaseUrl ? + openAIEmbeddingProxyBaseUrl ? new ProxyOpenAIEmbeddings({ - modelName: this.langChainParams.embeddingModel, + modelName: openAIEmbeddingProxyModelName || this.langChainParams.embeddingModel, openAIApiKey, maxRetries: 3, maxConcurrency: 3, timeout: 10000, - openAIProxyBaseUrl, + openAIEmbeddingProxyBaseUrl, }) : new OpenAIEmbeddings({ - modelName: this.langChainParams.embeddingModel, + modelName: openAIEmbeddingProxyModelName || this.langChainParams.embeddingModel, openAIApiKey, maxRetries: 3, maxConcurrency: 3, @@ -87,7 +86,7 @@ export default class EmbeddingManager { default: console.error('No embedding provider set or no valid API key provided. Defaulting to OpenAI.'); return OpenAIEmbeddingsAPI || new OpenAIEmbeddings({ - modelName: this.langChainParams.embeddingModel, + modelName: openAIEmbeddingProxyModelName || this.langChainParams.embeddingModel, openAIApiKey: 'default-key', maxRetries: 3, maxConcurrency: 3, diff --git a/src/aiParams.ts b/src/aiParams.ts index 37285cb6..60a93101 100644 --- a/src/aiParams.ts +++ b/src/aiParams.ts @@ -51,6 +51,9 @@ export interface LangChainParams { openRouterModel: string, lmStudioBaseUrl: string, openAIProxyBaseUrl?: string, + openAIProxyModelName?: string, + openAIEmbeddingProxyBaseUrl?: string, + openAIEmbeddingProxyModelName?: string, } export interface SetChainOptions { diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 34d2ce8b..984b0ddb 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -161,7 +161,7 @@ const Chat: React.FC = ({ // Recursively get all note TFiles in the path noteFiles = await getNotesFromPath(vault, settings.chatNoteContextPath); } - if (settings.chatNoteContextTags.length > 0) { //prevent overriding chatNoteContextPath if not tags are used + if (settings.chatNoteContextTags?.length > 0) { // Get all notes with the specified tags // If path is provided, get all notes with the specified tags in the path // If path is not provided, get all notes with the specified tags diff --git a/src/components/ChatComponents/ChatIcons.tsx b/src/components/ChatComponents/ChatIcons.tsx index 77faad53..8f5477a2 100644 --- a/src/components/ChatComponents/ChatIcons.tsx +++ b/src/components/ChatComponents/ChatIcons.tsx @@ -86,7 +86,7 @@ const ChatIcons: React.FC = ({ const activeNoteOnMessage: ChatMessage = { sender: AI_SENDER, - message: `OK Feel free to ask me questions about [[${noteName}]]. \n\nPlease note that this is a retrieval-based QA for notes longer than the model context window. Specific questions are encouraged. For generic questions like 'give me a summary', 'brainstorm based on the content', Chat mode with *Send Note to Prompt* button used with a *long context model* is a more suitable choice. \n\n(This mode will be upgraded to work on the entire vault next)`, + message: `OK Feel free to ask me questions about [[${noteName}]]. \n\nPlease note that this is a retrieval-based QA for notes longer than the model context window. Specific questions are encouraged. For generic questions like 'give me a summary', 'brainstorm based on the content', Chat mode with *Send Note to Prompt* button used with a *long context model* is a more suitable choice. \n\n(A new mode will be added to work on the entire vault next)`, isVisible: true, }; addMessage(activeNoteOnMessage); diff --git a/src/constants.ts b/src/constants.ts index f5427fe7..a4e35dab 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -131,6 +131,9 @@ export const DEFAULT_SETTINGS: CopilotSettings = { contextTurns: 15, userSystemPrompt: '', openAIProxyBaseUrl: '', + openAIProxyModelName: '', + openAIEmbeddingProxyBaseUrl: '', + openAIEmbeddingProxyModelName: '', ollamaModel: 'llama2', ollamaBaseUrl: '', lmStudioBaseUrl: 'http://localhost:1234/v1', diff --git a/src/main.ts b/src/main.ts index 89915ac5..833b34ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -528,6 +528,9 @@ export default class CopilotPlugin extends Plugin { chainType: ChainType.LLM_CHAIN, // Set LLM_CHAIN as default ChainType options: { forceNewCreation: true } as SetChainOptions, openAIProxyBaseUrl: this.settings.openAIProxyBaseUrl, + openAIProxyModelName: this.settings.openAIProxyModelName, + openAIEmbeddingProxyBaseUrl: this.settings.openAIEmbeddingProxyBaseUrl, + openAIEmbeddingProxyModelName: this.settings.openAIEmbeddingProxyModelName, }; } } diff --git a/src/settings/SettingsPage.tsx b/src/settings/SettingsPage.tsx index a71ff5b1..01f7a663 100644 --- a/src/settings/SettingsPage.tsx +++ b/src/settings/SettingsPage.tsx @@ -25,6 +25,9 @@ export interface CopilotSettings { contextTurns: number; userSystemPrompt: string; openAIProxyBaseUrl: string; + openAIProxyModelName: string; + openAIEmbeddingProxyBaseUrl: string; + openAIEmbeddingProxyModelName: string; ollamaModel: string; ollamaBaseUrl: string; lmStudioBaseUrl: string; diff --git a/src/settings/components/AdvancedSettings.tsx b/src/settings/components/AdvancedSettings.tsx index 97d7d648..ee1bdb10 100644 --- a/src/settings/components/AdvancedSettings.tsx +++ b/src/settings/components/AdvancedSettings.tsx @@ -4,6 +4,12 @@ import { TextAreaComponent, TextComponent } from './SettingBlocks'; interface AdvancedSettingsProps { openAIProxyBaseUrl: string; setOpenAIProxyBaseUrl: (value: string) => void; + openAIProxyModelName: string; + setOpenAIProxyModelName: (value: string) => void; + openAIEmbeddingProxyBaseUrl: string; + setOpenAIEmbeddingProxyBaseUrl: (value: string) => void; + openAIEmbeddingProxyModelName: string; + setOpenAIEmbeddingProxyModelName: (value: string) => void; userSystemPrompt: string; setUserSystemPrompt: (value: string) => void; } @@ -11,6 +17,12 @@ interface AdvancedSettingsProps { const AdvancedSettings: React.FC = ({ openAIProxyBaseUrl, setOpenAIProxyBaseUrl, + openAIProxyModelName, + setOpenAIProxyModelName, + openAIEmbeddingProxyBaseUrl, + setOpenAIEmbeddingProxyBaseUrl, + openAIEmbeddingProxyModelName, + setOpenAIEmbeddingProxyModelName, userSystemPrompt, setUserSystemPrompt, }) => { @@ -20,15 +32,36 @@ const AdvancedSettings: React.FC = ({

Advanced Settings

- OpenAI Proxy Base URL overrides the default OpenAI base URL, meaning now your OpenAI models are routed to this provider instead! Clear this field to use OpenAI again. + OpenAI Proxy settings override the default OpenAI parameters, meaning now your OpenAI models are routed to this provider instead! Clear these fields to use OpenAI again.
+ + +