1.LLMChain:一个链
from langchain.chains.llm import LLMChain
from langchain_community.llms.openai import OpenAI
from langchain.prompts.prompt import PromptTemplate
llm = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
promptTemplate = PromptTemplate.from_template("你是起名大师,我家是{sex}宝,姓{firstName},请起3个好养的名字?")
# 多个参数
chain = LLMChain(
llm=llm,
prompt= promptTemplate,
verbose=True,#打开日志
)
ret = chain.invoke({'sex': "男",'firstName': "王"})
print(ret)2.
2.SimpleSequentialChain:将一个链的输出作为下一个链的输入
from langchain.chains.llm import LLMChain
from langchain_community.llms import Tongyi
llm = Tongyi()
from langchain.prompts import ChatPromptTemplate
from langchain.chains.sequential import SimpleSequentialChain
# chain 1
first_prompt = ChatPromptTemplate.from_template("帮我给{product}的公司起一个响亮容易记忆的名字?")