-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
519 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { Wenxin } from '@lobehub/icons'; | ||
import { Input } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { WenxinProviderCard } from '@/config/modelProviders'; | ||
import { GlobalLLMProviderKey } from '@/types/user/settings'; | ||
|
||
import { KeyVaultsConfigKey } from '../../const'; | ||
import { ProviderItem } from '../../type'; | ||
|
||
const providerKey: GlobalLLMProviderKey = 'wenxin'; | ||
|
||
export const useWenxinProvider = (): ProviderItem => { | ||
const { t } = useTranslation('modelProvider'); | ||
|
||
return { | ||
...WenxinProviderCard, | ||
apiKeyItems: [ | ||
{ | ||
children: ( | ||
<Input.Password | ||
autoComplete={'new-password'} | ||
placeholder={t(`${providerKey}.accessKey.placeholder`)} | ||
/> | ||
), | ||
desc: t(`${providerKey}.accessKey.desc`), | ||
label: t(`${providerKey}.accessKey.title`), | ||
name: [KeyVaultsConfigKey, providerKey, 'accessKey'], | ||
}, | ||
{ | ||
children: ( | ||
<Input.Password | ||
autoComplete={'new-password'} | ||
placeholder={t(`${providerKey}.secretKey.placeholder`)} | ||
/> | ||
), | ||
desc: t(`${providerKey}.secretKey.desc`), | ||
label: t(`${providerKey}.secretKey.title`), | ||
name: [KeyVaultsConfigKey, providerKey, 'secretKey'], | ||
}, | ||
], | ||
title: <Wenxin.Combine size={32} type={'color'} />, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @vitest-environment edge-runtime | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { POST as UniverseRoute } from '../[provider]/route'; | ||
import { POST, runtime } from './route'; | ||
|
||
// 模拟 '../[provider]/route' | ||
vi.mock('../[provider]/route', () => ({ | ||
POST: vi.fn().mockResolvedValue('mocked response'), | ||
})); | ||
|
||
describe('Configuration tests', () => { | ||
it('should have runtime set to "edge"', () => { | ||
expect(runtime).toBe('nodejs'); | ||
}); | ||
}); | ||
|
||
describe('Wenxin POST function tests', () => { | ||
it('should call UniverseRoute with correct parameters', async () => { | ||
const mockRequest = new Request('https://example.com', { method: 'POST' }); | ||
await POST(mockRequest); | ||
expect(UniverseRoute).toHaveBeenCalledWith(mockRequest, { | ||
createRuntime: expect.anything(), | ||
params: { provider: 'wenxin' }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getLLMConfig } from '@/config/llm'; | ||
import { AgentRuntime } from '@/libs/agent-runtime'; | ||
import LobeWenxinAI from '@/libs/agent-runtime/wenxin'; | ||
|
||
import { POST as UniverseRoute } from '../[provider]/route'; | ||
|
||
export const runtime = 'nodejs'; | ||
|
||
export const maxDuration = 30; | ||
|
||
export const POST = async (req: Request) => | ||
UniverseRoute(req, { | ||
createRuntime: (payload) => { | ||
const { WENXIN_ACCESS_KEY, WENXIN_SECRET_KEY } = getLLMConfig(); | ||
let accessKey: string | undefined = WENXIN_ACCESS_KEY; | ||
let secretKey: string | undefined = WENXIN_SECRET_KEY; | ||
|
||
// if the payload has the api key, use user | ||
if (payload.apiKey) { | ||
accessKey = payload?.wenxinAccessKey; | ||
secretKey = payload?.wenxinSecretKey; | ||
} | ||
|
||
const params = { accessKey, secretKey }; | ||
const instance = new LobeWenxinAI(params); | ||
|
||
return new AgentRuntime(instance); | ||
}, | ||
params: { provider: 'wenxin' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ModelProviderCard } from '@/types/llm'; | ||
|
||
// ref https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html | ||
const Wenxin: ModelProviderCard = { | ||
chatModels: [], | ||
checkModel: 'ERNIE-4.0-8K', | ||
id: 'wenxin', | ||
name: 'Wenxin', | ||
}; | ||
|
||
export default Wenxin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.