Skip to main content
Open In ColabOpen on GitHub

MosaicML

MosaicML 提供托管推理服务。你可以使用各种开源模型,也可以部署自己的模型。

本示例将介绍如何使用 LangChain 与 MosaicML Inference 交互以完成文本。

# 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
from langchain.chains import LLMChain
from langchain_community.llms import MosaicML
from langchain_core.prompts import PromptTemplate
API Reference:LLMChain | MosaicML | 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)