MosaicML
MosaicML 提供了一个托管的推理服务。您可以使用各种开源模型,或部署您自己的模型。
本示例介绍了如何使用 LangChain 与 MosaicML 推理进行文本补全。
# sign up for an account: https://forms.mosaicml.com/demo?utm_source=langchain
from getpass import getpass
MOSAICML_API_TOKEN = getpass()
import os
os.environ["MOSAICML_API_TOKEN"] = MOSAICML_API_TOKEN
<!--IMPORTS:[{"imported": "LLMChain", "source": "langchain.chains", "docs": "https://python.langchain.com/api_reference/langchain/chains/langchain.chains.llm.LLMChain.html", "title": "MosaicML"}, {"imported": "MosaicML", "source": "langchain_community.llms", "docs": "https://python.langchain.com/api_reference/community/llms/langchain_community.llms.mosaicml.MosaicML.html", "title": "MosaicML"}, {"imported": "PromptTemplate", "source": "langchain_core.prompts", "docs": "https://python.langchain.com/api_reference/core/prompts/langchain_core.prompts.prompt.PromptTemplate.html", "title": "MosaicML"}]-->
from langchain.chains import LLMChain
from langchain_community.llms import MosaicML
from langchain_core.prompts import PromptTemplate
template = """Question: {question}"""
prompt = PromptTemplate.from_template(template)
llm = MosaicML(inject_instruction_format=True, model_kwargs={"max_new_tokens": 128})
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What is one good reason why you should train a large language model on domain specific data?"
llm_chain.run(question)