langchain-ChatGLM
esay use ChatGLM in LangChain.
Install Requirement
pip install -r requirements.txt
Usage
from chatglm_pipline import ChatGLMPipeline
from langchain import PromptTemplate, LLMChain
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = ChatGLMPipeline.from_model_id(
model_id="THUDM/chatglm2-6b",
device=-1, # if use GPU set to 0
model_kwargs={"temperature": 0, "max_length": 64, "trust_remote_code": True},
callback_manager=callback_manager,
verbose=True,
)
template = """问: {question}
答: 让我们一步一步地思考."""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "华晨宇和张碧晨是什么关系?"
llm_chain.run(question)
model_kwargs
| key | values | remark |
|---|---|---|
"device" |
"cuda" |
使用cuda加速 |
"float" |
True, False |
使用cpu推理 |
"quantize" |
8 |
量化 |
Metadata
Release files for langchain-chatglm 0.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain-chatglm-0.0.13.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_chatglm-0.0.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / langchain-chatglm-0.0.13.tar.gz
| Download URL | langchain-chatglm-0.0.13.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
890ebdae1d5f98d5c4478765fbe1c3d8c02abbb8546162e4511ac5d457c9064e
|
|
BLAKE2b-256 checksum How to use checksums |
020ea86cef71c38d8c3db7eeb1dbc4c895a664cf2d8af5146b16e20b3adc1a8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Release files / langchain_chatglm-0.0.13-py3-none-any.whl
| Download URL | langchain_chatglm-0.0.13-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1689048395f86244e69d0610009e0c018295aa6a88fb3b6798a7c585dff93a1d
|
|
BLAKE2b-256 checksum How to use checksums |
95ade4a49844bf90b91e68e5f87975cd7de77718aea9c63720358a88dc089e9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|