-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathopen_api_llm_app.py
More file actions
35 lines (26 loc) · 907 Bytes
/
open_api_llm_app.py
File metadata and controls
35 lines (26 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
from dotenv import find_dotenv, load_dotenv
from langchain import LLMChain, PromptTemplate
from langchain.llms import OpenAI
from loguru import logger
_ = load_dotenv(find_dotenv())
# os.getenv('OPENAI_API_KEY')
class App:
def __init__(self) -> None:
self.template = """Question: {question}
Answer: Let's think step by step."""
self.prompt = PromptTemplate(
template=self.template, input_variables=["question"]
)
self.llm = OpenAI(temperature=0.5)
self.llm_chain = LLMChain(prompt=self.prompt, llm=self.llm)
def __call__(self):
st.write("# Q&A")
question = st.text_input("Ask a question")
if question:
answers = self.llm_chain.run(question)
logger.info(f"Answers: {answers}")
st.write(answers)
if __name__ == "__main__":
app = App()
app()