Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Oct 31, 2024
2 parents cdb4147 + bce512e commit fe3c102
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 38 deletions.
43 changes: 43 additions & 0 deletions docs/self-hosting/platform/btpanel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Deploy LobeChat using aaPanel
description: Learn how to deploy the LobeChat service using aaPanel-Docker, including installing the Docker container environment and using the command to start the service with one click. Detailed instructions on how to configure environment variables and use proxy addresses.
tags:
- Docker
- LobeChat
- Deployment guidelines
---

## Prerequisite

To install aaPanel, go to the [aaPanel](https://www.aapanel.com/new/download.html#install) official website and select the corresponding script to download and install.

## Deployment

1. Log in to aaPanel and click `Docker` in the menu bar
![install](https://github.com/user-attachments/assets/f67180c2-47ba-4b04-9f12-d274c7821085)

2. The first time you will be prompted to install the `Docker` and `Docker Compose` services, click Install Now. If it is already installed, please ignore it.
![install2](https://github.com/user-attachments/assets/e269bd27-d323-43ba-811b-c0f5e4137903)

3. After the installation is complete, find `LobeChat` in `One-Click Install` and click `install`
![install-LobeChat](https://github.com/user-attachments/assets/9f989104-bb8e-4acd-9721-6b1db1017d2b)

4. configure basic information such as the domain name, OpenAI API key, and port to complete the installation
Note:
The domain name is optional, if the domain name is filled, it can be managed through [Website]--> [Proxy Project], and you do not need to check [Allow external access] after filling in the domain name, otherwise you need to check it before you can access it through the port
![addLobeChat](https://github.com/user-attachments/assets/f0b2e72d-9eee-46a8-b094-4834b78764df)
5. After installation, enter the domain name or IP+ port set in the previous step in the browser to access.
- Name: application name, default `LobeChat-random characters`
- Version selection: default `latest`
- Domain name: If you need to access directly through the domain name, please configure the domain name here and resolve the domain name to the server
- Allow external access: If you need direct access through `IP+Port`, please check. If you have set up a domain name, please do not check here.
- Port: Default `3210`, can be modified by yourself

6. After submission, the panel will automatically initialize the application, which will take about `1-3` minutes. It can be accessed after the initialization is completed.


## Visit LobeChat
- If you have set a domain name, please directly enter the domain name in the browser address bar, such as `http://demo.lobechat`, to access the `LobeChat` console.
- If you choose to access through `IP+Port`, please enter the domain name in the browser address bar to access `http://<aaPanelIP>:3210` to access the `HertzBeat` console.
![console](https://github.com/user-attachments/assets/a1af5778-f47a-4fdc-baf5-ca2a1e66f48e)

49 changes: 49 additions & 0 deletions docs/self-hosting/platform/btpanel.zh-CN.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: 通过 宝塔面板Docker应用商店 部署 LobeChat
description: 学习如何使用 宝塔面板Docker应用 部署 LobeChat 服务,包括安装 Docker 容器环境和使用指令一键启动服务。详细说明如何配置环境变量和使用代理地址。
tags:
- Docker
- LobeChat
- 部署指引
---

# 宝塔面板部署

## 前提
- 仅适用于宝塔面板9.2.0及以上版本
- 安装宝塔面板,前往[宝塔面板](https://www.bt.cn/new/download.html)官网,选择正式版的脚本下载安装


## 部署

1. 登录宝塔面板,在左侧菜单栏中点击 `Docker`
![Docker](https://github.com/user-attachments/assets/15d92756-92f0-45da-8f95-bfe725d13003)

2. 首次会提示安装`Docker``Docker Compose`服务,点击立即安装,若已安装请忽略。
![安装环境](https://github.com/user-attachments/assets/6e383b75-09e3-42d1-8a6c-5fb7cf558f00)

3. 安装完成后在`Docker-应用商店-AI/大模型`中找到 `LobeChat`,点击`安装`
![安装](https://github.com/user-attachments/assets/db59a5e7-32ed-49d7-a791-8f8ee6618c01)

4. 设置域名等基本信息,点击`确定`
![设置](https://github.com/user-attachments/assets/37251adf-949b-4aec-bc49-bf4647e119da)
- 名称:应用名称,默认`lobechat_随机字符`
- 版本选择:默认`latest`
- 域名:如您需要通过域名访问,请在此处填写您的域名
- 允许外部访问:如您需通过`IP+Port`直接访问,请勾选,如您已经设置了域名,请不要勾选此处
- 端口:默认`3210`,可自行修改
- 访问密码:默认随机生成
- OpenAI API 密钥:请输入您的 Open API 密钥
- OpenAI 代理 URL:默认为官方地址
- OpenAI 模型列表:输入使用的模型
- CPU 核心数限制:0为不限制,根据实际需要设置
- 内存限制:0为不限制,根据实际需要设置


5. 提交后面板会自动进行应用初始化,大概需要`1-3`分钟,初始化完成后即可访问。


## 访问 LobeChat
- 如果您填写域名,请在浏览器输入您的域名访问,如`http://demo.lobechat`,即可访问 `LobeChat` 页面。
- 请在浏览器地址栏中输入域名访问 `http://<宝塔面板IP>:3210`,即可访问 `LobeChat` 页面。
![LobeChat](https://github.com/user-attachments/assets/808f8849-5738-4a60-8ccf-01e300b0dc88)
30 changes: 22 additions & 8 deletions src/app/(backend)/webapi/assistant/store/route.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { NextResponse } from 'next/server';

import { DEFAULT_LANG } from '@/const/locale';
import { AssistantStore } from '@/server/modules/AssistantStore';

export const runtime = 'edge';

export const GET = async (req: Request) => {
const locale = new URL(req.url).searchParams.get('locale');
try {
const locale = new URL(req.url).searchParams.get('locale');

const market = new AssistantStore();
const market = new AssistantStore();

let res: Response;
let res: Response;

res = await fetch(market.getAgentIndexUrl(locale as any));
res = await fetch(market.getAgentIndexUrl(locale as any));

if (res.status === 404) {
res = await fetch(market.getAgentIndexUrl(DEFAULT_LANG));
}
if (res.status === 404) {
res = await fetch(market.getAgentIndexUrl(DEFAULT_LANG));
}

return res;
const data = await res.json();
return NextResponse.json(data);
} catch (e) {
console.error(e);
return new Response(`failed to fetch agent market index`, {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
status: 500,
});
}
};
2 changes: 1 addition & 1 deletion src/database/server/schemas/lobechat/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const agents = pgTable('agents', {
.$defaultFn(() => idGenerator('agents'))
.notNull(),
slug: varchar('slug', { length: 100 })
.$defaultFn(() => randomSlug())
.$defaultFn(() => randomSlug(4))
.unique(),
title: text('title'),
description: text('description'),
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/utils/idGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const idGenerator = (namespace: keyof typeof prefixes, size = 12) => {

return `${prefix}_${hash()}`;
};
export const randomSlug = () => (generate(2) as string[]).join('-');
export const randomSlug = (count = 2) => (generate(count) as string[]).join('-');

export const inboxSessionId = (userId: string) => `ssn_inbox_${userId}`;
6 changes: 3 additions & 3 deletions src/libs/agent-runtime/BaseAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatModelCard } from '@/types/llm';
import {
ChatCompetitionOptions,
ChatStreamPayload,
EmbeddingItem,
Embeddings,
EmbeddingsOptions,
EmbeddingsPayload,
TextToImagePayload,
Expand All @@ -17,7 +17,7 @@ export interface LobeRuntimeAI {
baseURL?: string;
chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions): Promise<Response>;

embeddings?(payload: EmbeddingsPayload, options?: EmbeddingsOptions): Promise<EmbeddingItem[]>;
embeddings?(payload: EmbeddingsPayload, options?: EmbeddingsOptions): Promise<Embeddings[]>;

models?(): Promise<any>;

Expand All @@ -40,5 +40,5 @@ export abstract class LobeOpenAICompatibleRuntime {
abstract embeddings(
payload: EmbeddingsPayload,
options?: EmbeddingsOptions,
): Promise<EmbeddingItem[]>;
): Promise<Embeddings[]>;
}
22 changes: 6 additions & 16 deletions src/libs/agent-runtime/types/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,9 @@ export interface EmbeddingsOptions {
user?: string;
}

export interface EmbeddingItem {
/**
* The embedding vector, which is a list of floats. The length of vector depends on
* the model as listed in the
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
*/
embedding: Array<number>;
/**
* The index of the embedding in the list of embeddings.
*/
index: number;
/**
* The object type, which is always "embedding".
*/
object: 'embedding';
}
/**
* The embedding vector, which is a list of floats. The length of vector depends on
* the model as listed in the
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
*/
export type Embeddings = Array<number>;
6 changes: 3 additions & 3 deletions src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ChatCompetitionOptions,
ChatCompletionErrorPayload,
ChatStreamPayload,
EmbeddingItem,
Embeddings,
EmbeddingsOptions,
EmbeddingsPayload,
TextToImagePayload,
Expand Down Expand Up @@ -271,14 +271,14 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
async embeddings(
payload: EmbeddingsPayload,
options?: EmbeddingsOptions,
): Promise<EmbeddingItem[]> {
): Promise<Embeddings[]> {
try {
const res = await this.client.embeddings.create(
{ ...payload, user: options?.user },
{ headers: options?.headers, signal: options?.signal },
);

return res.data;
return res.data.map((item) => item.embedding);
} catch (error) {
throw this.handleError(error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/routers/async/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export const fileRouter = router({
console.timeEnd(`任务[${number}]: embeddings`);

const items: NewEmbeddingsItem[] =
embeddings?.map((e) => ({
chunkId: chunks[e.index].id,
embeddings: e.embedding,
embeddings?.map((e, idx) => ({
chunkId: chunks[idx].id,
embeddings: e,
fileId: input.fileId,
model: input.model,
})) || [];
Expand Down
2 changes: 1 addition & 1 deletion src/server/routers/async/ragEval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ragEvalRouter = router({
});

const embeddingId = await ctx.embeddingModel.create({
embeddings: embeddings?.[0].embedding,
embeddings: embeddings?.[0],
model: embeddingModel,
});

Expand Down
4 changes: 2 additions & 2 deletions src/server/routers/lambda/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const chunkRouter = router({
console.timeEnd('embedding');

return ctx.chunkModel.semanticSearch({
embedding: embeddings![0].embedding,
embedding: embeddings![0],
fileIds: input.fileIds,
query: input.query,
});
Expand All @@ -147,7 +147,7 @@ export const chunkRouter = router({
model: input.model || DEFAULT_EMBEDDING_MODEL,
});

embedding = embeddings![0].embedding;
embedding = embeddings![0];
const embeddingsId = await ctx.embeddingModel.create({
embeddings: embedding,
model: input.model,
Expand Down

0 comments on commit fe3c102

Please sign in to comment.