langchain实现的闭源模型统一API
Project description
LangChain 实现闭源大模型的统一
本项目的目的是将闭源大模型,如科大星火 文心一言 通义千问等闭源大模型进行Langchain的实现,即继承了langchain的BaseChatModel的实现。
(仓库初步构建,欢迎贡献源码。)
背景
随着AIGC的快速发展,市面上出现了越来越多的大模型,其中包括开源大模型如qwen,baichuan,chatglm等,开源的模型已经有很好社区来支持openai格式的API接口,之所以使用openai格式的API接口,很重要的一个因素是可以轻松的使用langchain(目前最流行)。但是闭源大模型由于接口不统一,导致很难使用langchain提供的生态,因为我才有想法构建本项目。
支持的闭源模型
- 讯飞星火
- 文心一言
- 通义千问
- 百川
安装(要用官方源,国内源可能同步更新不及时)
pip install oneapi2langchain -i https://pypi.org/simple/
示例代码
from oneapi2langchain import ChatSpark # 完全支持langchain
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oneapi2langchain-0.0.102.tar.gz.
File metadata
- Download URL: oneapi2langchain-0.0.102.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1db2741618e4b90c2752c9b2d2af503cdd5869a5ad224fffecea4684d9907c15
|
|
| MD5 |
8bdb689edb11a4e998ae0717b06d891f
|
|
| BLAKE2b-256 |
c5433b0762674a740c653871a0cfe1a7eaad31819ebf4b0eb316b5e15f0b8c1c
|
File details
Details for the file oneapi2langchain-0.0.102-py3-none-any.whl.
File metadata
- Download URL: oneapi2langchain-0.0.102-py3-none-any.whl
- Upload date:
- Size: 49.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f16076c918c6802a5201f91da7caa6cddbcf5fcd2f46bf0488007cb866a3ef1
|
|
| MD5 |
1015c666487121ae919642f592f4e722
|
|
| BLAKE2b-256 |
f247797cae7d28096643110e6fa0afe55142b36c3b92c925f5d342c33ad69147
|