Skip to content

Commit

Permalink
[v2.4.7] Add gemini pro model (logancyang#225)
Browse files Browse the repository at this point in the history
* Add gemino pro model and google api setting
  • Loading branch information
logancyang committed Jan 8, 2024
1 parent b90a165 commit c74737b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "copilot",
"name": "Copilot",
"version": "2.4.6",
"version": "2.4.7",
"minAppVersion": "0.15.0",
"description": "A ChatGPT Copilot in Obsidian.",
"author": "Logan Yang",
Expand Down
31 changes: 26 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-copilot",
"version": "2.4.6",
"version": "2.4.7",
"description": "ChatGPT integration for Obsidian",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@huggingface/inference": "^1.8.0",
"@koa/cors": "^4.0.0",
"@langchain/google-genai": "^0.0.7",
"@tabler/icons-react": "^2.14.0",
"@types/pouchdb": "^6.4.0",
"axios": "^1.3.4",
Expand Down
24 changes: 24 additions & 0 deletions src/aiState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
COHEREAI,
ChatModelDisplayNames,
DEFAULT_SYSTEM_PROMPT,
GOOGLE,
GOOGLE_MODELS,
HUGGINGFACE,
LOCALAI,
OPENAI,
Expand All @@ -19,6 +21,7 @@ import {
import { ChatMessage } from '@/sharedState';
import { getModelName, isSupportedChain } from '@/utils';
import VectorDBManager, { MemoryVector } from '@/vectorDBManager';
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import {
BaseChain,
ConversationChain,
Expand Down Expand Up @@ -62,6 +65,8 @@ interface ModelConfig {
azureOpenAIApiInstanceName?: string,
azureOpenAIApiDeploymentName?: string,
azureOpenAIApiVersion?: string,
// Google API key https://api.js.langchain.com/classes/langchain_google_genai.ChatGoogleGenerativeAI.html
apiKey?: string,
openAIProxyBaseUrl?: string,
localAIModel?: string,
}
Expand All @@ -76,6 +81,7 @@ export interface LangChainParams {
azureOpenAIApiDeploymentName: string,
azureOpenAIApiVersion: string,
azureOpenAIApiEmbeddingDeploymentName: string,
googleApiKey?: string,
model: string,
modelDisplayName: string,
temperature: number,
Expand Down Expand Up @@ -135,6 +141,7 @@ class AIState {
private static chatOpenAI: ChatOpenAI;
private static chatAnthropic: ChatAnthropic;
private static azureChatOpenAI: ChatOpenAI;
private static chatGoogleGenerativeAI: ChatGoogleGenerativeAI;
private static chain: BaseChain;
private static retrievalChain: RetrievalQAChain;
private static conversationalRetrievalChain: ConversationalRetrievalQAChain;
Expand Down Expand Up @@ -207,6 +214,7 @@ class AIState {
temperature,
maxTokens,
openAIProxyBaseUrl,
googleApiKey,
localAIModel,
} = this.langChainParams;

Expand Down Expand Up @@ -245,6 +253,11 @@ class AIState {
azureOpenAIApiVersion: azureOpenAIApiVersion,
};
break;
case GOOGLE:
config = {
...config,
apiKey: googleApiKey,
};
}

return config;
Expand Down Expand Up @@ -288,6 +301,14 @@ class AIState {
};
}

for (const modelDisplayNameKey of GOOGLE_MODELS) {
modelMap[modelDisplayNameKey] = {
hasApiKey: Boolean(this.langChainParams.googleApiKey),
AIConstructor: ChatGoogleGenerativeAI,
vendor: GOOGLE,
};
}

this.modelMap = modelMap;
}

Expand Down Expand Up @@ -396,6 +417,9 @@ class AIState {
case AZURE_OPENAI:
AIState.azureChatOpenAI = newModelInstance as ChatOpenAI;
break;
case GOOGLE:
AIState.chatGoogleGenerativeAI = newModelInstance as ChatGoogleGenerativeAI;
break;
}

AIState.chatModel = newModelInstance;
Expand Down
1 change: 1 addition & 0 deletions src/components/ChatComponents/ChatIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const ChatIcons: React.FC<ChatIconsProps> = ({
<option value={ChatModelDisplayNames.AZURE_GPT_35_TURBO_16K}>{ChatModelDisplayNames.AZURE_GPT_35_TURBO_16K}</option>
<option value={ChatModelDisplayNames.AZURE_GPT_4}>{ChatModelDisplayNames.AZURE_GPT_4}</option>
<option value={ChatModelDisplayNames.AZURE_GPT_4_32K}>{ChatModelDisplayNames.AZURE_GPT_4_32K}</option>
<option value={ChatModelDisplayNames.GEMINI_PRO}>{ChatModelDisplayNames.GEMINI_PRO}</option>
<option value={ChatModelDisplayNames.LOCAL_AI}>{ChatModelDisplayNames.LOCAL_AI}</option>
</select>
<span className="tooltip-text">Model Selection</span>
Expand Down
10 changes: 10 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ChatModels {
CLAUDE_INSTANT_1_100K = 'claude-instant-1-100k',
AZURE_GPT_35_TURBO = 'gpt-35-turbo',
AZURE_GPT_35_TURBO_16K = 'gpt-35-turbo-16k',
GEMINI_PRO = 'gemini-pro',
}

export enum ChatModelDisplayNames {
Expand All @@ -33,6 +34,7 @@ export enum ChatModelDisplayNames {
AZURE_GPT_35_TURBO_16K = 'AZURE GPT-3.5-16K',
AZURE_GPT_4 = 'AZURE GPT-4',
AZURE_GPT_4_32K = 'AZURE GPT-4 32K',
GEMINI_PRO = 'GEMINI PRO',
LOCAL_AI = 'LocalAI',
}

Expand All @@ -59,6 +61,10 @@ export const CLAUDE_MODELS = new Set([
ChatModelDisplayNames.CLAUDE_INSTANT_1_100K,
]);

export const GOOGLE_MODELS = new Set([
ChatModelDisplayNames.GEMINI_PRO,
]);

export const DISPLAY_NAME_TO_MODEL: Record<string, string> = {
[ChatModelDisplayNames.GPT_35_TURBO]: ChatModels.GPT_35_TURBO,
[ChatModelDisplayNames.GPT_35_TURBO_16K]: ChatModels.GPT_35_TURBO_16K,
Expand All @@ -73,6 +79,7 @@ export const DISPLAY_NAME_TO_MODEL: Record<string, string> = {
[ChatModelDisplayNames.AZURE_GPT_35_TURBO_16K]: ChatModels.AZURE_GPT_35_TURBO_16K,
[ChatModelDisplayNames.AZURE_GPT_4]: ChatModels.GPT_4,
[ChatModelDisplayNames.AZURE_GPT_4_32K]: ChatModels.GPT_4_32K,
[ChatModelDisplayNames.GEMINI_PRO]: ChatModels.GEMINI_PRO,
};

// Model Providers
Expand All @@ -81,12 +88,14 @@ export const HUGGINGFACE = 'huggingface';
export const COHEREAI = 'cohereai';
export const AZURE_OPENAI = 'azure_openai';
export const ANTHROPIC = 'anthropic';
export const GOOGLE = 'google';
export const LOCALAI = 'localai';

export const VENDOR_MODELS: Record<string, Set<string>> = {
[OPENAI]: OPENAI_MODELS,
[AZURE_OPENAI]: AZURE_MODELS,
[ANTHROPIC]: CLAUDE_MODELS,
[GOOGLE]: GOOGLE_MODELS,
};

// Embedding Models
Expand All @@ -106,6 +115,7 @@ export const DEFAULT_SETTINGS: CopilotSettings = {
azureOpenAIApiDeploymentName: '',
azureOpenAIApiVersion: '',
azureOpenAIApiEmbeddingDeploymentName: '',
googleApiKey: '',
defaultModel: ChatModels.GPT_4_TURBO,
defaultModelDisplayName: ChatModelDisplayNames.GPT_4_TURBO,
temperature: 0.7,
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface CopilotSettings {
azureOpenAIApiDeploymentName: string;
azureOpenAIApiVersion: string;
azureOpenAIApiEmbeddingDeploymentName: string;
googleApiKey: string;
defaultModel: string;
defaultModelDisplayName: string;
temperature: number;
Expand Down Expand Up @@ -482,6 +483,7 @@ export default class CopilotPlugin extends Plugin {
azureOpenAIApiDeploymentName,
azureOpenAIApiVersion,
azureOpenAIApiEmbeddingDeploymentName,
googleApiKey,
temperature,
maxTokens,
contextTurns,
Expand All @@ -498,6 +500,7 @@ export default class CopilotPlugin extends Plugin {
azureOpenAIApiDeploymentName,
azureOpenAIApiVersion,
azureOpenAIApiEmbeddingDeploymentName,
googleApiKey,
localAIModel,
model: this.settings.defaultModel,
modelDisplayName: this.settings.defaultModelDisplayName,
Expand Down
27 changes: 27 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class CopilotSettingTab extends PluginSettingTab {
ChatModelDisplayNames.AZURE_GPT_35_TURBO_16K,
ChatModelDisplayNames.AZURE_GPT_4,
ChatModelDisplayNames.AZURE_GPT_4_32K,
ChatModelDisplayNames.GEMINI_PRO,
ChatModelDisplayNames.LOCAL_AI,
];

Expand Down Expand Up @@ -205,6 +206,32 @@ export class CopilotSettingTab extends PluginSettingTab {
// }
// );

containerEl.createEl('h6', { text: 'Google Gemini API' });

new Setting(containerEl)
.setName("Your Google API key")
.setDesc(
createFragment((frag) => {
frag.appendText("If you have Google Cloud, you can get Gemini API key ");
frag.createEl('a', {
text: "here",
href: "https://makersuite.google.com/app/apikey"
});
})
)
.addText((text) => {
text.inputEl.type = "password";
text.inputEl.style.width = "100%";
text
.setPlaceholder("Google API key")
.setValue(this.plugin.settings.googleApiKey)
.onChange(async (value) => {
this.plugin.settings.googleApiKey = value;
await this.plugin.saveSettings();
})
}
);

containerEl.createEl('h6', { text: 'Azure OpenAI API' });

new Setting(containerEl)
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"2.4.3": "0.15.0",
"2.4.4": "0.15.0",
"2.4.5": "0.15.0",
"2.4.6": "0.15.0"
"2.4.6": "0.15.0",
"2.4.7": "0.15.0"
}

0 comments on commit c74737b

Please sign in to comment.