File size: 1,593 Bytes
68a4bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 # Bring in deps
import os
from apikey import apikey

import streamlit as st
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemory
from langchain.utilities import WikipediaAPIWrapper

# Set OpenAI API key
os.environ['OPENAI_API_KEY'] = apikey

# App framework
st.title('Test bot')
prompt = st.text_input('Plug in the topic here')

# Check if there's a prompt
if prompt:
   

    question_template = PromptTemplate(
            input_variables=['topic', 'wikipedia_research','answer'],
            template='create 5 multiple-choice question and answer with the following information: QUESTION: {topic} OPTIONS: {wikipedia_research} ANSWER: {wikipedia_research}'
    )



    # Memory
    
    question_memory = ConversationBufferMemory(input_key='topic', memory_key='chat_history')
    

    # Llms
    llm = OpenAI(temperature=0.9)
  
    question_chain = LLMChain(llm=llm, prompt=question_template, verbose=True, output_key='question', memory=question_memory)
   
    wiki = WikipediaAPIWrapper()

    # Run chains
   
    
    wiki_research = wiki.run(prompt)
    question = question_chain.run(topic=prompt, wikipedia_research=wiki_research)
    

    
    st.write("Question:", question)
  
    


    
    with st.expander('Question history'):
        st.info(question_memory.buffer)

    with st.expander('Wikipedia Research'):
        st.info(wiki_research)
else:
    st.warning("Please enter your topic.")