AnishaG0201 commited on
Commit
0d09775
1 Parent(s): ca36fca

Update function.py

Browse files
Files changed (1) hide show
  1. function.py +34 -0
function.py CHANGED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import OpenAI
2
+ from langchain_google_genai import ChatGoogleGenerativeAI
3
+
4
+ def GetLLMResponse(selected_topic_level, selected_topic,num_quizzes, model):
5
+ question_prompt = ('I want you to just generate question with this specification: Generate a {selected_topic_level} math quiz on the topic of {selected_topic}. Generate only {num_quizzes} questions not more and without providing answers.')
6
+
7
+
8
+ if model == "Open AI":
9
+ llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
10
+ questions = llm(question_prompt)
11
+ # return questions
12
+
13
+ elif model == "Gemini":
14
+ llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
15
+ questions = llm.invoke(question_prompt)
16
+ # return questions.content
17
+
18
+
19
+ answer_prompt = ( "I want you to become a teacher answer this specific Question:\n {questions}\n\n. You should gave me a straightforward and consise explanation and answer to each one of them")
20
+
21
+
22
+ if model == "Open AI":
23
+ llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"])
24
+ answers = llm(answer_prompt)
25
+ # return questions
26
+
27
+ elif model == "Gemini":
28
+ llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
29
+ answers = llm.invoke(answer_prompt)
30
+ # return questions.content
31
+
32
+
33
+ return(questions,answers)
34
+