test_01.py 582 字节
Newer Older
1 2 3 4
import os
from langchain import PromptTemplate, OpenAI, LLMChain
import chainlit as cl

5 6 7
os.environ["http_proxy"] = "http://localhost:7890"
os.environ["https_proxy"] = "http://localhost:7890"
os.environ["OPENAI_API_KEY"] = "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"
8 9 10 11 12 13 14 15 16
template = """Question: {question}
Answer: Let's think step by step."""


@cl.langchain_factory(use_async=True)
def factory():
    prompt = PromptTemplate(template=template, input_variables=["question"])
    llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0), verbose=True)
    return llm_chain