From 5b124c3635df31a6a0f8ba5e9b9255b165d2155b Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 14 Feb 2025 11:44:15 +0800 Subject: [PATCH 1/6] feat: add new model provider PPIO --- .env.example | 4 + Dockerfile | 2 + Dockerfile.database | 2 + README.md | 5 +- README.zh-CN.md | 2 +- .../environment-variables/model-provider.mdx | 16 ++ .../model-provider.zh-CN.mdx | 16 ++ locales/en-US/providers.json | 3 + locales/zh-CN/providers.json | 3 + .../settings/llm/ProviderList/providers.tsx | 2 + src/config/aiModels/index.ts | 3 + src/config/aiModels/ppio.ts | 255 +++++++++++++++++ src/config/llm.ts | 6 + src/config/modelProviders/index.ts | 5 +- src/config/modelProviders/ppio.ts | 242 ++++++++++++++++ src/libs/agent-runtime/AgentRuntime.ts | 7 + .../ppio/__snapshots__/index.test.ts.snap | 26 ++ .../agent-runtime/ppio/fixtures/models.json | 42 +++ src/libs/agent-runtime/ppio/index.test.ts | 264 ++++++++++++++++++ src/libs/agent-runtime/ppio/index.ts | 38 +++ src/libs/agent-runtime/ppio/type.ts | 12 + src/libs/agent-runtime/types/type.ts | 1 + src/types/user/settings/keyVaults.ts | 1 + 23 files changed, 953 insertions(+), 4 deletions(-) create mode 100644 src/config/aiModels/ppio.ts create mode 100644 src/config/modelProviders/ppio.ts create mode 100644 src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap create mode 100644 src/libs/agent-runtime/ppio/fixtures/models.json create mode 100644 src/libs/agent-runtime/ppio/index.test.ts create mode 100644 src/libs/agent-runtime/ppio/index.ts create mode 100644 src/libs/agent-runtime/ppio/type.ts diff --git a/.env.example b/.env.example index b7a7f4b7e6e88..782b3ba1c4fb0 100644 --- a/.env.example +++ b/.env.example @@ -127,6 +127,10 @@ OPENAI_API_KEY=sk-xxxxxxxxx # TENCENT_CLOUD_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +### PPIO #### + +# PPIO_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + ######################################## ############ Market Service ############ ######################################## diff --git a/Dockerfile b/Dockerfile index 679cc846a0d7d..f11ec07c59706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -203,6 +203,8 @@ ENV \ OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \ # Perplexity PERPLEXITY_API_KEY="" PERPLEXITY_MODEL_LIST="" PERPLEXITY_PROXY_URL="" \ + # PPIO + PPIO_API_KEY="" PPIO_MODEL_LIST="" \ # Qwen QWEN_API_KEY="" QWEN_MODEL_LIST="" QWEN_PROXY_URL="" \ # SambaNova diff --git a/Dockerfile.database b/Dockerfile.database index b1663ed9fd2c0..ad4f0a1d52d35 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -240,6 +240,8 @@ ENV \ OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \ # Perplexity PERPLEXITY_API_KEY="" PERPLEXITY_MODEL_LIST="" PERPLEXITY_PROXY_URL="" \ + # PPIO + PPIO_API_KEY="" PPIO_MODEL_LIST="" \ # Qwen QWEN_API_KEY="" QWEN_MODEL_LIST="" QWEN_PROXY_URL="" \ # SambaNova diff --git a/README.md b/README.md index b3b356d7ca53d..5aa4175e31326 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ We have implemented support for the following model service providers:
See more providers (+26) +- **[PPIO](https://lobechat.com/discover/provider/ppio)**: PPIO supports stable and cost-efficient open-source LLM APIs, such as DeepSeek, Llama, Qwen etc. [Learn more](https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link) - **[Novita](https://lobechat.com/discover/provider/novita)**: Novita AI is a platform providing a variety of large language models and AI image generation API services, flexible, reliable, and cost-effective. It supports the latest open-source models like Llama3 and Mistral, offering a comprehensive, user-friendly, and auto-scaling API solution for generative AI application development, suitable for the rapid growth of AI startups. - **[Together AI](https://lobechat.com/discover/provider/togetherai)**: Together AI is dedicated to achieving leading performance through innovative AI models, offering extensive customization capabilities, including rapid scaling support and intuitive deployment processes to meet various enterprise needs. - **[Fireworks AI](https://lobechat.com/discover/provider/fireworksai)**: Fireworks AI is a leading provider of advanced language model services, focusing on functional calling and multimodal processing. Its latest model, Firefunction V2, is based on Llama-3, optimized for function calling, conversation, and instruction following. The visual language model FireLLaVA-13B supports mixed input of images and text. Other notable models include the Llama series and Mixtral series, providing efficient multilingual instruction following and generation support. @@ -671,7 +672,7 @@ If you would like to learn more details, please feel free to look at our [📘 D ## 🤝 Contributing -Contributions of all types are more than welcome; if you are interested in contributing code, feel free to check out our GitHub [Issues][github-issues-link] and [Projects][github-project-link] to get stuck in to show us what you’re made of. +Contributions of all types are more than welcome; if you are interested in contributing code, feel free to check out our GitHub [Issues][github-issues-link] and [Projects][github-project-link] to get stuck in to show us what you're made of. > \[!TIP] > @@ -892,7 +893,7 @@ This project is [Apache 2.0](./LICENSE) licensed. [profile-link]: https://github.com/lobehub [share-linkedin-link]: https://linkedin.com/feed [share-linkedin-shield]: https://img.shields.io/badge/-share%20on%20linkedin-black?labelColor=black&logo=linkedin&logoColor=white&style=flat-square -[share-mastodon-link]: https://mastodon.social/share?text=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source,%20extensible%20(Function%20Calling),%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT/LLM%20web%20application.%20https://github.com/lobehub/lobe-chat%20#chatbot%20#chatGPT%20#openAI +[share-mastodon-link]: https://mastodon.social/share?text=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source,%20extensible%20%28Function%20Calling%29,%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT%2FLLM%20web%20application.%20https://github.com/lobehub/lobe-chat%20#chatbot%20#chatGPT%20#openAI [share-mastodon-shield]: https://img.shields.io/badge/-share%20on%20mastodon-black?labelColor=black&logo=mastodon&logoColor=white&style=flat-square [share-reddit-link]: https://www.reddit.com/submit?title=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source%2C%20extensible%20%28Function%20Calling%29%2C%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT%2FLLM%20web%20application.%20%23chatbot%20%23chatGPT%20%23openAI&url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat [share-reddit-shield]: https://img.shields.io/badge/-share%20on%20reddit-black?labelColor=black&logo=reddit&logoColor=white&style=flat-square diff --git a/README.zh-CN.md b/README.zh-CN.md index 87ce640bf2b57..083056488a26f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -197,7 +197,7 @@ LobeChat 支持文件上传与知识库功能,你可以上传文件、图片 - **[GitHub](https://lobechat.com/discover/provider/github)**: 通过 GitHub 模型,开发人员可以成为 AI 工程师,并使用行业领先的 AI 模型进行构建。
See more providers (+26) - +- **[PPIO](https://lobechat.com/discover/provider/ppio)**: PPIO 派欧云提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。[了解更多](https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link) - **[Novita](https://lobechat.com/discover/provider/novita)**: Novita AI 是一个提供多种大语言模型与 AI 图像生成的 API 服务的平台,灵活、可靠且具有成本效益。它支持 Llama3、Mistral 等最新的开源模型,并为生成式 AI 应用开发提供了全面、用户友好且自动扩展的 API 解决方案,适合 AI 初创公司的快速发展。 - **[Together AI](https://lobechat.com/discover/provider/togetherai)**: Together AI 致力于通过创新的 AI 模型实现领先的性能,提供广泛的自定义能力,包括快速扩展支持和直观的部署流程,满足企业的各种需求。 - **[Fireworks AI](https://lobechat.com/discover/provider/fireworksai)**: Fireworks AI 是一家领先的高级语言模型服务商,专注于功能调用和多模态处理。其最新模型 Firefunction V2 基于 Llama-3,优化用于函数调用、对话及指令跟随。视觉语言模型 FireLLaVA-13B 支持图像和文本混合输入。其他 notable 模型包括 Llama 系列和 Mixtral 系列,提供高效的多语言指令跟随与生成支持。 diff --git a/docs/self-hosting/environment-variables/model-provider.mdx b/docs/self-hosting/environment-variables/model-provider.mdx index 8b9f1a3f500d2..08dc3e4f91223 100644 --- a/docs/self-hosting/environment-variables/model-provider.mdx +++ b/docs/self-hosting/environment-variables/model-provider.mdx @@ -217,6 +217,22 @@ If you need to use Azure OpenAI to provide model services, you can refer to the - Default: `-` - Example: `-all,+01-ai/yi-34b-chat,+huggingfaceh4/zephyr-7b-beta` +## PPIO + +### `PPIO_API_KEY` + +- Type: Required +- Description: This your PPIO API Key. +- Default: - +- Example: `sk_xxxxxxxxxx` + +### `PPIO_MODEL_LIST` + +- Type: Optional +- Description: Used to control the model list, use `+` to add a model, use `-` to hide a model, use `model_name=display_name` to customize the display name of a model, separated by commas. Definition syntax rules see [model-list][model-list] +- Default: `-` +- Example: `-all,+deepseek/deepseek-v3/community,+deepseek/deepseek-r1-distill-llama-70b` + ## Github ### `GITHUB_TOKEN` diff --git a/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx b/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx index 0a2cfa76880c3..76d66d1546307 100644 --- a/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +++ b/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx @@ -215,6 +215,22 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量, - 默认值:`-` - 示例:`-all,+01-ai/yi-34b-chat,+huggingfaceh4/zephyr-7b-beta` +## PPIO + +### `PPIO_API_KEY` + +- 类型:必选 +- 描述:这是你在 PPIO 网站申请的 API 密钥 +- 默认值:- +- 示例:`sk_xxxxxxxxxxxx` + +### `PPIO_MODEL_LIST` + +- 类型:可选 +- 描述:用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名<扩展配置>` 来自定义模型的展示名,用英文逗号隔开。模型定义语法规则见 [模型列表][model-list] +- 默认值:`-` +- 示例:`-all,+deepseek/deepseek-v3/community,+deepseek/deepseek-r1-distill-llama-70b` + ## Github ### `GITHUB_TOKEN` diff --git a/locales/en-US/providers.json b/locales/en-US/providers.json index cbb5e24c5499f..844daed61fcd9 100644 --- a/locales/en-US/providers.json +++ b/locales/en-US/providers.json @@ -139,5 +139,8 @@ }, "zhipu": { "description": "Zhipu AI offers an open platform for multimodal and language models, supporting a wide range of AI application scenarios, including text processing, image understanding, and programming assistance." + }, + "ppio": { + "description": "PPIO supports stable and cost-efficient open-source LLM APIs, such as DeepSeek, Llama, Qwen etc." } } diff --git a/locales/zh-CN/providers.json b/locales/zh-CN/providers.json index 4ccd0f5cb7e0c..87c288e701a00 100644 --- a/locales/zh-CN/providers.json +++ b/locales/zh-CN/providers.json @@ -139,5 +139,8 @@ }, "zhipu": { "description": "智谱 AI 提供多模态与语言模型的开放平台,支持广泛的AI应用场景,包括文本处理、图像理解与编程辅助等。" + "ppio": { + "description": "PPIO 派欧云提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。" } } + diff --git a/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx b/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx index ce36abdab8512..6d503a1aae6d6 100644 --- a/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx +++ b/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx @@ -21,6 +21,7 @@ import { NvidiaProviderCard, OpenRouterProviderCard, PerplexityProviderCard, + PPIOProviderCard, QwenProviderCard, SambaNovaProviderCard, SenseNovaProviderCard, @@ -98,6 +99,7 @@ export const useProviderList = (): ProviderItem[] => { SiliconCloudProviderCard, HigressProviderCard, GiteeAIProviderCard, + PPIOProviderCard, ], [ AzureProvider, diff --git a/src/config/aiModels/index.ts b/src/config/aiModels/index.ts index 1b540d01e0072..7cd0ed49c669d 100644 --- a/src/config/aiModels/index.ts +++ b/src/config/aiModels/index.ts @@ -30,6 +30,7 @@ import { default as ollama } from './ollama'; import { default as openai } from './openai'; import { default as openrouter } from './openrouter'; import { default as perplexity } from './perplexity'; +import { default as ppio } from './ppio'; import { default as qwen } from './qwen'; import { default as sambanova } from './sambanova'; import { default as sensenova } from './sensenova'; @@ -98,6 +99,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({ openai, openrouter, perplexity, + ppio, qwen, sambanova, sensenova, @@ -147,6 +149,7 @@ export { default as ollama } from './ollama'; export { default as openai } from './openai'; export { default as openrouter } from './openrouter'; export { default as perplexity } from './perplexity'; +export { default as ppio } from './ppio'; export { default as qwen } from './qwen'; export { default as sambanova } from './sambanova'; export { default as sensenova } from './sensenova'; diff --git a/src/config/aiModels/ppio.ts b/src/config/aiModels/ppio.ts new file mode 100644 index 0000000000000..3fae831596b01 --- /dev/null +++ b/src/config/aiModels/ppio.ts @@ -0,0 +1,255 @@ +import { AIChatModelCard } from '@/types/aiModel'; + +const ppioChatModels: AIChatModelCard[] = [ + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "displayName": "DeepSeek: DeepSeek R1(Community)", + "enabled": true, + "id": "deepseek/deepseek-r1/community", + "pricing": { + "currency": "CNY", + "input": 4, + "output": 16 + }, + "type": "chat" + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "displayName": "DeepSeek: DeepSeek V3(Community)\t", + "enabled": true, + "id": "deepseek/deepseek-v3/community", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 2 + }, + "type": "chat" + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "displayName": "DeepSeek R1", + "enabled": true, + "id": "deepseek/deepseek-r1", + "pricing": { + "currency": "CNY", + "input": 4, + "output": 16 + }, + "type": "chat" + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "displayName": "DeepSeek V3", + "enabled": true, + "id": "deepseek/deepseek-v3", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 2 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_000, + "description": "DeepSeek R1 Distill Llama 70B是基于Llama3.3 70B的大型语言模型,该模型利用DeepSeek R1输出的微调,实现了与大型前沿模型相当的竞争性能。", + "displayName": "DeepSeek R1 Distill Llama 70B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-llama-70b", + "pricing": { + "currency": "CNY", + "input": 5.8, + "output": 5.8 + }, + "type": "chat" + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1 Distill Qwen 32B 是一种基于 Qwen 2.5 32B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 72.6\nMATH-500 pass@1: 94.3\nCodeForces Rating: 1691\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", + "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 32B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-qwen-32b", + "pricing": { + "currency": "CNY", + "input": 2.18, + "output": 2.18 + }, + "type": "chat" + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1 Distill Qwen 14B 是一种基于 Qwen 2.5 14B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 69.7\nMATH-500 pass@1: 93.9\nCodeForces Rating: 1481\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", + "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 14B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-qwen-14b", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 1 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_000, + "description": "DeepSeek R1 Distill Llama 8B 是一种基于 Llama-3.1-8B-Instruct 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。", + "displayName": "DeepSeek: DeepSeek R1 Distill Llama 8B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-llama-8b", + "pricing": { + "currency": "CNY", + "input": 0.3, + "output": 0.3 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2.5-72B-Instruct 是阿里云发布的最新大语言模型系列之一。该 72B 模型在编码和数学等领域具有显著改进的能力。该模型还提供了多语言支持,覆盖超过 29 种语言,包括中文、英文等。模型在指令跟随、理解结构化数据以及生成结构化输出(尤其是 JSON)方面都有显著提升。", + "displayName": "qwen/qwen-2.5-72b-instruct", + "enabled": true, + "id": "qwen/qwen-2.5-72b-instruct", + "pricing": { + "currency": "CNY", + "input": 2.75, + "output": 2.88 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2-VL 是 Qwen-VL 模型的最新迭代版本,在视觉理解基准测试中达到了最先进的性能,包括 MathVista、DocVQA、RealWorldQA 和 MTVQA 等。Qwen2-VL 能够理解超过 20 分钟的视频,用于高质量的基于视频的问答、对话和内容创作。它还具备复杂推理和决策能力,可以与移动设备、机器人等集成,基于视觉环境和文本指令进行自动操作。除了英语和中文,Qwen2-VL 现在还支持理解图像中不同语言的文本,包括大多数欧洲语言、日语、韩语、阿拉伯语和越南语等", + "displayName": "qwen/qwen-2-vl-72b-instruct", + "enabled": true, + "id": "qwen/qwen-2-vl-72b-instruct", + "pricing": { + "currency": "CNY", + "input": 4.5, + "output": 4.5 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "meta-llama/llama-3.2-3b-instruct", + "displayName": "meta-llama/llama-3.2-3b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.2-3b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.216, + "output": 0.36 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_000, + "description": "Qwen2.5-32B-Instruct 是阿里云发布的最新大语言模型系列之一。该 32B 模型在编码和数学等领域具有显著改进的能力。该模型提供了多语言支持,覆盖超过 29 种语言,包括中文、英文等。模型在指令跟随、理解结构化数据以及生成结构化输出(尤其是 JSON)方面都有显著提升。", + "displayName": "qwen/qwen2.5-32b-instruct", + "enabled": true, + "id": "qwen/qwen2.5-32b-instruct", + "pricing": { + "currency": "CNY", + "input": 1.26, + "output": 1.26 + }, + "type": "chat" + }, + { + "contextWindowTokens": 14_336, + "description": "Baichuan-13B 百川智能开发的包含 130 亿参数的开源可商用的大规模语言模型,在权威的中文和英文 benchmark 上均取得同尺寸最好的效果", + "displayName": "baichuan/baichuan2-13b-chat", + "enabled": true, + "id": "baichuan/baichuan2-13b-chat", + "pricing": { + "currency": "CNY", + "input": 1.75, + "output": 1.75 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "Meta最新一代的Llama 3.1模型系列,70B(700亿参数)的指令微调版本针对高质量对话场景进行了优化。在业界评估中,与领先的闭源模型相比,它展现出了强劲的性能。(仅针对企业实名认证通过主体开放)", + "displayName": "meta-llama/llama-3.1-70b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.1-70b-instruct", + "pricing": { + "currency": "CNY", + "input": 2.45, + "output": 2.82 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "Meta最新一代的Llama 3.1模型系列,8B(80亿参数)的指令微调版本特别快速高效。在业界评估中,表现出强劲的性能,超越了很多领先的闭源模型。(仅针对企业实名认证通过主体开放)", + "displayName": "meta-llama/llama-3.1-8b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.1-8b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.4, + "output": 0.4 + }, + "type": "chat" + }, + { + "contextWindowTokens": 16_384, + "description": "零一万物,最新开源微调模型,340亿参数,微调支持多种对话场景,高质量训练数据,对齐人类偏好。", + "displayName": "01-ai/yi-1.5-34b-chat", + "enabled": true, + "id": "01-ai/yi-1.5-34b-chat", + "pricing": { + "currency": "CNY", + "input": 1.1, + "output": 1.1 + }, + "type": "chat" + }, + { + "contextWindowTokens": 16_384, + "description": "零一万物,最新开源微调模型,90亿参数,微调支持多种对话场景,高质量训练数据,对齐人类偏好。", + "displayName": "01-ai/yi-1.5-9b-chat", + "enabled": true, + "id": "01-ai/yi-1.5-9b-chat", + "pricing": { + "currency": "CNY", + "input": 0.4, + "output": 0.4 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "智谱AI发布的GLM-4系列最新一代预训练模型的开源版本。", + "displayName": "thudm/glm-4-9b-chat", + "enabled": true, + "id": "thudm/glm-4-9b-chat", + "pricing": { + "currency": "CNY", + "input": 0.5, + "output": 0.5 + }, + "type": "chat" + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2是全新的Qwen大型语言模型系列。Qwen2 7B是一个基于transformer的模型,在语言理解、多语言能力、编程、数学和推理方面表现出色。", + "displayName": "qwen/qwen-2-7b-instruct", + "enabled": true, + "id": "qwen/qwen-2-7b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.32, + "output": 0.32 + }, + "type": "chat" + } +] + +export const allModels = [...ppioChatModels]; + +export default allModels; \ No newline at end of file diff --git a/src/config/llm.ts b/src/config/llm.ts index 6dee94976de0d..c4e1411c454a5 100644 --- a/src/config/llm.ts +++ b/src/config/llm.ts @@ -147,6 +147,9 @@ export const getLLMConfig = () => { ENABLED_SAMBANOVA: z.boolean(), SAMBANOVA_API_KEY: z.string().optional(), + + ENABLED_PPIO: z.boolean(), + PPIO_API_KEY: z.string().optional(), }, runtimeEnv: { API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE, @@ -292,6 +295,9 @@ export const getLLMConfig = () => { ENABLED_SAMBANOVA: !!process.env.SAMBANOVA_API_KEY, SAMBANOVA_API_KEY: process.env.SAMBANOVA_API_KEY, + + ENABLED_PPIO: !!process.env.PPIO_API_KEY, + PPIO_API_KEY: process.env.PPIO_API_KEY, }, }); }; diff --git a/src/config/modelProviders/index.ts b/src/config/modelProviders/index.ts index 0ead7d0b69565..2055a20a8f096 100644 --- a/src/config/modelProviders/index.ts +++ b/src/config/modelProviders/index.ts @@ -30,6 +30,7 @@ import OllamaProvider from './ollama'; import OpenAIProvider from './openai'; import OpenRouterProvider from './openrouter'; import PerplexityProvider from './perplexity'; +import PPIOProvider from './ppio'; import QwenProvider from './qwen'; import SambaNovaProvider from './sambanova'; import SenseNovaProvider from './sensenova'; @@ -142,7 +143,8 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [ TaichuProvider, Ai360Provider, DoubaoProvider, -]; + PPIOProvider, +] as const; export const filterEnabledModels = (provider: ModelProviderCard) => { return provider.chatModels.filter((v) => v.enabled).map((m) => m.id); @@ -183,6 +185,7 @@ export { default as OllamaProviderCard } from './ollama'; export { default as OpenAIProviderCard } from './openai'; export { default as OpenRouterProviderCard } from './openrouter'; export { default as PerplexityProviderCard } from './perplexity'; +export { default as PPIOProviderCard } from './ppio'; export { default as QwenProviderCard } from './qwen'; export { default as SambaNovaProviderCard } from './sambanova'; export { default as SenseNovaProviderCard } from './sensenova'; diff --git a/src/config/modelProviders/ppio.ts b/src/config/modelProviders/ppio.ts new file mode 100644 index 0000000000000..dc0f2300020c6 --- /dev/null +++ b/src/config/modelProviders/ppio.ts @@ -0,0 +1,242 @@ +import { ModelProviderCard } from '@/types/llm'; + +const PPIO: ModelProviderCard = { + chatModels: [ + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "displayName": "DeepSeek: DeepSeek R1(Community)", + "enabled": true, + "id": "deepseek/deepseek-r1/community", + "pricing": { + "currency": "CNY", + "input": 4, + "output": 16 + } + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "displayName": "DeepSeek: DeepSeek V3(Community)\t", + "enabled": true, + "id": "deepseek/deepseek-v3/community", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 2 + } + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "displayName": "DeepSeek R1", + "enabled": true, + "id": "deepseek/deepseek-r1", + "pricing": { + "currency": "CNY", + "input": 4, + "output": 16 + } + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "displayName": "DeepSeek V3", + "enabled": true, + "id": "deepseek/deepseek-v3", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 2 + } + }, + { + "contextWindowTokens": 32_000, + "description": "DeepSeek R1 Distill Llama 70B是基于Llama3.3 70B的大型语言模型,该模型利用DeepSeek R1输出的微调,实现了与大型前沿模型相当的竞争性能。", + "displayName": "DeepSeek R1 Distill Llama 70B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-llama-70b", + "pricing": { + "currency": "CNY", + "input": 5.8, + "output": 5.8 + } + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1 Distill Qwen 32B 是一种基于 Qwen 2.5 32B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 72.6\nMATH-500 pass@1: 94.3\nCodeForces Rating: 1691\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", + "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 32B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-qwen-32b", + "pricing": { + "currency": "CNY", + "input": 2.18, + "output": 2.18 + } + }, + { + "contextWindowTokens": 64_000, + "description": "DeepSeek R1 Distill Qwen 14B 是一种基于 Qwen 2.5 14B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 69.7\nMATH-500 pass@1: 93.9\nCodeForces Rating: 1481\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", + "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 14B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-qwen-14b", + "pricing": { + "currency": "CNY", + "input": 1, + "output": 1 + } + }, + { + "contextWindowTokens": 32_000, + "description": "DeepSeek R1 Distill Llama 8B 是一种基于 Llama-3.1-8B-Instruct 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。", + "displayName": "DeepSeek: DeepSeek R1 Distill Llama 8B", + "enabled": true, + "id": "deepseek/deepseek-r1-distill-llama-8b", + "pricing": { + "currency": "CNY", + "input": 0.3, + "output": 0.3 + } + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2.5-72B-Instruct 是阿里云发布的最新大语言模型系列之一。该 72B 模型在编码和数学等领域具有显著改进的能力。该模型还提供了多语言支持,覆盖超过 29 种语言,包括中文、英文等。模型在指令跟随、理解结构化数据以及生成结构化输出(尤其是 JSON)方面都有显著提升。", + "displayName": "qwen/qwen-2.5-72b-instruct", + "enabled": true, + "id": "qwen/qwen-2.5-72b-instruct", + "pricing": { + "currency": "CNY", + "input": 2.75, + "output": 2.88 + } + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2-VL 是 Qwen-VL 模型的最新迭代版本,在视觉理解基准测试中达到了最先进的性能,包括 MathVista、DocVQA、RealWorldQA 和 MTVQA 等。Qwen2-VL 能够理解超过 20 分钟的视频,用于高质量的基于视频的问答、对话和内容创作。它还具备复杂推理和决策能力,可以与移动设备、机器人等集成,基于视觉环境和文本指令进行自动操作。除了英语和中文,Qwen2-VL 现在还支持理解图像中不同语言的文本,包括大多数欧洲语言、日语、韩语、阿拉伯语和越南语等", + "displayName": "qwen/qwen-2-vl-72b-instruct", + "enabled": true, + "id": "qwen/qwen-2-vl-72b-instruct", + "pricing": { + "currency": "CNY", + "input": 4.5, + "output": 4.5 + } + }, + { + "contextWindowTokens": 32_768, + "description": "meta-llama/llama-3.2-3b-instruct", + "displayName": "meta-llama/llama-3.2-3b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.2-3b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.216, + "output": 0.36 + } + }, + { + "contextWindowTokens": 32_000, + "description": "Qwen2.5-32B-Instruct 是阿里云发布的最新大语言模型系列之一。该 32B 模型在编码和数学等领域具有显著改进的能力。该模型提供了多语言支持,覆盖超过 29 种语言,包括中文、英文等。模型在指令跟随、理解结构化数据以及生成结构化输出(尤其是 JSON)方面都有显著提升。", + "displayName": "qwen/qwen2.5-32b-instruct", + "enabled": true, + "id": "qwen/qwen2.5-32b-instruct", + "pricing": { + "currency": "CNY", + "input": 1.26, + "output": 1.26 + } + }, + { + "contextWindowTokens": 14_336, + "description": "Baichuan-13B 百川智能开发的包含 130 亿参数的开源可商用的大规模语言模型,在权威的中文和英文 benchmark 上均取得同尺寸最好的效果", + "displayName": "baichuan/baichuan2-13b-chat", + "enabled": true, + "id": "baichuan/baichuan2-13b-chat", + "pricing": { + "currency": "CNY", + "input": 1.75, + "output": 1.75 + } + }, + { + "contextWindowTokens": 32_768, + "description": "Meta最新一代的Llama 3.1模型系列,70B(700亿参数)的指令微调版本针对高质量对话场景进行了优化。在业界评估中,与领先的闭源模型相比,它展现出了强劲的性能。(仅针对企业实名认证通过主体开放)", + "displayName": "meta-llama/llama-3.1-70b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.1-70b-instruct", + "pricing": { + "currency": "CNY", + "input": 2.45, + "output": 2.82 + } + }, + { + "contextWindowTokens": 32_768, + "description": "Meta最新一代的Llama 3.1模型系列,8B(80亿参数)的指令微调版本特别快速高效。在业界评估中,表现出强劲的性能,超越了很多领先的闭源模型。(仅针对企业实名认证通过主体开放)", + "displayName": "meta-llama/llama-3.1-8b-instruct", + "enabled": true, + "id": "meta-llama/llama-3.1-8b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.4, + "output": 0.4 + } + }, + { + "contextWindowTokens": 16_384, + "description": "零一万物,最新开源微调模型,340亿参数,微调支持多种对话场景,高质量训练数据,对齐人类偏好。", + "displayName": "01-ai/yi-1.5-34b-chat", + "enabled": true, + "id": "01-ai/yi-1.5-34b-chat", + "pricing": { + "currency": "CNY", + "input": 1.1, + "output": 1.1 + } + }, + { + "contextWindowTokens": 16_384, + "description": "零一万物,最新开源微调模型,90亿参数,微调支持多种对话场景,高质量训练数据,对齐人类偏好。", + "displayName": "01-ai/yi-1.5-9b-chat", + "enabled": true, + "id": "01-ai/yi-1.5-9b-chat", + "pricing": { + "currency": "CNY", + "input": 0.4, + "output": 0.4 + } + }, + { + "contextWindowTokens": 32_768, + "description": "智谱AI发布的GLM-4系列最新一代预训练模型的开源版本。", + "displayName": "thudm/glm-4-9b-chat", + "enabled": true, + "id": "thudm/glm-4-9b-chat", + "pricing": { + "currency": "CNY", + "input": 0.5, + "output": 0.5 + } + }, + { + "contextWindowTokens": 32_768, + "description": "Qwen2是全新的Qwen大型语言模型系列。Qwen2 7B是一个基于transformer的模型,在语言理解、多语言能力、编程、数学和推理方面表现出色。", + "displayName": "qwen/qwen-2-7b-instruct", + "enabled": true, + "id": "qwen/qwen-2-7b-instruct", + "pricing": { + "currency": "CNY", + "input": 0.32, + "output": 0.32 + } + } + ], // Will be updated with model list + disableBrowserRequest: true, + id: 'ppio', + modelList: { showModelFetcher: true }, + name: 'PPIO', + settings: {}, + url: 'https://ppinfra.com/?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link', +}; + +export default PPIO; \ No newline at end of file diff --git a/src/libs/agent-runtime/AgentRuntime.ts b/src/libs/agent-runtime/AgentRuntime.ts index 2c56de177f72d..55cae0705180c 100644 --- a/src/libs/agent-runtime/AgentRuntime.ts +++ b/src/libs/agent-runtime/AgentRuntime.ts @@ -32,6 +32,7 @@ import { LobeOllamaAI } from './ollama'; import { LobeOpenAI } from './openai'; import { LobeOpenRouterAI } from './openrouter'; import { LobePerplexityAI } from './perplexity'; +import { LobePPIOAI } from './ppio'; import { LobeQwenAI } from './qwen'; import { LobeSambaNovaAI } from './sambanova'; import { LobeSenseNovaAI } from './sensenova'; @@ -169,6 +170,7 @@ class AgentRuntime { openai: Partial; openrouter: Partial; perplexity: Partial; + ppio: Partial; qwen: Partial; sambanova: Partial; sensenova: Partial; @@ -421,6 +423,11 @@ class AgentRuntime { runtimeModel = new LobeWenxinAI(params.wenxin); break; } + + case ModelProvider.PPIO: { + runtimeModel = new LobePPIOAI(params.ppio ?? {}); + break; + } } return new AgentRuntime(runtimeModel); } diff --git a/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap b/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap new file mode 100644 index 0000000000000..40cbd426448a5 --- /dev/null +++ b/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap @@ -0,0 +1,26 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`PPIO > models > should get models 1`] = ` +[ + { + "contextWindowTokens": 64000, + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "displayName": "DeepSeek: DeepSeek R1(Community)", + "enabled": true, + "functionCall": false, + "id": "deepseek/deepseek-r1/community", + "reasoning": true, + "vision": false, + }, + { + "contextWindowTokens": 64000, + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "displayName": "DeepSeek: DeepSeek V3(Community)", + "enabled": true, + "functionCall": false, + "id": "deepseek/deepseek-v3/community", + "reasoning": false, + "vision": false, + }, +] +`; diff --git a/src/libs/agent-runtime/ppio/fixtures/models.json b/src/libs/agent-runtime/ppio/fixtures/models.json new file mode 100644 index 0000000000000..964a70c3620a2 --- /dev/null +++ b/src/libs/agent-runtime/ppio/fixtures/models.json @@ -0,0 +1,42 @@ +[ + { + "created": 1738928740, + "id": "deepseek/deepseek-r1/community", + "object": "model", + "owned_by": "unknown", + "permission": null, + "root": "", + "parent": "", + "input_token_price_per_m": 40000, + "output_token_price_per_m": 160000, + "title": "deepseek/deepseek-r1/community", + "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", + "tags": [ + "全参数", + "满血版" + ], + "context_size": 64000, + "status": 1, + "display_name": "DeepSeek: DeepSeek R1(Community)" + }, + { + "created": 1738928844, + "id": "deepseek/deepseek-v3/community", + "object": "model", + "owned_by": "unknown", + "permission": null, + "root": "", + "parent": "", + "input_token_price_per_m": 10000, + "output_token_price_per_m": 20000, + "title": "deepseek/deepseek-v3/community", + "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", + "tags": [ + "全参数", + "满血版" + ], + "context_size": 64000, + "status": 1, + "display_name": "DeepSeek: DeepSeek V3(Community)" + } +] \ No newline at end of file diff --git a/src/libs/agent-runtime/ppio/index.test.ts b/src/libs/agent-runtime/ppio/index.test.ts new file mode 100644 index 0000000000000..8e1233cb0195f --- /dev/null +++ b/src/libs/agent-runtime/ppio/index.test.ts @@ -0,0 +1,264 @@ + // @vitest-environment node +import OpenAI from 'openai'; +import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +import { LobeOpenAICompatibleRuntime } from '@/libs/agent-runtime'; +import { ModelProvider } from '@/libs/agent-runtime'; +import { AgentRuntimeErrorType } from '@/libs/agent-runtime'; + +import * as debugStreamModule from '../utils/debugStream'; +import models from './fixtures/models.json'; +import { LobePPIOAI } from './index'; + +const provider = ModelProvider.PPIO; +const defaultBaseURL = 'https://api.ppinfra.com/v3/openai'; +const bizErrorType = AgentRuntimeErrorType.ProviderBizError; +const invalidErrorType = AgentRuntimeErrorType.InvalidProviderAPIKey; + +// Mock the console.error to avoid polluting test output +vi.spyOn(console, 'error').mockImplementation(() => {}); + +let instance: LobeOpenAICompatibleRuntime; + +beforeEach(() => { + instance = new LobePPIOAI({ apiKey: 'test' }); + + // 使用 vi.spyOn 来模拟 chat.completions.create 方法 + vi.spyOn(instance['client'].chat.completions, 'create').mockResolvedValue( + new ReadableStream() as any, + ); + vi.spyOn(instance['client'].models, 'list').mockResolvedValue({ data: [] } as any); +}); + +afterEach(() => { + vi.clearAllMocks(); +}); + +describe('PPIO', () => { + describe('init', () => { + it('should correctly initialize with an API key', async () => { + const instance = new LobePPIOAI({ apiKey: 'test_api_key' }); + expect(instance).toBeInstanceOf(LobePPIOAI); + expect(instance.baseURL).toEqual(defaultBaseURL); + }); + }); + + describe('chat', () => { + describe('Error', () => { + it('should return Error with an openai error response when OpenAI.APIError is thrown', async () => { + // Arrange + const apiError = new OpenAI.APIError( + 400, + { + status: 400, + error: { + message: 'Bad Request', + }, + }, + 'Error message', + {}, + ); + + vi.spyOn(instance['client'].chat.completions, 'create').mockRejectedValue(apiError); + + // Act + try { + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + temperature: 0.999, + }); + } catch (e) { + expect(e).toEqual({ + endpoint: defaultBaseURL, + error: { + error: { message: 'Bad Request' }, + status: 400, + }, + errorType: bizErrorType, + provider, + }); + } + }); + + it('should throw AgentRuntimeError if no apiKey is provided', async () => { + try { + new LobePPIOAI({}); + } catch (e) { + expect(e).toEqual({ errorType: invalidErrorType }); + } + }); + + it('should return Error with the cause when OpenAI.APIError is thrown with cause', async () => { + // Arrange + const errorInfo = { + stack: 'abc', + cause: { + message: 'api is undefined', + }, + }; + const apiError = new OpenAI.APIError(400, errorInfo, 'module error', {}); + + vi.spyOn(instance['client'].chat.completions, 'create').mockRejectedValue(apiError); + + // Act + try { + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + temperature: 0.999, + }); + } catch (e) { + expect(e).toEqual({ + endpoint: defaultBaseURL, + error: { + cause: { message: 'api is undefined' }, + stack: 'abc', + }, + errorType: bizErrorType, + provider, + }); + } + }); + + it('should return Error with an cause response with desensitize Url', async () => { + // Arrange + const errorInfo = { + stack: 'abc', + cause: { message: 'api is undefined' }, + }; + const apiError = new OpenAI.APIError(400, errorInfo, 'module error', {}); + + instance = new LobePPIOAI({ + apiKey: 'test', + + baseURL: 'https://api.abc.com/v1', + }); + + vi.spyOn(instance['client'].chat.completions, 'create').mockRejectedValue(apiError); + + // Act + try { + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + temperature: 0.999, + }); + } catch (e) { + expect(e).toEqual({ + endpoint: 'https://api.***.com/v1', + error: { + cause: { message: 'api is undefined' }, + stack: 'abc', + }, + errorType: bizErrorType, + provider, + }); + } + }); + + it('should throw an error type on 401 status code', async () => { + // Mock the API call to simulate a 401 error + const error = new Error('InvalidApiKey') as any; + error.status = 401; + vi.mocked(instance['client'].chat.completions.create).mockRejectedValue(error); + + try { + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + temperature: 0.999, + }); + } catch (e) { + expect(e).toEqual({ + endpoint: defaultBaseURL, + error: new Error('InvalidApiKey'), + errorType: invalidErrorType, + provider, + }); + } + }); + + it('should return AgentRuntimeError for non-OpenAI errors', async () => { + // Arrange + const genericError = new Error('Generic Error'); + + vi.spyOn(instance['client'].chat.completions, 'create').mockRejectedValue(genericError); + + // Act + try { + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + temperature: 0.999, + }); + } catch (e) { + expect(e).toEqual({ + endpoint: defaultBaseURL, + errorType: 'AgentRuntimeError', + provider, + error: { + name: genericError.name, + cause: genericError.cause, + message: genericError.message, + stack: genericError.stack, + }, + }); + } + }); + }); + + describe('DEBUG', () => { + it('should call debugStream and return StreamingTextResponse when DEBUG_PPIO_CHAT_COMPLETION is 1', async () => { + // Arrange + const mockProdStream = new ReadableStream() as any; // 模拟的 prod 流 + const mockDebugStream = new ReadableStream({ + start(controller) { + controller.enqueue('Debug stream content'); + controller.close(); + }, + }) as any; + mockDebugStream.toReadableStream = () => mockDebugStream; // 添加 toReadableStream 方法 + + // 模拟 chat.completions.create 返回值,包括模拟的 tee 方法 + (instance['client'].chat.completions.create as Mock).mockResolvedValue({ + tee: () => [mockProdStream, { toReadableStream: () => mockDebugStream }], + }); + + // 保存原始环境变量值 + const originalDebugValue = process.env.DEBUG_PPIO_CHAT_COMPLETION; + + // 模拟环境变量 + process.env.DEBUG_PPIO_CHAT_COMPLETION = '1'; + vi.spyOn(debugStreamModule, 'debugStream').mockImplementation(() => Promise.resolve()); + + // 执行测试 + // 运行你的测试函数,确保它会在条件满足时调用 debugStream + // 假设的测试函数调用,你可能需要根据实际情况调整 + await instance.chat({ + messages: [{ content: 'Hello', role: 'user' }], + model: 'meta-llama/llama-3-8b-instruct', + stream: true, + temperature: 0.999, + }); + + // 验证 debugStream 被调用 + expect(debugStreamModule.debugStream).toHaveBeenCalled(); + + // 恢复原始环境变量值 + process.env.DEBUG_PPIO_CHAT_COMPLETION = originalDebugValue; + }); + }); + }); + + describe('models', () => { + it('should get models', async () => { + // mock the models.list method + (instance['client'].models.list as Mock).mockResolvedValue({ data: models }); + + const list = await instance.models(); + + expect(list).toMatchSnapshot(); + }); + }); +}); diff --git a/src/libs/agent-runtime/ppio/index.ts b/src/libs/agent-runtime/ppio/index.ts new file mode 100644 index 0000000000000..3e307a13b5929 --- /dev/null +++ b/src/libs/agent-runtime/ppio/index.ts @@ -0,0 +1,38 @@ +import { ModelProvider } from '../types'; +import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; +import { PPIOModelCard } from './type'; + +import { LOBE_DEFAULT_MODEL_LIST } from '@/config/aiModels'; + +export const LobePPIOAI = LobeOpenAICompatibleFactory({ + baseURL: 'https://api.ppinfra.com/v3/openai', + constructorOptions: { + defaultHeaders: { + 'X-API-Source': 'lobechat', + }, + }, + debug: { + chatCompletion: () => process.env.DEBUG_PPIO_CHAT_COMPLETION === '1', + }, + models: { + transformModel: (m) => { + const reasoningKeywords = [ + 'deepseek-r1', + ]; + + const model = m as unknown as PPIOModelCard; + + return { + contextWindowTokens: model.context_size, + description: model.description, + displayName: model.display_name || model.title || model.id, + enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false, + functionCall: model.description.toLowerCase().includes('function calling'), + id: model.id, + reasoning: model.description.toLowerCase().includes('reasoning task') || reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)), + vision: model.description.toLowerCase().includes('视觉'), + }; + }, + }, + provider: ModelProvider.PPIO, +}); diff --git a/src/libs/agent-runtime/ppio/type.ts b/src/libs/agent-runtime/ppio/type.ts new file mode 100644 index 0000000000000..c3704ac026473 --- /dev/null +++ b/src/libs/agent-runtime/ppio/type.ts @@ -0,0 +1,12 @@ +export interface PPIOModelCard { + context_size: number; + created: number; + description: string; + display_name: string; + id: string; + input_token_price_per_m: number; + output_token_price_per_m: number; + status: number; + tags: string[]; + title: string; +} diff --git a/src/libs/agent-runtime/types/type.ts b/src/libs/agent-runtime/types/type.ts index 1e7402d344664..5517a31b750ec 100644 --- a/src/libs/agent-runtime/types/type.ts +++ b/src/libs/agent-runtime/types/type.ts @@ -54,6 +54,7 @@ export enum ModelProvider { Ollama = 'ollama', OpenAI = 'openai', OpenRouter = 'openrouter', + PPIO = 'ppio', Perplexity = 'perplexity', Qwen = 'qwen', SambaNova = 'sambanova', diff --git a/src/types/user/settings/keyVaults.ts b/src/types/user/settings/keyVaults.ts index 8cb7efde1a2c4..ed7ad7ddb9869 100644 --- a/src/types/user/settings/keyVaults.ts +++ b/src/types/user/settings/keyVaults.ts @@ -58,6 +58,7 @@ export interface UserKeyVaults { openrouter?: OpenAICompatibleKeyVault; password?: string; perplexity?: OpenAICompatibleKeyVault; + ppio?: OpenAICompatibleKeyVault; qwen?: OpenAICompatibleKeyVault; sambanova?: OpenAICompatibleKeyVault; sensenova?: OpenAICompatibleKeyVault; From 4589159625751e211e5e6fc2139b53694f377807 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 15 Feb 2025 00:10:30 +0800 Subject: [PATCH 2/6] feat: add usage docs; fix model configs --- docs/usage/providers/ppio.mdx | 57 +++++++++++++++++++ docs/usage/providers/ppio.zh-CN.mdx | 55 ++++++++++++++++++ src/config/aiModels/ppio.ts | 31 +++++++++- src/config/modelProviders/index.ts | 2 +- src/config/modelProviders/ppio.ts | 14 +++-- .../ppio/__snapshots__/index.test.ts.snap | 4 +- .../agent-runtime/ppio/fixtures/models.json | 4 +- src/libs/agent-runtime/ppio/index.ts | 2 +- 8 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 docs/usage/providers/ppio.mdx create mode 100644 docs/usage/providers/ppio.zh-CN.mdx diff --git a/docs/usage/providers/ppio.mdx b/docs/usage/providers/ppio.mdx new file mode 100644 index 0000000000000..dba0a1554d492 --- /dev/null +++ b/docs/usage/providers/ppio.mdx @@ -0,0 +1,57 @@ +--- +title: Using PPIO API Key in LobeChat +description: >- + Learn how to integrate PPIO's language model APIs into LobeChat. Follow + the steps to register, create an PPIO API key, configure settings, and + chat with our various AI models. +tags: + - PPIO + - DeepSeek + - Llama + - Qwen + - uncensored + - API key + - Web UI +--- + +# Using PPIO in LobeChat + +{'Using + +[PPIO](https://ppinfra.com?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link) supports stable and cost-efficient open-source LLM APIs, such as DeepSeek, Llama, Qwen etc. + +This document will guide you on how to integrate PPIO in LobeChat: + + + ### Step 1: Register and Log in to PPIO + + - Visit [PPIO](https://ppinfra.com?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link) and create an account + - Upon registration, PPIO will provide a ¥5 credit (about 5M tokens). + + {'Register + + ### Step 2: Obtain the API Key + + - Visit PPIO's [key management page](https://ppinfra.com/settings/key-management), create and copy an API Key. + + {'Obtain + + ### Step 3: Configure PPIO in LobeChat + + - Visit the `Settings` interface in LobeChat + - Find the setting for `PPIO` under `Language Model` + + {'Enter + + - Open PPIO and enter the obtained API key + - Choose a PPIO model for your assistant to start the conversation + + {'Select + + + During usage, you may need to pay the API service provider, please refer to PPIO's [pricing + policy](https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link). + + + +You can now engage in conversations using the models provided by PPIO in LobeChat. diff --git a/docs/usage/providers/ppio.zh-CN.mdx b/docs/usage/providers/ppio.zh-CN.mdx new file mode 100644 index 0000000000000..2613acde909ea --- /dev/null +++ b/docs/usage/providers/ppio.zh-CN.mdx @@ -0,0 +1,55 @@ +--- +title: 在 LobeChat 中使用 PPIO 派欧云 API Key +description: >- + 学习如何将 PPIO 派欧云的 LLM API 集成到 LobeChat 中。跟随以下步骤注册 PPIO 账号、创建 API + Key、并在 LobeChat 中进行设置。 +tags: + - PPIO + - PPInfra + - DeepSeek + - Qwen + - Llama3 + - API key + - Web UI +--- + +# 在 LobeChat 中使用 PPIO 派欧云 + +{'在 + +[PPIO 派欧云](https://ppinfra.com?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link)提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。 + +本文档将指导你如何在 LobeChat 中使用 PPIO: + + + ### 步骤一:注册 PPIO 派欧云账号并登录 + + - 访问 [PPIO 派欧云](https://ppinfra.com?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link) 并注册账号 + - 注册后,PPIO 会赠送 5 元(约 500 万 tokens)的使用额度 + + {'注册 + + ### 步骤二:创建 API 密钥 + + - 访问 PPIO 派欧云的 [密钥管理页面](https://ppinfra.com/settings/key-management) ,创建并且复制一个 API 密钥. + + {'创建 + + ### 步骤三:在 LobeChat 中配置 PPIO 派欧云 + + - 访问 LobeChat 的 `设置` 界面 + - 在 `语言模型` 下找到 `PPIO` 的设置项 + - 打开 PPIO 并填入获得的 API 密钥 + + {'在 + + - 为你的助手选择一个 Novita AI 模型即可开始对话 + + {'选择并使用 + + + 在使用过程中你可能需要向 API 服务提供商付费,PPIO 的 API 费用参考[这里](https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link)。 + + + +至此你已经可以在 LobeChat 中使用 Novita AI 提供的模型进行对话了。 diff --git a/src/config/aiModels/ppio.ts b/src/config/aiModels/ppio.ts index 3fae831596b01..6eca24d8a8f34 100644 --- a/src/config/aiModels/ppio.ts +++ b/src/config/aiModels/ppio.ts @@ -2,9 +2,12 @@ import { AIChatModelCard } from '@/types/aiModel'; const ppioChatModels: AIChatModelCard[] = [ { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", - "displayName": "DeepSeek: DeepSeek R1(Community)", + "displayName": "DeepSeek: DeepSeek R1 (Community)", "enabled": true, "id": "deepseek/deepseek-r1/community", "pricing": { @@ -15,9 +18,12 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", - "displayName": "DeepSeek: DeepSeek V3(Community)\t", + "displayName": "DeepSeek: DeepSeek V3 (Community)", "enabled": true, "id": "deepseek/deepseek-v3/community", "pricing": { @@ -28,6 +34,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", "displayName": "DeepSeek R1", @@ -41,6 +50,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", "displayName": "DeepSeek V3", @@ -54,6 +66,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 32_000, "description": "DeepSeek R1 Distill Llama 70B是基于Llama3.3 70B的大型语言模型,该模型利用DeepSeek R1输出的微调,实现了与大型前沿模型相当的竞争性能。", "displayName": "DeepSeek R1 Distill Llama 70B", @@ -67,6 +82,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek R1 Distill Qwen 32B 是一种基于 Qwen 2.5 32B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 72.6\nMATH-500 pass@1: 94.3\nCodeForces Rating: 1691\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 32B", @@ -80,6 +98,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 64_000, "description": "DeepSeek R1 Distill Qwen 14B 是一种基于 Qwen 2.5 14B 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。该模型在多个基准测试中超越了 OpenAI 的 o1-mini,取得了密集模型(dense models)的最新技术领先成果(state-of-the-art)。以下是一些基准测试的结果:\nAIME 2024 pass@1: 69.7\nMATH-500 pass@1: 93.9\nCodeForces Rating: 1481\n该模型通过从 DeepSeek R1 的输出中进行微调,展现了与更大规模的前沿模型相当的竞争性能。", "displayName": "DeepSeek: DeepSeek R1 Distill Qwen 14B", @@ -93,6 +114,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + reasoning: true, + }, "contextWindowTokens": 32_000, "description": "DeepSeek R1 Distill Llama 8B 是一种基于 Llama-3.1-8B-Instruct 的蒸馏大语言模型,通过使用 DeepSeek R1 的输出进行训练而得。", "displayName": "DeepSeek: DeepSeek R1 Distill Llama 8B", @@ -119,6 +143,9 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { + abilities: { + vision: true, + }, "contextWindowTokens": 32_768, "description": "Qwen2-VL 是 Qwen-VL 模型的最新迭代版本,在视觉理解基准测试中达到了最先进的性能,包括 MathVista、DocVQA、RealWorldQA 和 MTVQA 等。Qwen2-VL 能够理解超过 20 分钟的视频,用于高质量的基于视频的问答、对话和内容创作。它还具备复杂推理和决策能力,可以与移动设备、机器人等集成,基于视觉环境和文本指令进行自动操作。除了英语和中文,Qwen2-VL 现在还支持理解图像中不同语言的文本,包括大多数欧洲语言、日语、韩语、阿拉伯语和越南语等", "displayName": "qwen/qwen-2-vl-72b-instruct", diff --git a/src/config/modelProviders/index.ts b/src/config/modelProviders/index.ts index 2055a20a8f096..819250afa00d3 100644 --- a/src/config/modelProviders/index.ts +++ b/src/config/modelProviders/index.ts @@ -106,6 +106,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [ GoogleProvider, VertexAIProvider, DeepSeekProvider, + PPIOProvider, HuggingFaceProvider, OpenRouterProvider, CloudflareProvider, @@ -143,7 +144,6 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [ TaichuProvider, Ai360Provider, DoubaoProvider, - PPIOProvider, ] as const; export const filterEnabledModels = (provider: ModelProviderCard) => { diff --git a/src/config/modelProviders/ppio.ts b/src/config/modelProviders/ppio.ts index dc0f2300020c6..7318d5587c48b 100644 --- a/src/config/modelProviders/ppio.ts +++ b/src/config/modelProviders/ppio.ts @@ -5,7 +5,7 @@ const PPIO: ModelProviderCard = { { "contextWindowTokens": 64_000, "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", - "displayName": "DeepSeek: DeepSeek R1(Community)", + "displayName": "DeepSeek: DeepSeek R1 (community)", "enabled": true, "id": "deepseek/deepseek-r1/community", "pricing": { @@ -17,7 +17,7 @@ const PPIO: ModelProviderCard = { { "contextWindowTokens": 64_000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", - "displayName": "DeepSeek: DeepSeek V3(Community)\t", + "displayName": "DeepSeek: DeepSeek V3 (community)", "enabled": true, "id": "deepseek/deepseek-v3/community", "pricing": { @@ -231,11 +231,17 @@ const PPIO: ModelProviderCard = { } } ], // Will be updated with model list - disableBrowserRequest: true, + checkModel: 'deepseek/deepseek-r1-distill-qwen-32b', + description: 'PPIO 派欧云提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。', id: 'ppio', modelList: { showModelFetcher: true }, + modelsUrl: 'https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link', name: 'PPIO', - settings: {}, + settings: { + disableBrowserRequest: true, + sdkType: 'openai', + showModelFetcher: true, + }, url: 'https://ppinfra.com/?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link', }; diff --git a/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap b/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap index 40cbd426448a5..792ecfd3dab66 100644 --- a/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap +++ b/src/libs/agent-runtime/ppio/__snapshots__/index.test.ts.snap @@ -5,7 +5,7 @@ exports[`PPIO > models > should get models 1`] = ` { "contextWindowTokens": 64000, "description": "DeepSeek R1是DeepSeek团队发布的最新开源模型,具备非常强悍的推理性能,尤其在数学、编程和推理任务上达到了与OpenAI的o1模型相当的水平。", - "displayName": "DeepSeek: DeepSeek R1(Community)", + "displayName": "DeepSeek: DeepSeek R1 (community)", "enabled": true, "functionCall": false, "id": "deepseek/deepseek-r1/community", @@ -15,7 +15,7 @@ exports[`PPIO > models > should get models 1`] = ` { "contextWindowTokens": 64000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", - "displayName": "DeepSeek: DeepSeek V3(Community)", + "displayName": "DeepSeek: DeepSeek V3 (community)", "enabled": true, "functionCall": false, "id": "deepseek/deepseek-v3/community", diff --git a/src/libs/agent-runtime/ppio/fixtures/models.json b/src/libs/agent-runtime/ppio/fixtures/models.json index 964a70c3620a2..1af96801f7901 100644 --- a/src/libs/agent-runtime/ppio/fixtures/models.json +++ b/src/libs/agent-runtime/ppio/fixtures/models.json @@ -17,7 +17,7 @@ ], "context_size": 64000, "status": 1, - "display_name": "DeepSeek: DeepSeek R1(Community)" + "display_name": "DeepSeek: DeepSeek R1 (community)" }, { "created": 1738928844, @@ -37,6 +37,6 @@ ], "context_size": 64000, "status": 1, - "display_name": "DeepSeek: DeepSeek V3(Community)" + "display_name": "DeepSeek: DeepSeek V3 (community)" } ] \ No newline at end of file diff --git a/src/libs/agent-runtime/ppio/index.ts b/src/libs/agent-runtime/ppio/index.ts index 3e307a13b5929..5a50591d8ceb6 100644 --- a/src/libs/agent-runtime/ppio/index.ts +++ b/src/libs/agent-runtime/ppio/index.ts @@ -25,7 +25,7 @@ export const LobePPIOAI = LobeOpenAICompatibleFactory({ return { contextWindowTokens: model.context_size, description: model.description, - displayName: model.display_name || model.title || model.id, + displayName: model.display_name?.replace("(", " (").replace(")", ")").replace("\t", "") || model.title || model.id, enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false, functionCall: model.description.toLowerCase().includes('function calling'), id: model.id, From c603c10caef7d884da21dfcf793b0f1586a94735 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 15 Feb 2025 17:54:50 +0800 Subject: [PATCH 3/6] fix: fix ppio runtime; fix model configs --- src/config/aiModels/ppio.ts | 6 ---- src/config/modelProviders/ppio.ts | 1 + src/libs/agent-runtime/ppio/index.ts | 49 ++++++++++++++++++---------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/config/aiModels/ppio.ts b/src/config/aiModels/ppio.ts index 6eca24d8a8f34..bd9c914d763cf 100644 --- a/src/config/aiModels/ppio.ts +++ b/src/config/aiModels/ppio.ts @@ -18,9 +18,6 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { - abilities: { - reasoning: true, - }, "contextWindowTokens": 64_000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", "displayName": "DeepSeek: DeepSeek V3 (Community)", @@ -50,9 +47,6 @@ const ppioChatModels: AIChatModelCard[] = [ "type": "chat" }, { - abilities: { - reasoning: true, - }, "contextWindowTokens": 64_000, "description": "DeepSeek-V3在推理速度方面实现了比之前模型的重大突破。在开源模型中排名第一,并可与全球最先进的闭源模型相媲美。DeepSeek-V3 采用了多头潜在注意力 (MLA) 和 DeepSeekMoE 架构,这些架构在 DeepSeek-V2 中得到了全面验证。此外,DeepSeek-V3 开创了一种用于负载均衡的辅助无损策略,并设定了多标记预测训练目标以获得更强的性能。", "displayName": "DeepSeek V3", diff --git a/src/config/modelProviders/ppio.ts b/src/config/modelProviders/ppio.ts index 7318d5587c48b..8159433693451 100644 --- a/src/config/modelProviders/ppio.ts +++ b/src/config/modelProviders/ppio.ts @@ -233,6 +233,7 @@ const PPIO: ModelProviderCard = { ], // Will be updated with model list checkModel: 'deepseek/deepseek-r1-distill-qwen-32b', description: 'PPIO 派欧云提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。', + disableBrowserRequest: true, id: 'ppio', modelList: { showModelFetcher: true }, modelsUrl: 'https://ppinfra.com/llm-api?utm_source=github_lobe-chat&utm_medium=github_readme&utm_campaign=link', diff --git a/src/libs/agent-runtime/ppio/index.ts b/src/libs/agent-runtime/ppio/index.ts index 5a50591d8ceb6..1ff66127d3785 100644 --- a/src/libs/agent-runtime/ppio/index.ts +++ b/src/libs/agent-runtime/ppio/index.ts @@ -2,7 +2,7 @@ import { ModelProvider } from '../types'; import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; import { PPIOModelCard } from './type'; -import { LOBE_DEFAULT_MODEL_LIST } from '@/config/aiModels'; +import type { ChatModelCard } from '@/types/llm'; export const LobePPIOAI = LobeOpenAICompatibleFactory({ baseURL: 'https://api.ppinfra.com/v3/openai', @@ -14,25 +14,38 @@ export const LobePPIOAI = LobeOpenAICompatibleFactory({ debug: { chatCompletion: () => process.env.DEBUG_PPIO_CHAT_COMPLETION === '1', }, - models: { - transformModel: (m) => { - const reasoningKeywords = [ - 'deepseek-r1', - ]; + models: async ({ client }) => { + const { LOBE_DEFAULT_MODEL_LIST } = await import('@/config/aiModels'); - const model = m as unknown as PPIOModelCard; + const reasoningKeywords = [ + 'deepseek-r1', + ]; - return { - contextWindowTokens: model.context_size, - description: model.description, - displayName: model.display_name?.replace("(", " (").replace(")", ")").replace("\t", "") || model.title || model.id, - enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false, - functionCall: model.description.toLowerCase().includes('function calling'), - id: model.id, - reasoning: model.description.toLowerCase().includes('reasoning task') || reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)), - vision: model.description.toLowerCase().includes('视觉'), - }; - }, + const modelsPage = await client.models.list() as any; + const modelList: PPIOModelCard[] = modelsPage.data; + + return modelList + .map((model) => { + const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.toLowerCase() === m.id.toLowerCase()); + + return { + contextWindowTokens: model.context_size, + description: model.description, + displayName: model.display_name?.replace("(", " (").replace(")", ")").replace("\t", "") || model.title || model.id, + enabled: knownModel?.enabled || false, + functionCall: knownModel?.abilities?.functionCall || false, + id: model.id, + reasoning: + reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) + || knownModel?.abilities?.reasoning + || false, + vision: + model.description.toLowerCase().includes('视觉') + || knownModel?.abilities?.vision + || false, + }; + }) + .filter(Boolean) as ChatModelCard[]; }, provider: ModelProvider.PPIO, }); From 8f59f2fed84dc3792a78cf6db649b69c6a3765a9 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 17 Feb 2025 10:55:26 +0800 Subject: [PATCH 4/6] fix: fix default model list --- src/config/modelProviders/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/modelProviders/index.ts b/src/config/modelProviders/index.ts index 819250afa00d3..68a99994e0202 100644 --- a/src/config/modelProviders/index.ts +++ b/src/config/modelProviders/index.ts @@ -93,6 +93,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [ SenseNovaProvider.chatModels, InternLMProvider.chatModels, HigressProvider.chatModels, + PPIOProvider.chatModels, ].flat(); export const DEFAULT_MODEL_PROVIDER_LIST = [ From d3e68321bf7e8d05783d9d064ecadc84565551cd Mon Sep 17 00:00:00 2001 From: arvinxx Date: Mon, 24 Feb 2025 02:26:40 +0800 Subject: [PATCH 5/6] fix --- src/config/modelProviders/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/modelProviders/index.ts b/src/config/modelProviders/index.ts index 68a99994e0202..0c25d0a9981a7 100644 --- a/src/config/modelProviders/index.ts +++ b/src/config/modelProviders/index.ts @@ -145,7 +145,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [ TaichuProvider, Ai360Provider, DoubaoProvider, -] as const; +]; export const filterEnabledModels = (provider: ModelProviderCard) => { return provider.chatModels.filter((v) => v.enabled).map((m) => m.id); From aa4ff2f29d1119bd7ce17107f72e25c05f86f20d Mon Sep 17 00:00:00 2001 From: cnJasonZ Date: Fri, 28 Feb 2025 15:57:27 +0800 Subject: [PATCH 6/6] fix: fix locales providers.json --- locales/zh-CN/providers.json | 1 + 1 file changed, 1 insertion(+) diff --git a/locales/zh-CN/providers.json b/locales/zh-CN/providers.json index 87c288e701a00..d2e744efc8b2e 100644 --- a/locales/zh-CN/providers.json +++ b/locales/zh-CN/providers.json @@ -139,6 +139,7 @@ }, "zhipu": { "description": "智谱 AI 提供多模态与语言模型的开放平台,支持广泛的AI应用场景,包括文本处理、图像理解与编程辅助等。" + }, "ppio": { "description": "PPIO 派欧云提供稳定、高性价比的开源模型 API 服务,支持 DeepSeek 全系列、Llama、Qwen 等行业领先大模型。" }