-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add DeepSeek API bots #891
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import LangChainBot from "../LangChainBot"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { ChatOpenAI } from "@langchain/openai"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import store from "@/store"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default class DeepSeekAPIBot extends LangChainBot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static _brandId = "deepSeekApi"; // Brand id of the bot, should be unique. Used in i18n. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static _className = "DeepSeekAPIBot"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
static _logoFilename = "deepseek.svg"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
super(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async _checkAvailability() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let available = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (store.state.deepSeekApi.apiKey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.setupModel(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
available = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return available; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix method name mismatch and add error handling
async _checkAvailability() {
let available = false;
- if (store.state.deepSeekApi.apiKey) {
- this.setupModel();
+ const apiKey = store.state.deepSeekApi.apiKey;
+ if (apiKey && typeof apiKey === 'string' && apiKey.trim()) {
+ this._setupModel();
available = true;
}
return available;
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_setupModel() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PeterDaveHello marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const chatModel = new ChatOpenAI({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
configuration: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
basePath: "https://api.deepseek.com/v1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
openAIApiKey: store.state.deepSeekApi.apiKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
modelName: this.constructor._model ? this.constructor._model : "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
temperature: store.state.deepSeekApi.temperature, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
streaming: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return chatModel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+24
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve configuration management and error handling
_setupModel() {
+ const temperature = store.state.deepSeekApi.temperature;
+ if (temperature < 0 || temperature > 1) {
+ throw new Error('Temperature must be between 0 and 1');
+ }
+
+ try {
const chatModel = new ChatOpenAI({
configuration: {
- basePath: "https://api.deepseek.com/v1",
+ basePath: store.state.deepSeekApi.basePath || "https://api.deepseek.com/v1",
},
openAIApiKey: store.state.deepSeekApi.apiKey,
modelName: this.constructor._model ? this.constructor._model : "",
- temperature: store.state.deepSeekApi.temperature,
+ temperature,
streaming: true,
});
return chatModel;
+ } catch (error) {
+ throw new Error(`Failed to initialize DeepSeek chat model: ${error.message}`);
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getPastRounds() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return store.state.deepSeekApi.pastRounds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||
import DeepSeekAPIBot from "./DeepSeekAPIBot"; | ||||||||
|
||||||||
export default class DeepSeekAPIChatBot extends DeepSeekAPIBot { | ||||||||
static _className = "DeepSeekAPIChatBot"; | ||||||||
static _model = "deepseek-chat"; | ||||||||
|
||||||||
constructor() { | ||||||||
super(); | ||||||||
} | ||||||||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unnecessary constructor. The constructor only calls Apply this diff to remove the unnecessary constructor: - constructor() {
- super();
- } 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome[error] 7-9: This constructor is unnecessary. Unsafe fix: Remove the unnecessary constructor. (lint/complexity/noUselessConstructor) |
||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import DeepSeekAPIBot from "./DeepSeekAPIBot"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Remove unnecessary constructor in DeepSeekAPICoderBot The parent class
🔗 Analysis chainVerify parent class implementation The import statement looks correct, but let's verify the existence and implementation of the parent class. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the existence and basic structure of DeepSeekAPIBot
# Check if the parent class file exists and contains the expected class definition
ast-grep --pattern 'export $_ class DeepSeekAPIBot {
$$$
}'
Length of output: 63 Script: #!/bin/bash
# Let's try a different approach to verify the parent class
# First, let's find the exact file location
fd "DeepSeekAPIBot.js" --type f
# Then let's check the content of any files containing DeepSeekAPIBot
rg "class DeepSeekAPIBot" -A 5
Length of output: 566 Script: #!/bin/bash
# Let's verify the complete implementation of both classes to ensure proper inheritance
# Check DeepSeekAPIBot's complete implementation
rg "class DeepSeekAPIBot" -B 2 -A 15 src/bots/deepseek/DeepSeekAPIBot.js
# Check DeepSeekAPICoderBot's complete implementation
rg "class DeepSeekAPICoderBot" -B 2 -A 15 src/bots/deepseek/DeepSeekAPICoderBot.js
# Check if LangChainBot exists since DeepSeekAPIBot extends it
fd "LangChainBot.js" --type f
Length of output: 901 |
||
|
||
export default class DeepSeekAPICoderBot extends DeepSeekAPIBot { | ||
static _className = "DeepSeekAPICoderBot"; | ||
static _model = "deepseek-coder"; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
PeterDaveHello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<CommonBotSettings | ||
:settings="settings" | ||
:brand-id="brandId" | ||
mutation-type="setDeepSeekApi" | ||
:watcher="watcher" | ||
></CommonBotSettings> | ||
</template> | ||
|
||
<script> | ||
import Bot from "@/bots/deepseek/DeepSeekAPIBot"; | ||
import CommonBotSettings from "@/components/BotSettings/CommonBotSettings.vue"; | ||
import { Type } from "./settings.const"; | ||
|
||
const settings = [ | ||
{ | ||
type: Type.Text, | ||
name: "apiKey", | ||
title: "common.apiKey", | ||
description: "settings.secretPrompt", | ||
placeholder: "sk-...", | ||
}, | ||
{ | ||
type: Type.Slider, | ||
name: "temperature", | ||
title: "openaiApi.temperature", | ||
description: "openaiApi.temperaturePrompt", | ||
default: 1.0, | ||
min: 0, | ||
max: 2, | ||
step: 0.05, | ||
ticks: { | ||
0: "openaiApi.temperature0", | ||
2: "openaiApi.temperature2", | ||
}, | ||
}, | ||
{ | ||
type: Type.Slider, | ||
name: "pastRounds", | ||
title: "bot.pastRounds", | ||
description: "bot.pastRoundsPrompt", | ||
min: 0, | ||
max: 10, | ||
step: 1, | ||
}, | ||
]; | ||
export default { | ||
components: { | ||
CommonBotSettings, | ||
}, | ||
data() { | ||
return { | ||
settings: settings, | ||
brandId: Bot._brandId, | ||
}; | ||
}, | ||
methods: { | ||
watcher() { | ||
Bot.getInstance().setupModel(); | ||
}, | ||
}, | ||
}; | ||
Comment on lines
+47
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve component implementation robustness. Several improvements can be made to enhance code reliability:
Consider applying these improvements: data() {
return {
settings: settings,
- brandId: Bot._brandId,
+ brandId: Bot.getBrandId(), // Add this method to Bot class
};
},
methods: {
watcher() {
+ try {
+ const bot = Bot.getInstance();
+ if (!bot) {
+ throw new Error('Failed to get Bot instance');
+ }
Bot.getInstance().setupModel();
+ } catch (error) {
+ console.error('Failed to setup model:', error);
+ // Consider adding user notification here
+ }
},
},
|
||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add missing static _model property declaration
The
_model
property is referenced in_setupModel()
but not declared as a static property. Consider adding it to maintain consistency with other static properties.export default class DeepSeekAPIBot extends LangChainBot { static _brandId = "deepSeekApi"; // Brand id of the bot, should be unique. Used in i18n. static _className = "DeepSeekAPIBot"; static _logoFilename = "deepseek.svg"; + static _model = ""; // Default model name
📝 Committable suggestion