Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support claude api keys #774

Merged
merged 8 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 80 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"dependencies": {
"@kangc/v-md-editor": "^2.3.16",
"@langchain/anthropic": "^0.1.9",
"@langchain/google-genai": "^0.0.7",
"@langchain/openai": "^0.0.12",
"@mdi/font": "^7.4.47",
Expand Down
Binary file added public/bots/claudeapi-20-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bots/claudeapi-21-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bots/claudeapi-haiku-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bots/claudeapi-instant-12-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bots/claudeapi-opus-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/bots/claudeapi-sonnet-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPI20Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPI20Bot extends ClaudeAPIBot {
static _className = "ClaudeAPI20Bot";
static _logoFilename = "claudeapi-20-logo.png";
static _model = "claude-2.0";
owais34 marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super();
}
}
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPI21Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPI21Bot extends ClaudeAPIBot {
static _className = "ClaudeAPI21Bot";
static _logoFilename = "claudeapi-21-logo.png";
static _model = "claude-2.1";
constructor() {
super();
}
}
43 changes: 43 additions & 0 deletions src/bots/anthropic/ClaudeAPIBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import store from "@/store";
import LangChainBot from "../LangChainBot";
import { ChatAnthropic } from "@langchain/anthropic";

export default class ClaudeAPIBot extends LangChainBot {
static _brandId = "claudeApi";
static _className = "ClaudeAPIBot";

constructor() {
super();
}

async _checkAvailability() {
let available = false;

if (store.state.claudeApi.apiKey) {
this.setupModel();
available = true;
}
return available;
}

_setupModel() {
const chatModel = new ChatAnthropic({
anthropicApiKey: store.state.claudeApi.apiKey,
anthropicApiUrl: store.state.claudeApi.alterUrl
? store.state.claudeApi.alterUrl
: "",
maxTokens: store.state.claudeApi.maxTokens,
temperature: store.state.claudeApi.temperature,
modelName: this.constructor._model ? this.constructor._model : "",
streaming: true,
});

return chatModel;
}

getPastRounds() {
return store.state.claudeApi.pastRounds
? store.state.claudeApiApi.pastRounds
: 1;
}
}
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPIHaikuBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPIHaikuBot extends ClaudeAPIBot {
static _className = "ClaudeAPIHaikuBot";
static _logoFilename = "claudeapi-haiku-logo.png";
static _model = "claude-3-haiku-20240307";
constructor() {
super();
}
}
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPIInstant12Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPIInstant12Bot extends ClaudeAPIBot {
static _className = "ClaudeAPIInstant12Bot";
static _logoFilename = "claudeapi-instant-12-logo.png";
static _model = "claude-instant-1.2";
constructor() {
super();
}
}
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPIOpusBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPIOpusBot extends ClaudeAPIBot {
static _className = "ClaudeAPIOpusBot";
static _logoFilename = "claudeapi-opus-logo.png";
static _model = "claude-3-opus-20240229";
constructor() {
super();
}
}
10 changes: 10 additions & 0 deletions src/bots/anthropic/ClaudeAPISonnetBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ClaudeAPIBot from "./ClaudeAPIBot";

export default class ClaudeAPISonnetBot extends ClaudeAPIBot {
static _className = "ClaudeAPISonnetBot";
static _logoFilename = "claudeapi-sonnet-logo.png";
static _model = "claude-3-sonnet-20240229";
constructor() {
super();
}
}
18 changes: 18 additions & 0 deletions src/bots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ import Claude3SonnetBot from "./lmsys/Claude3SonnetBot";
import Claude3OpusBot from "./lmsys/Claude3OpusBot";
import ChatGLM4Bot from "./zhipu/ChatGLM4Bot";
import KimiBot from "./moonshot/KimiBot";
import ClaudeAPIOpusBot from "./anthropic/ClaudeAPIOpusBot";
import ClaudeAPI20Bot from "./anthropic/ClaudeAPI20Bot";
import ClaudeAPI21Bot from "./anthropic/ClaudeAPI21Bot";
import ClaudeAPISonnetBot from "./anthropic/ClaudeAPISonnetBot";
import ClaudeAPIHaikuBot from "./anthropic/ClaudeAPIHaikuBot";
import ClaudeAPIInstant12Bot from "./anthropic/ClaudeAPIInstant12Bot";

const all = [
Qihoo360AIBrainBot.getInstance(),
Expand All @@ -86,6 +92,12 @@ const all = [
ClaudePlusPoeBot.getInstance(),
Claude3OpusBot.getInstance(),
Claude3SonnetBot.getInstance(),
ClaudeAPIOpusBot.getInstance(),
ClaudeAPISonnetBot.getInstance(),
ClaudeAPIHaikuBot.getInstance(),
ClaudeAPI20Bot.getInstance(),
ClaudeAPI21Bot.getInstance(),
ClaudeAPIInstant12Bot.getInstance(),
CodeLlama34bPoeBot.getInstance(),
CodeLlamaHCBot.getInstance(),
CodeLlamaBot.getInstance(),
Expand Down Expand Up @@ -263,6 +275,12 @@ export const botTags = {
bots.getBotByClassName("WenxinQianfanBot"),
bots.getBotByClassName("WenxinQianfanTurboBot"),
bots.getBotByClassName("WenxinQianfan4Bot"),
bots.getBotByClassName("ClaudeAPI20Bot"),
bots.getBotByClassName("ClaudeAPI21Bot"),
bots.getBotByClassName("ClaudeAPIHaikuBot"),
bots.getBotByClassName("ClaudeAPIInstant12Bot"),
bots.getBotByClassName("ClaudeAPIOpusBot"),
bots.getBotByClassName("ClaudeAPISonnetBot"),
],
madeInChina: [
bots.getBotByClassName("Qihoo360AIBrainBot"),
Expand Down
63 changes: 63 additions & 0 deletions src/components/BotSettings/ClaudeAPIBotSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<CommonBotSettings
:settings="settings"
:brand-id="brandId"
mutation-type="setClaudeApi"
:watcher="watcher"
></CommonBotSettings>
</template>

<script>
import _bots from "@/bots";
import Bot from "@/bots/anthropic/ClaudeAPIBot";
import CommonBotSettings from "@/components/BotSettings/CommonBotSettings.vue";
import { Type } from "./settings.const";

const settings = [
{
type: Type.Text,
name: "apiKey",
title: "claudeApi.apiKey",
description: "settings.secretPrompt",
placeholder: "sk-...",
},
{
type: Type.Slider,
name: "temperature",
title: "openaiApi.temperature",
description: "openaiApi.temperaturePrompt",
min: 0,
max: 1,
step: 0.1,
ticks: {
0: "openaiApi.temperature0",
1: "openaiApi.temperature2",
},
},
{
type: Type.Text,
name: "alterUrl",
title: "openaiApi.alterUrl",
description: "openaiApi.alterUrlPrompt",
placeholder: "https://your.proxy.com/v1",
},
];
export default {
components: {
CommonBotSettings,
},
data() {
return {
settings: settings,
brandId: Bot._brandId,
};
},
methods: {
watcher() {
_bots.all
.filter((bot) => bot instanceof Bot)
.map((bot) => bot.setupModel());
},
},
};
</script>
2 changes: 2 additions & 0 deletions src/components/SettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import ChatGLMBotSettings from "./BotSettings/ChatGLMBotSettings.vue";
import KimiBotSettings from "./BotSettings/KimiBotSettings.vue";

import { resolveTheme, applyTheme, Mode } from "../theme";
import ClaudeAPIBotSettings from "./BotSettings/ClaudeAPIBotSettings.vue";

const { ipcRenderer } = window.require("electron");
const { t: $t, locale } = useI18n();
Expand Down Expand Up @@ -163,6 +164,7 @@ const botSettings = [
{ brand: "spark", component: SparkBotSettings },
{ brand: "wenxinQianfan", component: WenxinQianfanBotSettings },
{ brand: "youChat", component: YouChatBotSettings },
{ brand: "claudeApi", component: ClaudeAPIBotSettings },
];

const proxy = ProxySettings;
Expand Down
9 changes: 9 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@
"gemini-pro": "Gemini",
"gemini-ultra": "Gemini Advanced"
},
"claudeApi":{
"name": "Claude API",
"claude-3-opus-20240229" : "claude-3-opus",
"claude-3-sonnet-20240229": "claude-3-sonnet",
"claude-3-haiku-20240307": "claude-3-haiku",
"claude-21":"claude-2.1",
"claude-20":"claude-2.0",
"claude-instant-12":"claude-instant"
},
"bingChat": {
"name": "Copilot",
"solveCaptcha": "You need to <a { attributes }>solve CAPTCHA</a> to continue.",
Expand Down
Loading