Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: 允许用户自行定义 Embedding 模型 #5177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cookieY
Copy link
Contributor

@cookieY cookieY commented Dec 25, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

由于之前代码commit差距过大 重新提交,提交说明参考 #4370

📝 补充信息 | Additional Information

Copy link

vercel bot commented Dec 25, 2024

@cookieY is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🌠 Feature Request New feature or request | 特性与建议 labels Dec 25, 2024
@lobehubbot
Copy link
Member

👍 @cookieY

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented Dec 25, 2024

Codecov Report

Attention: Patch coverage is 51.50000% with 97 lines in your changes missing coverage. Please review.

Project coverage is 92.02%. Comparing base (50e0dc4) to head (e85f2e5).

Files with missing lines Patch % Lines
src/libs/agent-runtime/bedrock/index.ts 30.76% 45 Missing ⚠️
src/libs/agent-runtime/ollama/index.ts 28.94% 27 Missing ⚠️
...ent-runtime/utils/openaiCompatibleFactory/index.ts 27.58% 21 Missing ⚠️
src/server/globalConfig/index.ts 66.66% 2 Missing ⚠️
src/config/knowledge.ts 75.00% 1 Missing ⚠️
src/database/schemas/ragEvals.ts 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5177      +/-   ##
==========================================
- Coverage   92.20%   92.02%   -0.18%     
==========================================
  Files         568      571       +3     
  Lines       43395    43596     +201     
  Branches     2706     2707       +1     
==========================================
+ Hits        40012    40120     +108     
- Misses       3383     3476      +93     
Flag Coverage Δ
app 92.02% <51.50%> (-0.18%) ⬇️
server 97.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@halexan
Copy link

halexan commented Dec 25, 2024

支不支持本地部署的embedding模型?例如 api 地址是 http://127.0.0.1/v1 的类 openai 接口?

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Does it support locally deployed embedding models? For example, the api address is an openai-like interface at http://127.0.0.1/v1?

@cookieY
Copy link
Contributor Author

cookieY commented Dec 25, 2024

支不支持本地部署的embedding模型?例如 api 地址是 http://127.0.0.1/v1 的类 openai 接口?

基于现有的框架设计无法实现这样的自定义需求,本地部署可以使用 ollama

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Does it support locally deployed embedding models? For example, the api address is an openai-like interface at http://127.0.0.1/v1?

Such custom requirements cannot be achieved based on the existing framework design. For local deployment, ollama can be used.

@@ -4,10 +4,14 @@ import { z } from 'zod';
export const getKnowledgeConfig = () => {
return createEnv({
runtimeEnv: {
DEFAULT_FILES_CONFIG: !!process.env.DEFAULT_FILES_CONFIG
? process.env.DEFAULT_FILES_CONFIG
: 'embedding_model=openai/embedding-text-3-small,reranker_model=cohere/rerank-english-v3.0,query_mode=full_text',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不应该给默认值

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认的 embedding model 、 query model 以及reranker model 不应该用 DEFAULT_SYSTEM_AGENT_ITEM 吧?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能用任何服务端方法。因为 schema 既会在 server 端跑,也会在 client端执行

如果要改默认向量化模型,这里就不需要加 $defaultFn(() => DEFAULT_EMBEDDING_MODEL),

@@ -4,6 +4,7 @@ export interface EmbeddingsPayload {
* supported in `text-embedding-3` and later models.
*/
dimensions?: number;
index?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥这里还需要index?

@@ -275,22 +275,46 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
.filter(Boolean) as ChatModelCard[];
}

/**
* Due to the limitation of a maximum of 8k tokens per request in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8k 不是 request 的要求,而是 openai embedding 模型的上下文大小,因此这里不应该改变。要改也是上层调用 embedding 的地方做 8k 的分块

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的实现逻辑并不合理。system agent 和 embedding 是两个不同的业务功能模块,不应该混在一起。单独写一个 parseFileConfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个模块感觉没有太大必要,而且未来提供 ui 配置还没法合并,不应该这么写。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌠 Feature Request New feature or request | 特性与建议 size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants