20 lines
563 B
Python
20 lines
563 B
Python
from langchain import LLMChain, PromptTemplate
|
|
from langchain_openai import OpenAI
|
|
|
|
def main():
|
|
template = """
|
|
You are a helpful assistant.
|
|
Question: {question}
|
|
Answer:"""
|
|
prompt = PromptTemplate(template=template, input_variables=["question"])
|
|
llm = OpenAI(api_key="YOUR_API_KEY", temperature=0.7)
|
|
chain = LLMChain(llm=llm, prompt=prompt)
|
|
while True:
|
|
q = input("Ask a question (or 'exit'): ")
|
|
if q.lower() in {"exit", "quit"}:
|
|
break
|
|
print(chain.run({"question": q}))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|