fix: apikey

This commit is contained in:
archer
2023-06-25 13:20:00 +08:00
parent cfb31afbd9
commit 426176db47
3 changed files with 22 additions and 16 deletions

View File

@@ -39,7 +39,12 @@ export async function openaiEmbedding({
input,
mustPay = false
}: { userId: string; mustPay?: boolean } & Props) {
const apiKey = getSystemOpenAiKey();
const { userOpenAiKey, systemAuthKey } = await getApiKey({
model: 'gpt-3.5-turbo',
userId,
mustPay
});
const apiKey = userOpenAiKey || systemAuthKey;
// 获取 chatAPI
const chatAPI = getOpenAIApi(apiKey);
@@ -68,7 +73,7 @@ export async function openaiEmbedding({
});
pushGenerateVectorBill({
isPay: mustPay,
isPay: !userOpenAiKey,
userId,
text: input.join(''),
tokenLen: result.tokenLen

View File

@@ -54,7 +54,6 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
{ label: '佣金', id: TableEnum.promotion, Component: <PromotionTable /> },
{ label: '通知', id: TableEnum.inform, Component: <InformTable /> }
]);
const [currentTab, setCurrentTab] = useState(tableType);
const router = useRouter();
const { copyData } = useCopyData();
@@ -84,7 +83,14 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
async (data: UserUpdateParams) => {
setLoading(true);
try {
data.openaiKey && (await authOpenAiKey(data.openaiKey));
if (data.openaiKey) {
const text = await authOpenAiKey(data.openaiKey);
text &&
toast({
title: text,
status: 'warning'
});
}
await putUserInfo({
openaiKey: data.openaiKey,
avatar: data.avatar
@@ -95,7 +101,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
});
reset(data);
toast({
title: '更新成功',
title: '更新数据成功',
status: 'success'
});
} catch (error) {
@@ -195,7 +201,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
<Box flex={'0 0 85px'}>openaiKey:</Box>
<Input
{...register(`openaiKey`)}
maxW={'300px'}
maxW={'350px'}
placeholder={'openai账号。回车或失去焦点保存'}
size={'sm'}
onBlur={handleSubmit(onclickSave)}
@@ -251,13 +257,13 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
m={'auto'}
w={'200px'}
list={tableList.current}
activeId={currentTab}
activeId={tableType}
size={'sm'}
onChange={(id: any) => setCurrentTab(id)}
onChange={(id: any) => router.replace(`/number?type=${id}`)}
/>
<Box minH={'300px'}>
{(() => {
const item = tableList.current.find((item) => item.id === currentTab);
const item = tableList.current.find((item) => item.id === tableType);
return item ? item.Component : null;
})()}