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 参考并引用
Metadata
Release files for oneapi2langchain 0.0.102
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oneapi2langchain-0.0.102.tar.gz | 31.0 kB | Without provenance | Details for oneapi2langchain-0.0.102.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oneapi2langchain-0.0.102-py3-none-any.whl | Python 3 | none | any | Details for oneapi2langchain-0.0.102-py3-none-any.whl |
Total release size: 80.1 kB
Release files / oneapi2langchain-0.0.102.tar.gz
| Download URL | oneapi2langchain-0.0.102.tar.gz |
|---|---|
| Size | 31.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1db2741618e4b90c2752c9b2d2af503cdd5869a5ad224fffecea4684d9907c15
|
|
BLAKE2b-256 checksum How to use checksums |
c5433b0762674a740c653871a0cfe1a7eaad31819ebf4b0eb316b5e15f0b8c1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / oneapi2langchain-0.0.102-py3-none-any.whl
| Download URL | oneapi2langchain-0.0.102-py3-none-any.whl |
|---|---|
| Size | 49.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f16076c918c6802a5201f91da7caa6cddbcf5fcd2f46bf0488007cb866a3ef1
|
|
BLAKE2b-256 checksum How to use checksums |
f247797cae7d28096643110e6fa0afe55142b36c3b92c925f5d342c33ad69147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for oneapi2langchain 0.0.102
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.