Alexander Casimir Fischer commited on
Commit
6b7ab17
1 Parent(s): c4c78ac
Files changed (1) hide show
  1. app.py +17 -24
app.py CHANGED
@@ -1,9 +1,9 @@
1
  #importing dependencies
2
  import os
3
- from keys import token
4
 
5
  import streamlit as st
6
- from langchain import HuggingFaceHub
7
  from langchain.prompts import PromptTemplate
8
  from langchain.chains import LLMChain
9
  from langchain.tools import WikipediaQueryRun
@@ -12,8 +12,7 @@ from langchain.utilities import WikipediaAPIWrapper
12
 
13
  wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
14
 
15
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = token
16
- repo_id = "tiiuae/falcon-40b"
17
 
18
  #app framework
19
  st.title("🛕Gurubot AI")
@@ -64,7 +63,7 @@ elif church == "Science":
64
  scripture = "Wikipedia, precisely the explanations you find in {wikipedia_results}"
65
 
66
  context = PromptTemplate(
67
- input_variables = ["persona", "scripture", "prompt"],
68
  template="The user will provide you with an input text \
69
  in form of a question or \
70
  in form of a description of a situation or \
@@ -73,13 +72,13 @@ context = PromptTemplate(
73
  and answer the user's question or give advice to the user. \
74
  Choose your words in accordance to the teachings of {scripture}. \
75
  And please remember, that you are in fact {persona}, so do not talk in third person about {persona}. \
76
- Input text: {prompt}"
77
  )
78
 
79
  find_keyword = PromptTemplate(
80
- input_variables = ['prompt'],
81
  template="The user will provide you with an input text. \
82
- Please return the main keyword of this input text. Input text: {prompt}"
83
  )
84
 
85
  yoda_grammar = PromptTemplate(
@@ -94,30 +93,24 @@ yoda_grammar = PromptTemplate(
94
 
95
 
96
  #llms
97
- #llm = OpenAI(temperature=0.9)
98
- #llm_facts = OpenAI(temperature=0)
99
- llm = HuggingFaceHub(
100
- repo_id=repo_id, model_kwargs={"temperature": 0.9, "max_length": 50}
101
- )
102
- llm_facts = HuggingFaceHub(
103
- repo_id=repo_id, model_kwargs={"temperature": 0.0, "max_length": 50}
104
- )
105
- main_chain = LLMChain(prompt=context, llm=llm)
106
- yoda_grammar_chain = LLMChain(prompt=yoda_grammar, llm=llm_facts)
107
- keyword_chain = LLMChain(prompt=find_keyword, llm=llm_facts)
108
- wiki_chain = LLMChain(prompt=context, llm=llm_facts)
109
 
110
 
111
  #answer on screen if prompt is entered
112
  if prompt:
113
  if church == "Science":
114
- keyword = keyword_chain.run(prompt=prompt)
115
  wikipedia_results = wikipedia.run(keyword)
116
- response = wiki_chain.run(persona=persona, scripture=scripture, prompt=prompt)
117
  elif church == "Jedi":
118
- answer = main_chain.run(persona=persona, scripture=scripture, prompt=prompt)
119
  response = yoda_grammar_chain.run(answer=answer)
120
 
121
  else:
122
- response = main_chain.run(persona=persona, scripture=scripture, prompt=prompt)
123
  st.write(response)
 
1
  #importing dependencies
2
  import os
3
+ from keys import apikey
4
 
5
  import streamlit as st
6
+ from langchain.llms import OpenAI
7
  from langchain.prompts import PromptTemplate
8
  from langchain.chains import LLMChain
9
  from langchain.tools import WikipediaQueryRun
 
12
 
13
  wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
14
 
15
+ os.environ["OPENAI_API_KEY"] = apikey
 
16
 
17
  #app framework
18
  st.title("🛕Gurubot AI")
 
63
  scripture = "Wikipedia, precisely the explanations you find in {wikipedia_results}"
64
 
65
  context = PromptTemplate(
66
+ input_variables = ["persona", "scripture", "topic"],
67
  template="The user will provide you with an input text \
68
  in form of a question or \
69
  in form of a description of a situation or \
 
72
  and answer the user's question or give advice to the user. \
73
  Choose your words in accordance to the teachings of {scripture}. \
74
  And please remember, that you are in fact {persona}, so do not talk in third person about {persona}. \
75
+ Input text: {topic}"
76
  )
77
 
78
  find_keyword = PromptTemplate(
79
+ input_variables = ['topic'],
80
  template="The user will provide you with an input text. \
81
+ Please return the main keyword of this input text. Input text: {topic}"
82
  )
83
 
84
  yoda_grammar = PromptTemplate(
 
93
 
94
 
95
  #llms
96
+ llm = OpenAI(temperature=0.9)
97
+ llm_facts = OpenAI(temperature=0)
98
+ main_chain = LLMChain(llm=llm, prompt=context, verbose=True)
99
+ yoda_grammar_chain = LLMChain(llm=llm_facts, prompt=yoda_grammar)
100
+ keyword_chain = LLMChain(llm=llm_facts, prompt=find_keyword)
101
+ wiki_chain = LLMChain(llm=llm_facts, prompt=context, verbose=True)
 
 
 
 
 
 
102
 
103
 
104
  #answer on screen if prompt is entered
105
  if prompt:
106
  if church == "Science":
107
+ keyword = keyword_chain.run(topic=prompt)
108
  wikipedia_results = wikipedia.run(keyword)
109
+ response = wiki_chain.run(persona=persona, scripture=scripture, topic=prompt)
110
  elif church == "Jedi":
111
+ answer = main_chain.run(persona=persona, scripture=scripture, topic=prompt)
112
  response = yoda_grammar_chain.run(answer=answer)
113
 
114
  else:
115
+ response = main_chain.run(persona=persona, scripture=scripture, topic=prompt)
116
  st.write(response)