\3c pan>\3c span id="__caret">_\3c pan>\3c !-- #div_digg { float: r" />
 经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » TypeScript » 查看文章
Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
来源:cnblogs  作者:graywen  时间:2025/3/7 9:11:14  对本文有异议

Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库

前言

在 AI 飞速发展的时代,大型语言模型(LLMs)逐渐成为推动技术进步的重要力量。无论是自然语言处理、文本生成,还是智能问答和代码辅助,LLMs 的应用场景正在不断扩展,各种模型层出不穷。然而,面对种类繁多的模型和各自不同的接口标准,开发者在集成和管理这些模型时往往会面临复杂性和兼容性的问题。

Pantheons 的诞生正是为了解决这一痛点。它是一个使用 TypeScript 基于 OpenAI Node.js SDK 构建的统一对话库,旨在为开发者提供一个简洁、高效的接口,方便与多个大型语言模型(LLMs)进行交互。通过 Pantheons,开发者可以轻松集成 OpenAI、DeepSeek、DashScope、Gemini 等主流语言模型,无需担心底层差异,专注于实现自己的业务逻辑。

功能特性

  • 统一接口设计:所有模型基于 OpenAI Node.js SDK 构建;共享相同的调用方式,大幅降低学习成本
  • 类型安全:基于 TypeScript 构建,提供完整的类型定义,让开发更加顺畅
  • 支持多种模型:目前支持十几种主流大语言模型,包括 OpenAI、Azure OpenAI、通义千问、文心一言、腾讯混元、Google Gemini 等,覆盖几乎所有主流云端和本地 LLM 服务。
  • 适配多种运行环境:支持 Node.js, Bun 和 Web 等多种运行时环境,适配性强。

支持的大模型

使用方法

Nodejs

  1. import { DeepSeek } from 'pantheons';
  2. (async () => {
  3. const client = new DeepSeek('Your key');
  4. const stream = await client.stream({
  5. model: 'deepseek-chat',
  6. stream: true,
  7. messages: [{ role: 'user', content: 'Hi!' }],
  8. });
  9. let result = '';
  10. for await (const chunk of stream) {
  11. result += chunk.choices[0].delta?.content;
  12. }
  13. console.log(result);
  14. })();
  15.  

Bun

  1. import { DeepSeek } from '@greywen/pantheons';
  2. const client = new DeepSeek('Your key');
  3. const stream = await client.stream({
  4. model: 'deepseek-chat',
  5. stream: true,
  6. messages: [{ role: 'user', content: 'Hi!' }],
  7. });
  8. let result = '';
  9. for await (const chunk of stream) {
  10. result += chunk.choices[0].delta?.content;
  11. }
  12. console.log(result);
  13.  

多模型

  1. import { DashScope, Moonshot, DeepSeek } from 'pantheons';
  2. const deepSeekClient = new DeepSeek('Your key');
  3. const dashScopeClient = new DashScope('Your key');
  4. const moonshotClient = new Moonshot('Your key');
  5. const messages = [{ role: 'user', content: 'Hi!' }];
  6. const deepSeekStream = await dashScopeClient.stream({
  7. model: 'deepseek-chat',
  8. stream: true,
  9. messages,
  10. });
  11. const dashScopeStream = await dashScopeClient.stream({
  12. model: 'qwen-max',
  13. stream: true,
  14. messages,
  15. });
  16. const moonshotStream = await moonshotClient.stream({
  17. model: 'kimi-latest',
  18. stream: true,
  19. messages,
  20. });
  21. async function readStream(stream: AsyncIterable<any>, output: string[]) {
  22. for await (const chunk of stream) {
  23. const content = chunk.choices[0].delta?.content || '';
  24. output.push(content);
  25. }
  26. }
  27. const deepSeekOutput: string = [];
  28. const dashScopeOutput: string[] = [];
  29. const moonshotOutput: string[] = [];
  30. await Promise.all([
  31. readStream(deepSeekStream, deepSeekOutput),
  32. readStream(dashScopeStream, dashScopeOutput),
  33. readStream(moonshotStream, moonshotOutput),
  34. ]);
  35. console.log(deepSeekOutput, dashScopeOutput, moonshotOutput);
  36.  

私有化部署URL

  1. import { Ollama } from 'pantheons';
  2. client = new Ollama('Your Key', { baseURL: 'Your URL' });
  3. const stream = await client.stream({
  4. model: 'qwen2.5-coder:latest',
  5. stream: true,
  6. messages: [{ role: 'user', content: 'Hi!' }],
  7. });
  8. let actual = '';
  9. for await (const chunk of stream) {
  10. actual += chunk.choices[0].delta?.content;
  11. }
  12. console.log(actual);
  13.  

总结

Pantheons 是一个面向多模型集成工具,借助其统一、高效的接口设计,开发者可以显著减少在多语言模型集成中的开发成本和时间。无论你是希望快速接入一个模型,还是需要在多个模型之间自由切换,Pantheons 都能成为你不可或缺的工具。

未来,Pantheons 将继续扩展更多模型的支持,同时优化性能与易用性,为开发者提供更强大的工具链。如果你正在寻找一个解决多模型集成痛点的方案,不妨试试 Pantheons

欢迎广大开发者 Star 、提交 issue、贡献代码、参与讨论, 感谢!

同时也欢迎大家使用我们已发布的大模型项目 Sdcb Chats 如果您觉得有帮助请在 GitHub 上 Star 我们!您的支持是我们前进的动力。

再次感谢您的支持,期待未来为您带来更多惊喜!

原文链接:https://www.cnblogs.com/greywen/p/18747300

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号