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

feat: impl deepseek #625

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion client/.kiwi/en/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
gITHU: ' GitHub platform',
},
CreateButton: {
chuangJianTOK: 'Create Token',
chuangJianTOK: 'Custodial Token',
},
CreateModal: {
miYao: 'Secret Key',
Expand Down
2 changes: 1 addition & 1 deletion client/.kiwi/ja/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
gITHU: ' GitHubプラットフォーム',
},
CreateButton: {
chuangJianTOK: 'トークンを作成',
chuangJianTOK: '托管されたトークン',
},
CreateModal: {
miYao: 'シークレットキー',
Expand Down
2 changes: 1 addition & 1 deletion client/.kiwi/ko/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
gITHU: ' GitHub 플랫폼',
},
CreateButton: {
chuangJianTOK: '토큰 생성',
chuangJianTOK: '위탁된 토큰',
},
CreateModal: {
miYao: '비밀 키',
Expand Down
2 changes: 1 addition & 1 deletion client/.kiwi/zh-CN/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
gITHU: ' GitHub 平台',
},
CreateButton: {
chuangJianTOK: '创建 Token',
chuangJianTOK: '托管 Token',
},
CreateModal: {
miYao: '密钥',
Expand Down
2 changes: 1 addition & 1 deletion client/.kiwi/zh-TW/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
gITHU: ' GitHub 平台',
},
CreateButton: {
chuangJianTOK: '創建 Token',
chuangJianTOK: '代管 Token',
},
CreateModal: {
miYao: '密鑰',
Expand Down
10 changes: 9 additions & 1 deletion client/app/hooks/useToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query';
import { getTokenList } from '../services/TokensController';
import { getTokenList, getLLMList } from '../services/TokensController';
import { Tables, Database } from '@/types/database.types';
import { Updater, useImmer } from 'use-immer';

Expand All @@ -21,3 +21,11 @@ export function useCreateToken(): [LLMTokenInsert, Updater<LLMTokenInsert>] {

return [llmToken, setLLMToken]
}

export function useListLLMs() {
return useQuery<string[]>({
queryKey: [`llm.list`],
queryFn: async () => getLLMList(),
retry: false,
});
}
7 changes: 7 additions & 0 deletions client/app/services/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export async function getTokenList() {
return response.data.data;
}

export async function getLLMList() {
const response = await axios.get(`${apiDomain}/api/user/llms`);
return response.data;
}


export async function deleteToken(id: string) {
const response = await axios.delete(`${apiDomain}/api/user/llm_token/${id}`);
return response.data;
Expand All @@ -34,3 +40,4 @@ export async function analyzeTopUsers() {
return response.data;
}


9 changes: 5 additions & 4 deletions client/app/user/tokens/components/CreateModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import I18N from '@/app/utils/I18N';
import { LLMTokenInsert, useCreateToken } from '@/app/hooks/useToken';
import { LLMTokenInsert, useCreateToken, useListLLMs } from '@/app/hooks/useToken';
import {
Button,
Input,
Expand All @@ -24,6 +24,8 @@ export interface CreateModalProps {

export default function CreateModal({ isOpen, onClose, isLoading, onCreate }: CreateModalProps) {
const [llmToken, setLLMToken] = useCreateToken();
const { data: llms = [] } = useListLLMs();

useEffect(() => setLLMToken({}), []);

const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
Expand All @@ -48,7 +50,7 @@ export default function CreateModal({ isOpen, onClose, isLoading, onCreate }: Cr
<ModalBody>
<form>
<div className="flex-1">

<div className="mb-[42px]">
<Input
name="slug"
Expand All @@ -67,8 +69,7 @@ export default function CreateModal({ isOpen, onClose, isLoading, onCreate }: Cr
required
onChange={handleChange}
>
<SelectItem key="openai">openai</SelectItem>
<SelectItem key="gemini">gemini</SelectItem>
{llms?.map(llm => <SelectItem key={llm}>{llm}</SelectItem>)}
</Select>
</div>
<div className="mt-[42px]">
Expand Down
50 changes: 50 additions & 0 deletions server/agent/llm/clients/deepseek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


from typing import Any, List, Optional
from langchain_openai import ChatOpenAI
from langchain_core.utils.function_calling import convert_to_openai_tool

from agent.llm import register_llm_client
from agent.llm.base import BaseLLMClient

from petercat_utils.data_class import MessageContent
from petercat_utils import get_env_variable

DEEPSEEK_API_KEY = get_env_variable("DEEPSEEK_API_KEY")


@register_llm_client("deepseek")
class DeepSeekClient(BaseLLMClient):
_client: ChatOpenAI

def __init__(
self,
temperature: Optional[float] = 0.2,
n: Optional[int] = 1,
top_p: Optional[float] = None,
max_tokens: Optional[int] = 1500,
streaming: Optional[bool] = False,
api_key: Optional[str] = DEEPSEEK_API_KEY,
):
print(f"DEEPSEEK_API_KEY={DEEPSEEK_API_KEY}")
RaoHai marked this conversation as resolved.
Show resolved Hide resolved
self._client = ChatOpenAI(
model_name="deepseek-chat",
temperature=temperature,
n=n,
top_p=top_p,
streaming=streaming,
max_tokens=max_tokens,
openai_api_key=api_key,
stream_usage=True,
openai_api_base="https://api.deepseek.com"
)

def get_client(self):
return self._client

def get_tools(self, tools: List[Any]):
return [convert_to_openai_tool(tool) for tool in tools]

def parse_content(self, content: List[MessageContent]):
print(f"parse_conent, content={content}")
return content
2 changes: 1 addition & 1 deletion server/core/service/user_token_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def top_bots(self, start_date: datetime.date, end_date: datetime.date):

def top_users(self, start_date: datetime.date, end_date: datetime.date):
return self.user_token_usage_dao.top_users(start_date=start_date, end_date=end_date)

def get_user_token_usage_service():
return UserTokenUsageService()

Expand Down
Loading