Skip to main content
本页介绍如何在 LangChain 中使用 C Transformers 库。 分为两部分:安装与设置,以及特定 C Transformers 封装的参考。

安装与设置

封装

LLM

有一个 CTransformers LLM 封装,可以通过以下方式访问:
from langchain_community.llms import CTransformers
它为所有模型提供了统一的接口:
llm = CTransformers(model='/path/to/ggml-gpt-2.bin', model_type='gpt2')

print(llm.invoke('AI is going to'))
如果遇到 illegal instruction 错误,请尝试使用 lib='avx'lib='basic'
llm = CTransformers(model='/path/to/ggml-gpt-2.bin', model_type='gpt2', lib='avx')
可以与 Hugging Face Hub 上托管的模型一起使用:
llm = CTransformers(model='marella/gpt-2-ggml')
如果模型仓库有多个模型文件(.bin 文件),请使用以下方式指定模型文件:
llm = CTransformers(model='marella/gpt-2-ggml', model_file='ggml-model.bin')
可以使用 config 参数传递额外参数:
config = {'max_new_tokens': 256, 'repetition_penalty': 1.1}

llm = CTransformers(model='marella/gpt-2-ggml', config=config)
可用参数列表请参阅文档 更详细的介绍请参阅此笔记本