Skip to main content

langchain实现的闭源模型统一API

Project description

LangChain 实现闭源大模型的统一

本项目的目的是将闭源大模型,如科大星火 文心一言 通义千问等闭源大模型进行Langchain的实现,即继承了langchain的BaseChatModel的实现。

(仓库初步构建,欢迎贡献源码。)

背景

随着AIGC的快速发展,市面上出现了越来越多的大模型,其中包括开源大模型如qwen,baichuan,chatglm等,开源的模型已经有很好社区来支持openai格式的API接口,之所以使用openai格式的API接口,很重要的一个因素是可以轻松的使用langchain(目前最流行)。但是闭源大模型由于接口不统一,导致很难使用langchain提供的生态,因为我才有想法构建本项目。

支持的闭源模型

  • 讯飞星火
  • 文心一言
  • 通义千问
  • 百川

安装

pip install --upgrade langchain_api

示例代码

from langchain_api import ChatSpark
from dotenv import load_dotenv  # 加载 APP_ID 等配置
load_dotenv()

if __name__ == "__main__":
  
    llm = ChatSpark()
    # # 测试 string  ok
    ret = llm.predict("你是谁",stop=['科大讯飞'])
    print(ret)
    # 测试 message  ok
    # ret = llm.predict_messages([ChatMessage(role="user",content="你是谁")])
    # print(ret)
    # 测试 invoke  ok
    # ret = llm.invoke("你是谁")
    # print(ret)
    # 测试流式
    # for i in llm.stream("你是谁"):
    #     print(i)

致谢

spark-ai-python 参考并引用

langchain 参考并引用

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

oneapi2langchain-0.0.1-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file oneapi2langchain-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: oneapi2langchain-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 48.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for oneapi2langchain-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91fd24f273b7c688ed9c6c3cb09fd997a090be4176fe2c08d0bdef0d0033ec52
MD5 7588649c7a8958f23b657441ea4e63af
BLAKE2b-256 3363ceac983ffd5f19e8a1ef4431ff2708e49f24f7a7f832ed084453e500ac88

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page