mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Add custom openai proxy model name and embedding (#305)
This commit is contained in:
parent
4635d5ae66
commit
5913fbb31f
10 changed files with 69 additions and 12 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ export interface LangChainParams {
|
|||
openRouterModel: string,
|
||||
lmStudioBaseUrl: string,
|
||||
openAIProxyBaseUrl?: string,
|
||||
openAIProxyModelName?: string,
|
||||
openAIEmbeddingProxyBaseUrl?: string,
|
||||
openAIEmbeddingProxyModelName?: string,
|
||||
}
|
||||
|
||||
export interface SetChainOptions {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ const Chat: React.FC<ChatProps> = ({
|
|||
// 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
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ const ChatIcons: React.FC<ChatIconsProps> = ({
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -131,6 +131,9 @@ export const DEFAULT_SETTINGS: CopilotSettings = {
|
|||
contextTurns: 15,
|
||||
userSystemPrompt: '',
|
||||
openAIProxyBaseUrl: '',
|
||||
openAIProxyModelName: '',
|
||||
openAIEmbeddingProxyBaseUrl: '',
|
||||
openAIEmbeddingProxyModelName: '',
|
||||
ollamaModel: 'llama2',
|
||||
ollamaBaseUrl: '',
|
||||
lmStudioBaseUrl: 'http://localhost:1234/v1',
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<AdvancedSettingsProps> = ({
|
||||
openAIProxyBaseUrl,
|
||||
setOpenAIProxyBaseUrl,
|
||||
openAIProxyModelName,
|
||||
setOpenAIProxyModelName,
|
||||
openAIEmbeddingProxyBaseUrl,
|
||||
setOpenAIEmbeddingProxyBaseUrl,
|
||||
openAIEmbeddingProxyModelName,
|
||||
setOpenAIEmbeddingProxyModelName,
|
||||
userSystemPrompt,
|
||||
setUserSystemPrompt,
|
||||
}) => {
|
||||
|
|
@ -20,15 +32,36 @@ const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({
|
|||
<br/>
|
||||
<h1>Advanced Settings</h1>
|
||||
<div className="warning-message">
|
||||
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.
|
||||
</div>
|
||||
<TextComponent
|
||||
name="OpenAI Proxy Base URL"
|
||||
description="For providers that shares the same API as OpenAI."
|
||||
description="For providers that share the same API as OpenAI."
|
||||
value={openAIProxyBaseUrl}
|
||||
onChange={setOpenAIProxyBaseUrl}
|
||||
placeholder="https://openai.example.com/v1"
|
||||
/>
|
||||
<TextComponent
|
||||
name="OpenAI Proxy Model Name"
|
||||
description="The actual model name you want to use with your provider. Overrides the OpenAI model name you pick in the Copilot Chat model selection. Note: non-OpenAI models picked will not be overridden!"
|
||||
value={openAIProxyModelName}
|
||||
onChange={setOpenAIProxyModelName}
|
||||
placeholder="gpt-3.5-turbo"
|
||||
/>
|
||||
<TextComponent
|
||||
name="OpenAI Embedding Proxy Base URL"
|
||||
description="For embedding providers that share the same API as OpenAI."
|
||||
value={openAIEmbeddingProxyBaseUrl}
|
||||
onChange={setOpenAIEmbeddingProxyBaseUrl}
|
||||
placeholder="https://openai.example.com/v1"
|
||||
/>
|
||||
<TextComponent
|
||||
name="OpenAI Embedding Proxy Model Name"
|
||||
description="The actual embedding model name you want to use with your provider. Overrides the OpenAI embedding model name you pick above. Note: non-OpenAI models picked will not be overridden!"
|
||||
value={openAIEmbeddingProxyModelName}
|
||||
onChange={setOpenAIEmbeddingProxyModelName}
|
||||
placeholder="text-embedding-ada-002"
|
||||
/>
|
||||
<TextAreaComponent
|
||||
name="User System Prompt"
|
||||
description="Warning: It will override the default system prompt for all messages!"
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ export default function SettingsMain({ plugin, reloadPlugin }: SettingsMainProps
|
|||
// Advanced settings
|
||||
const [userSystemPrompt, setUserSystemPrompt] = useState(plugin.settings.userSystemPrompt);
|
||||
const [openAIProxyBaseUrl, setOpenAIProxyBaseUrl] = useState(plugin.settings.openAIProxyBaseUrl);
|
||||
const [openAIProxyModelName, setOpenAIProxyModelName] = useState(plugin.settings.openAIProxyModelName);
|
||||
const [openAIEmbeddingProxyBaseUrl, setOpenAIEmbeddingProxyBaseUrl] = useState(plugin.settings.openAIEmbeddingProxyBaseUrl);
|
||||
const [openAIEmbeddingProxyModelName, setOpenAIEmbeddingProxyModelName] = useState(plugin.settings.openAIEmbeddingProxyModelName);
|
||||
|
||||
// Local Copilot Settings
|
||||
const [lmStudioBaseUrl, setlmStudioBaseUrl] = useState(plugin.settings.lmStudioBaseUrl);
|
||||
|
|
@ -79,6 +82,9 @@ export default function SettingsMain({ plugin, reloadPlugin }: SettingsMainProps
|
|||
// Advanced settings
|
||||
plugin.settings.userSystemPrompt = userSystemPrompt;
|
||||
plugin.settings.openAIProxyBaseUrl = openAIProxyBaseUrl;
|
||||
plugin.settings.openAIProxyModelName = openAIProxyModelName;
|
||||
plugin.settings.openAIEmbeddingProxyBaseUrl = openAIEmbeddingProxyBaseUrl;
|
||||
plugin.settings.openAIEmbeddingProxyModelName = openAIEmbeddingProxyModelName;
|
||||
|
||||
// Local Copilot Settings
|
||||
plugin.settings.lmStudioBaseUrl = lmStudioBaseUrl;
|
||||
|
|
@ -204,6 +210,12 @@ export default function SettingsMain({ plugin, reloadPlugin }: SettingsMainProps
|
|||
<AdvancedSettings
|
||||
openAIProxyBaseUrl={openAIProxyBaseUrl}
|
||||
setOpenAIProxyBaseUrl={setOpenAIProxyBaseUrl}
|
||||
openAIProxyModelName={openAIProxyModelName}
|
||||
setOpenAIProxyModelName={setOpenAIProxyModelName}
|
||||
openAIEmbeddingProxyBaseUrl={openAIEmbeddingProxyBaseUrl}
|
||||
setOpenAIEmbeddingProxyBaseUrl={setOpenAIEmbeddingProxyBaseUrl}
|
||||
openAIEmbeddingProxyModelName={openAIEmbeddingProxyModelName}
|
||||
setOpenAIEmbeddingProxyModelName={setOpenAIEmbeddingProxyModelName}
|
||||
userSystemPrompt={userSystemPrompt}
|
||||
setUserSystemPrompt={setUserSystemPrompt}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue