mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-02-02 20:53:13 +08:00
[update]change name
This commit is contained in:
parent
ed9ecebffc
commit
ea68e058cd
@ -20,8 +20,8 @@ import {
|
|||||||
LobePerplexityAI,
|
LobePerplexityAI,
|
||||||
LobeRuntimeAI,
|
LobeRuntimeAI,
|
||||||
LobeZhipuAI,
|
LobeZhipuAI,
|
||||||
|
LobeChatChatAI,
|
||||||
ModelProvider,
|
ModelProvider,
|
||||||
LobeKnowledgeAI,
|
|
||||||
} from '@/libs/agent-runtime';
|
} from '@/libs/agent-runtime';
|
||||||
import { TraceClient } from '@/libs/traces';
|
import { TraceClient } from '@/libs/traces';
|
||||||
|
|
||||||
@ -169,8 +169,8 @@ class AgentRuntime {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ModelProvider.Knowledge: {
|
case ModelProvider.ChatChat: {
|
||||||
runtimeModel = this.initKnowledge(payload);
|
runtimeModel = this.initChatChat(payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,11 +275,11 @@ class AgentRuntime {
|
|||||||
return new LobeMistralAI({ apiKey });
|
return new LobeMistralAI({ apiKey });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static initKnowledge(payload: JWTPayload) {
|
private static initChatChat(payload: JWTPayload) {
|
||||||
const { KNOWLEDGE_PROXY_URL } = getServerConfig();
|
const { KNOWLEDGE_PROXY_URL } = getServerConfig();
|
||||||
const baseURL = payload?.endpoint || KNOWLEDGE_PROXY_URL;
|
const baseURL = payload?.endpoint || KNOWLEDGE_PROXY_URL;
|
||||||
|
|
||||||
return new LobeKnowledgeAI({ baseURL });
|
return new LobeChatChatAI({ baseURL });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { useHover } from 'ahooks';
|
|||||||
import { createStyles, useResponsive } from 'antd-style';
|
import { createStyles, useResponsive } from 'antd-style';
|
||||||
import { memo, useMemo, useRef } from 'react';
|
import { memo, useMemo, useRef } from 'react';
|
||||||
import Avatar from '@/components/Avatar';
|
import Avatar from '@/components/Avatar';
|
||||||
|
|
||||||
const { Item } = List;
|
const { Item } = List;
|
||||||
|
|
||||||
const useStyles = createStyles(({ css, token, responsive }) => {
|
const useStyles = createStyles(({ css, token, responsive }) => {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { MobileNavBar } from '@lobehub/ui';
|
import { MobileNavBar } from '@lobehub/ui';
|
||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import Logo from '@/components/Logo';
|
import Logo from '@/components/Logo';
|
||||||
|
|
||||||
const Header = memo(() => {
|
const Header = memo(() => {
|
||||||
return <MobileNavBar center={<Logo type={'text'} />} />;
|
return <MobileNavBar center={<Logo type={'text'} />} />;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { MobileNavBar } from '@lobehub/ui';
|
import { MobileNavBar } from '@lobehub/ui';
|
||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import Logo from '@/components/Logo';
|
import Logo from '@/components/Logo';
|
||||||
|
|
||||||
const Header = memo(() => <MobileNavBar center={<Logo type={'text'} />} />);
|
const Header = memo(() => <MobileNavBar center={<Logo type={'text'} />} />);
|
||||||
|
|
||||||
export default Header;
|
export default Header;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { Loader2 } from 'lucide-react';
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { Center, Flexbox } from 'react-layout-kit';
|
import { Center, Flexbox } from 'react-layout-kit';
|
||||||
import Logo from '@/components/Logo';
|
import Logo from '@/components/Logo';
|
||||||
|
|
||||||
const FullscreenLoading = memo<{ title?: string }>(({ title }) => {
|
const FullscreenLoading = memo<{ title?: string }>(({ title }) => {
|
||||||
return (
|
return (
|
||||||
<Flexbox height={'100%'} style={{ userSelect: 'none' }} width={'100%'}>
|
<Flexbox height={'100%'} style={{ userSelect: 'none' }} width={'100%'}>
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { createStyles } from 'antd-style';
|
|||||||
import { ReactNode, memo } from 'react';
|
import { ReactNode, memo } from 'react';
|
||||||
import { Center, Flexbox } from 'react-layout-kit';
|
import { Center, Flexbox } from 'react-layout-kit';
|
||||||
import Avatar from '@/components/Avatar';
|
import Avatar from '@/components/Avatar';
|
||||||
|
|
||||||
export const useStyles = createStyles(({ css, token }) => ({
|
export const useStyles = createStyles(({ css, token }) => ({
|
||||||
container: css`
|
container: css`
|
||||||
color: ${token.colorText};
|
color: ${token.colorText};
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||||||
import { ChatStreamCallbacks } from '@/libs/agent-runtime';
|
import { ChatStreamCallbacks } from '@/libs/agent-runtime';
|
||||||
|
|
||||||
import * as debugStreamModule from '../utils/debugStream';
|
import * as debugStreamModule from '../utils/debugStream';
|
||||||
import { LobeKnowledgeAI } from './index';
|
import { LobeChatChatAI } from './index';
|
||||||
|
|
||||||
const provider = 'knowledge';
|
const provider = 'knowledge';
|
||||||
const defaultBaseURL = 'http://localhost:7861/v1';
|
const defaultBaseURL = 'http://localhost:7861/v1';
|
||||||
@ -15,10 +15,10 @@ const invalidErrorType = 'InvalidKnowledgeArgs';
|
|||||||
// Mock the console.error to avoid polluting test output
|
// Mock the console.error to avoid polluting test output
|
||||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
|
||||||
let instance: LobeKnowledgeAI;
|
let instance: LobeChatChatAI;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
instance = new LobeKnowledgeAI({ apiKey: 'knowledge', baseURL: defaultBaseURL });
|
instance = new LobeChatChatAI({ apiKey: 'knowledge', baseURL: defaultBaseURL });
|
||||||
|
|
||||||
// 使用 vi.spyOn 来模拟 chat.completions.create 方法
|
// 使用 vi.spyOn 来模拟 chat.completions.create 方法
|
||||||
vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
|
vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue(
|
||||||
@ -30,7 +30,7 @@ afterEach(() => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('LobeKnowledgeAI', () => {
|
describe('LobeChatChatAI', () => {
|
||||||
|
|
||||||
describe('init', ()=>{
|
describe('init', ()=>{
|
||||||
it('should init with default baseURL', () => {
|
it('should init with default baseURL', () => {
|
||||||
@ -13,13 +13,13 @@ import { Stream } from 'openai/streaming';
|
|||||||
const DEFAULT_BASE_URL = 'http://localhost:7861/v1';
|
const DEFAULT_BASE_URL = 'http://localhost:7861/v1';
|
||||||
|
|
||||||
|
|
||||||
export class LobeKnowledgeAI implements LobeRuntimeAI {
|
export class LobeChatChatAI implements LobeRuntimeAI {
|
||||||
private client: OpenAI;
|
private client: OpenAI;
|
||||||
|
|
||||||
baseURL: string;
|
baseURL: string;
|
||||||
|
|
||||||
constructor({ apiKey = 'knowledge', baseURL = DEFAULT_BASE_URL, ...res }: ClientOptions) {
|
constructor({ apiKey = 'chatChat', baseURL = DEFAULT_BASE_URL, ...res }: ClientOptions) {
|
||||||
if (!baseURL) throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidKnowledgeArgs);
|
if (!baseURL) throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidChatChatArgs);
|
||||||
|
|
||||||
this.client = new OpenAI({ apiKey, baseURL, ...res });
|
this.client = new OpenAI({ apiKey, baseURL, ...res });
|
||||||
this.baseURL = baseURL;
|
this.baseURL = baseURL;
|
||||||
@ -31,7 +31,7 @@ export class LobeKnowledgeAI implements LobeRuntimeAI {
|
|||||||
payload as unknown as (OpenAI.ChatCompletionCreateParamsStreaming | OpenAI.ChatCompletionCreateParamsNonStreaming),
|
payload as unknown as (OpenAI.ChatCompletionCreateParamsStreaming | OpenAI.ChatCompletionCreateParamsNonStreaming),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (LobeKnowledgeAI.isStream(response)) {
|
if (LobeChatChatAI.isStream(response)) {
|
||||||
|
|
||||||
const [prod, debug] = response.tee();
|
const [prod, debug] = response.tee();
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ export class LobeKnowledgeAI implements LobeRuntimeAI {
|
|||||||
console.debug(JSON.stringify(response));
|
console.debug(JSON.stringify(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = LobeKnowledgeAI.createChatCompletionStream(response?.choices[0].message.content || '');
|
const stream = LobeChatChatAI.createChatCompletionStream(response?.choices[0].message.content || '');
|
||||||
|
|
||||||
return new StreamingTextResponse(stream);
|
return new StreamingTextResponse(stream);
|
||||||
}
|
}
|
||||||
@ -65,8 +65,8 @@ export class LobeKnowledgeAI implements LobeRuntimeAI {
|
|||||||
throw AgentRuntimeError.chat({
|
throw AgentRuntimeError.chat({
|
||||||
endpoint: desensitizedEndpoint,
|
endpoint: desensitizedEndpoint,
|
||||||
error: error as any,
|
error: error as any,
|
||||||
errorType: AgentRuntimeErrorType.InvalidKnowledgeArgs,
|
errorType: AgentRuntimeErrorType.InvalidChatChatArgs,
|
||||||
provider: ModelProvider.Knowledge,
|
provider: ModelProvider.ChatChat,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,13 +78,13 @@ export class LobeKnowledgeAI implements LobeRuntimeAI {
|
|||||||
|
|
||||||
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
const { errorResult, RuntimeError } = handleOpenAIError(error);
|
||||||
|
|
||||||
const errorType = RuntimeError || AgentRuntimeErrorType.OllamaBizError;
|
const errorType = RuntimeError || AgentRuntimeErrorType.ChatChatBizError;
|
||||||
|
|
||||||
throw AgentRuntimeError.chat({
|
throw AgentRuntimeError.chat({
|
||||||
endpoint: desensitizedEndpoint,
|
endpoint: desensitizedEndpoint,
|
||||||
error: errorResult,
|
error: errorResult,
|
||||||
errorType,
|
errorType,
|
||||||
provider: ModelProvider.Knowledge,
|
provider: ModelProvider.ChatChat,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,8 +35,8 @@ export const AgentRuntimeErrorType = {
|
|||||||
InvalidAnthropicAPIKey: 'InvalidAnthropicAPIKey',
|
InvalidAnthropicAPIKey: 'InvalidAnthropicAPIKey',
|
||||||
AnthropicBizError: 'AnthropicBizError',
|
AnthropicBizError: 'AnthropicBizError',
|
||||||
|
|
||||||
InvalidKnowledgeArgs: 'InvalidKnowledgeArgs',
|
InvalidChatChatArgs: 'InvalidChatChatArgs',
|
||||||
KnowledgeBizError: 'KnowledgeBizError',
|
ChatChatBizError: 'ChatChatBizError',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type ILobeAgentRuntimeErrorType =
|
export type ILobeAgentRuntimeErrorType =
|
||||||
|
|||||||
@ -2,6 +2,7 @@ export { LobeAnthropicAI } from './anthropic';
|
|||||||
export { LobeAzureOpenAI } from './azureOpenai';
|
export { LobeAzureOpenAI } from './azureOpenai';
|
||||||
export * from './BaseAI';
|
export * from './BaseAI';
|
||||||
export { LobeBedrockAI } from './bedrock';
|
export { LobeBedrockAI } from './bedrock';
|
||||||
|
export { LobeChatChatAI } from './chatchat';
|
||||||
export * from './error';
|
export * from './error';
|
||||||
export { LobeGoogleAI } from './google';
|
export { LobeGoogleAI } from './google';
|
||||||
export { LobeMistralAI } from './mistral';
|
export { LobeMistralAI } from './mistral';
|
||||||
@ -12,4 +13,3 @@ export { LobePerplexityAI } from './perplexity';
|
|||||||
export * from './types';
|
export * from './types';
|
||||||
export { AgentRuntimeError } from './utils/createError';
|
export { AgentRuntimeError } from './utils/createError';
|
||||||
export { LobeZhipuAI } from './zhipu';
|
export { LobeZhipuAI } from './zhipu';
|
||||||
export { LobeKnowledgeAI } from './knowledge';
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export enum ModelProvider {
|
|||||||
Anthropic = 'anthropic',
|
Anthropic = 'anthropic',
|
||||||
Azure = 'azure',
|
Azure = 'azure',
|
||||||
Bedrock = 'bedrock',
|
Bedrock = 'bedrock',
|
||||||
|
ChatChat = 'chatChat',
|
||||||
ChatGLM = 'chatglm',
|
ChatGLM = 'chatglm',
|
||||||
Google = 'google',
|
Google = 'google',
|
||||||
Mistral = 'mistral',
|
Mistral = 'mistral',
|
||||||
@ -33,6 +34,5 @@ export enum ModelProvider {
|
|||||||
OpenAI = 'openai',
|
OpenAI = 'openai',
|
||||||
Perplexity = 'perplexity',
|
Perplexity = 'perplexity',
|
||||||
Tongyi = 'tongyi',
|
Tongyi = 'tongyi',
|
||||||
ZhiPu = 'zhipu',
|
ZhiPu = 'zhipu'
|
||||||
Knowledge = 'knowledge',
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user