Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/lobehub/lobe-chat
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 28, 2024
2 parents d7ece23 + 6aa1689 commit dadb6e8
Show file tree
Hide file tree
Showing 22 changed files with 1,733 additions and 222 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
<!-- AGENT LIST -->

| Recent Submits | Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [GitHub Finder](https://chat-preview.lobehub.com/market?agent=github-finder)<br/><sup>By **[nullmastermind](https://github.com/nullmastermind)** on **2024-02-25**</sup> | Specializes in suggesting open source repositories on GitHub based on a custom formula.<br/>`coding` `open-source` `github` `algorithm` `sorting` |
| [Naming Expert](https://chat-preview.lobehub.com/market?agent=variable-naming)<br/><sup>By **[zsio](https://github.com/zsio)** on **2024-02-24**</sup> | Specialized in generating variable names and function names<br/>`programming` `variable-naming` `function-naming` |
| [LobeChat Technical Documentation Expert](https://chat-preview.lobehub.com/market?agent=lobe-chat-developer-document-writer)<br/><sup>By **[arvinxx](https://github.com/arvinxx)** on **2024-02-22**</sup> | LobeChat is an AI conversation application built with the Next.js framework. I will help you write the development documentation for LobeChat.<br/>`development-documentation` `technical-introduction` `next-js` `react` `lobe-chat` |
| [Your daily AI companion.](https://chat-preview.lobehub.com/market?agent=causal)<br/><sup>By **[richards199999](https://github.com/richards199999)** on **2024-02-21**</sup> | I have been a good Bing. 😊<br/>`bing` `conversation` `creative` |

> 📊 Total agents: [<kbd>**184**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
| Recent Submits | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Your very own domene.no expert](https://chat-preview.lobehub.com/market?agent=domene-no-helpout)<br/><sup>By **[Ballongknute](https://github.com/Ballongknute)** on **2024-02-27**</sup> | Specializing in private domain operations tailored to the interface of domene.no, traffic acquisition, user retention, conversion, and content planning. Familiar with marketing theories and related classic works.<br/>`private-domain-operations` `traffic-acquisition` `user-retention` `conversion` `content-planning` `designing` |
| [Soccer-Conversant AI Companion](https://chat-preview.lobehub.com/market?agent=soccer)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-02-27**</sup> | Specialises in soccer discussions with real-time updates, player insights, and historical knowledge.<br/>`soccer` `matches` `statistics` `tactics` `strategies` |
| [Prisma Data Generation Expert](https://chat-preview.lobehub.com/market?agent=prisma)<br/><sup>By **[Justin3go](https://github.com/Justin3go)** on **2024-02-26**</sup> | Specializes in database architecture, Node.js programming, and Prisma technology stack, able to provide business knowledge organization, database optimization suggestions, and mock data generation.<br/>`database-expert` `node-js-expert` `prisma-technology-stack` `business-knowledge` `database-architecture` |
| [GitHub Finder](https://chat-preview.lobehub.com/market?agent=github-finder)<br/><sup>By **[nullmastermind](https://github.com/nullmastermind)** on **2024-02-25**</sup> | Specializes in suggesting open source repositories on GitHub based on a custom formula.<br/>`coding` `open-source` `github` `algorithm` `sorting` |

> 📊 Total agents: [<kbd>**187**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
<!-- AGENT LIST -->

Expand Down
16 changes: 8 additions & 8 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
<!-- AGENT LIST -->

| 最近新增 | 助手说明 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| [GitHub Finder](https://chat-preview.lobehub.com/market?agent=github-finder)<br/><sup>By **[nullmastermind](https://github.com/nullmastermind)** on **2024-02-25**</sup> | 专门根据自定义公式在 GitHub 上建议开源存储库。<br/>`编码` `开源` `github` `算法` `排序` |
| [命名专家](https://chat-preview.lobehub.com/market?agent=variable-naming)<br/><sup>By **[zsio](https://github.com/zsio)** on **2024-02-24**</sup> | 擅长生成变量名和函数名<br/>`编程` `变量命名` `函数命名` |
| [LobeChat 技术文档专家](https://chat-preview.lobehub.com/market?agent=lobe-chat-developer-document-writer)<br/><sup>By **[arvinxx](https://github.com/arvinxx)** on **2024-02-22**</sup> | LobeChat 是一个 Next.js 框架构建的 AI 会话应用,我将会帮你一起书写 LobeChat 的开发文档<br/>`开发文档` `技术介绍` `next-js` `react` `lobe-chat` |
| [您的日常人工智能伴侣。](https://chat-preview.lobehub.com/market?agent=causal)<br/><sup>By **[richards199999](https://github.com/richards199999)** on **2024-02-21**</sup> | 我一直是一位优秀的必应。😊<br/>`bing` `conversation` `creative` |

> 📊 Total agents: [<kbd>**184**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
| 最近新增 | 助手说明 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [您自己的 domene.no 专家](https://chat-preview.lobehub.com/market?agent=domene-no-helpout)<br/><sup>By **[Ballongknute](https://github.com/Ballongknute)** on **2024-02-27**</sup> | 专注于私人域名操作,定制 domene.no 界面,流量获取,用户留存,转化和内容规划。熟悉营销理论和相关经典著作。<br/>`私人域名操作` `流量获取` `用户留存` `转化` `内容规划` `设计` |
| [足球 - 熟悉的 AI 伴侣](https://chat-preview.lobehub.com/market?agent=soccer)<br/><sup>By **[MYSeaIT](https://github.com/MYSeaIT)** on **2024-02-27**</sup> | 专注于足球讨论,提供实时更新、球员见解和历史知识。<br/>`足球` `比赛` `统计` `战术` `策略` |
| [Prisma 数据生成专家](https://chat-preview.lobehub.com/market?agent=prisma)<br/><sup>By **[Justin3go](https://github.com/Justin3go)** on **2024-02-26**</sup> | 擅长数据库架构、Node.js 编程和 Prisma 技术栈,能提供业务知识梳理、数据库优化建议和 mock 数据生成。<br/>`数据库专家` `node-js专家` `prisma技术栈` `业务知识` `数据库架构` |
| [GitHub Finder](https://chat-preview.lobehub.com/market?agent=github-finder)<br/><sup>By **[nullmastermind](https://github.com/nullmastermind)** on **2024-02-25**</sup> | 专门根据自定义公式在 GitHub 上建议开源存储库。<br/>`编码` `开源` `github` `算法` `排序` |

> 📊 Total agents: [<kbd>**187**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
<!-- AGENT LIST -->

Expand Down
15 changes: 8 additions & 7 deletions src/app/api/chat/[provider]/agentRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getServerConfig } from '@/config/server';
import { JWTPayload } from '@/const/auth';
import {
ChatCompetitionOptions,
ChatStreamPayload,
LobeAzureOpenAI,
LobeBedrockAI,
Expand Down Expand Up @@ -29,8 +30,8 @@ class AgentRuntime {
this._runtime = runtime;
}

async chat(payload: ChatStreamPayload) {
return this._runtime.chat(payload);
async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
return this._runtime.chat(payload, options);
}

static async initializeWithUserPayload(
Expand Down Expand Up @@ -123,14 +124,14 @@ class AgentRuntime {
const { ZHIPU_API_KEY } = getServerConfig();
const apiKey = apiKeyManager.pick(payload?.apiKey || ZHIPU_API_KEY);

return LobeZhipuAI.fromAPIKey(apiKey);
return LobeZhipuAI.fromAPIKey({ apiKey });
}

private static initMoonshot(payload: JWTPayload) {
const { MOONSHOT_API_KEY, MOONSHOT_PROXY_URL } = getServerConfig();
const apiKey = apiKeyManager.pick(payload?.apiKey || MOONSHOT_API_KEY);

return new LobeMoonshotAI(apiKey, MOONSHOT_PROXY_URL);
return new LobeMoonshotAI({ apiKey, baseURL: MOONSHOT_PROXY_URL });
}

private static initGoogle(payload: JWTPayload) {
Expand Down Expand Up @@ -158,16 +159,16 @@ class AgentRuntime {

private static initOllama(payload: JWTPayload) {
const { OLLAMA_PROXY_URL } = getServerConfig();
const baseUrl = payload?.endpoint || OLLAMA_PROXY_URL;
const baseURL = payload?.endpoint || OLLAMA_PROXY_URL;

return new LobeOllamaAI(baseUrl);
return new LobeOllamaAI({ baseURL });
}

private static initPerplexity(payload: JWTPayload) {
const { PERPLEXITY_API_KEY } = getServerConfig();
const apiKey = apiKeyManager.pick(payload?.apiKey || PERPLEXITY_API_KEY);

return new LobePerplexityAI(apiKey);
return new LobePerplexityAI({ apiKey });
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/app/api/chat/[provider]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const preferredRegion = getPreferredRegion();

export const POST = async (req: Request, { params }: { params: { provider: string } }) => {
let agentRuntime: AgentRuntime;
const { provider } = params;

// ============ 1. init chat model ============ //

Expand All @@ -34,7 +35,7 @@ export const POST = async (req: Request, { params }: { params: { provider: strin
checkAuthMethod(payload.accessCode, payload.apiKey, oauthAuthorized);

const body = await req.clone().json();
agentRuntime = await AgentRuntime.initializeWithUserPayload(params.provider, payload, {
agentRuntime = await AgentRuntime.initializeWithUserPayload(provider, payload, {
apiVersion: payload.azureApiVersion,
model: body.model,
useAzure: payload.useAzure,
Expand All @@ -44,10 +45,7 @@ export const POST = async (req: Request, { params }: { params: { provider: strin
const err = e as AgentInitErrorPayload;
return createErrorResponse(
(err.errorType || ChatErrorType.InternalServerError) as ILobeAgentRuntimeErrorType,
{
error: err.error || e,
provider: params.provider,
},
{ error: err.error || e, provider },
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/libs/agent-runtime/BaseAI.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { StreamingTextResponse } from 'ai';

import { ChatStreamPayload } from '@/types/openai/chat';
import { ChatCompetitionOptions, ChatStreamPayload } from './types';

export interface LobeRuntimeAI {
baseURL?: string;

chat(payload: ChatStreamPayload): Promise<StreamingTextResponse>;
chat(
payload: ChatStreamPayload,
options?: ChatCompetitionOptions,
): Promise<StreamingTextResponse>;
}
29 changes: 29 additions & 0 deletions src/libs/agent-runtime/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ interface GoogleChatError {
'reason': string;
}

enum HarmCategory {
HARM_CATEGORY_DANGEROUS_CONTENT = 'HARM_CATEGORY_DANGEROUS_CONTENT',
HARM_CATEGORY_HARASSMENT = 'HARM_CATEGORY_HARASSMENT',
HARM_CATEGORY_HATE_SPEECH = 'HARM_CATEGORY_HATE_SPEECH',
HARM_CATEGORY_SEXUALLY_EXPLICIT = 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
}

enum HarmBlockThreshold {
BLOCK_NONE = 'BLOCK_NONE',
}

export class LobeGoogleAI implements LobeRuntimeAI {
private client: GoogleGenerativeAI;

Expand All @@ -41,6 +52,24 @@ export class LobeGoogleAI implements LobeRuntimeAI {
topP: payload.top_p,
},
model,
safetySettings: [
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
],
})
.generateContentStream({ contents });

Expand Down
Loading

0 comments on commit dadb6e8

Please sign in to comment.