Aswini96 commited on
Commit
65e9196
·
verified ·
1 Parent(s): c44b809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -6,27 +6,28 @@ import google.generativeai as genai
6
  # Set your GEMINI API key
7
  api_key = os.getenv("GEMINI_API_KEY")
8
  genai.configure(api_key = api_key)
 
9
 
10
- chat_model = genai.GenerativeModel(model_name='gemini-2.0-flash-exp')
11
- generationConfig = {temperature: 0.7, topK: 1, topP: 1, maxOutputTokens: 1024,};
12
- safetySettings = [
13
- {
14
- category: HarmCategory.HARM_CATEGORY_HARASSMENT,
15
- threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
16
- },
17
- {
18
- category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
19
- threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
20
- },
21
- {
22
- category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
23
- threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
24
- },
25
- {
26
- category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
27
- threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
28
- },
29
- ]
30
 
31
  # query = "Tell me about yourself"
32
  # response = model.generate_content(f"""You are an friendly assistant.Answer the following with high precision.{query}""")display(Markdown(response.text))
@@ -38,13 +39,10 @@ new_year_levels = [os.getenv("First_Word"), os.getenv("Second_Word"), os.getenv(
38
  def ask_openai(prompt, secret_word):
39
  """
40
  Sends the user prompt and safeguards to the OpenAI API to generate a response.
41
- """
42
- system_message = os.getenv("SYSTM_MSG")
43
-
44
  try:
45
- chat = model.start_chat(generationConfig, safetySettings,
46
- history=[{"role": "system", "content": system_message}, {"role": "user", "content": prompt},])
47
-
48
  print(repsonse)
49
  return response.text
50
 
 
6
  # Set your GEMINI API key
7
  api_key = os.getenv("GEMINI_API_KEY")
8
  genai.configure(api_key = api_key)
9
+ system_message = os.getenv("SYSTM_MSG")
10
 
11
+ model = genai.GenerativeModel(model_name="gemini-1.5-flash", system_instruction = system_message)
12
+ # generationConfig = GenerationConfig(max_output_tokens=2048, temperature=0.7, top_p=1, top_k=32)
13
+ # safetySettings = [
14
+ # {
15
+ # category: HarmCategory.HARM_CATEGORY_HARASSMENT,
16
+ # threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
17
+ # },
18
+ # {
19
+ # category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
20
+ # threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
21
+ # },
22
+ # {
23
+ # category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
24
+ # threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
25
+ # },
26
+ # {
27
+ # category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
28
+ # threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
29
+ # },
30
+ # ]
31
 
32
  # query = "Tell me about yourself"
33
  # response = model.generate_content(f"""You are an friendly assistant.Answer the following with high precision.{query}""")display(Markdown(response.text))
 
39
  def ask_openai(prompt, secret_word):
40
  """
41
  Sends the user prompt and safeguards to the OpenAI API to generate a response.
42
+ """
 
 
43
  try:
44
+ # chat = model.start_chat(history=[{"role": "user", "content": prompt},])
45
+ response = model.generate_content(prompt)
 
46
  print(repsonse)
47
  return response.text
48