Aswini96 commited on
Commit
61064a9
·
verified ·
1 Parent(s): 9cf8288

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -18
app.py CHANGED
@@ -9,7 +9,27 @@ from IPython.display import display, Markdown
9
  api_key = os.getenv("GEMINI_API_KEY")
10
  genai.configure(api_key = api_key)
11
 
12
- # model = genai.GenerativeModel(model_name='gemini-2.0-flash-exp')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # query = "Tell me about yourself"
14
  # response = model.generate_content(f"""You are an friendly assistant.Answer the following with high precision.{query}""")display(Markdown(response.text))
15
 
@@ -24,16 +44,22 @@ def ask_openai(prompt, secret_word):
24
  system_message = os.getenv("SYSTM_MSG")
25
 
26
  try:
27
- response = client.chat.completions.create(
28
- model="gpt-4o",
29
- messages=[
30
- {"role": "system", "content": system_message},
31
- {"role": "user", "content": prompt}
32
- ],
33
- temperature=0.7,
34
- max_tokens=100,
35
- )
36
- return response.choices[0].message.content
 
 
 
 
 
 
37
  except Exception as e:
38
  return f"Error: {str(e)}"
39
 
@@ -61,13 +87,15 @@ def jailbreak_game(user_prompt, current_level, attempts):
61
  else:
62
  NY_msg = "✨ May 2025 bring you endless joy, success, and fireworks of happiness! Happy New Year! ✨"
63
  try:
64
- response = client.chat.completions.create(
65
- model="gpt-4o",
66
- messages=[{"role": "user", "content": "Generate a unique Happy New year wish. Your response should be only the New Year wish."}],
67
- temperature=0.1,
68
- max_tokens=100,
69
- )
70
- NY_msg = response.choices[0].message.content
 
 
71
  except Exception as e:
72
  NY_msg = f"✨ May 2025 bring you endless joy, success, and fireworks of happiness! Happy New Year! ✨"
73
 
 
9
  api_key = os.getenv("GEMINI_API_KEY")
10
  genai.configure(api_key = api_key)
11
 
12
+ chat_model = genai.GenerativeModel(model_name='gemini-2.0-flash-exp')
13
+ generationConfig = {temperature: 0.7, topK: 1, topP: 1, maxOutputTokens: 1024,};
14
+ safetySettings = [
15
+ {
16
+ category: HarmCategory.HARM_CATEGORY_HARASSMENT,
17
+ threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
18
+ },
19
+ {
20
+ category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
21
+ threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
22
+ },
23
+ {
24
+ category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
25
+ threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
26
+ },
27
+ {
28
+ category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
29
+ threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
30
+ },
31
+ ]
32
+
33
  # query = "Tell me about yourself"
34
  # response = model.generate_content(f"""You are an friendly assistant.Answer the following with high precision.{query}""")display(Markdown(response.text))
35
 
 
44
  system_message = os.getenv("SYSTM_MSG")
45
 
46
  try:
47
+ chat = model.start_chat(generationConfig, safetySettings,
48
+ history=[{"role": "system", "content": system_message}, {"role": "user", "content": prompt},])
49
+
50
+ print(repsonse)
51
+ return response.text
52
+
53
+ # response = client.chat.completions.create(
54
+ # model="gpt-4o",
55
+ # messages=[
56
+ # {"role": "system", "content": system_message},
57
+ # {"role": "user", "content": prompt}
58
+ # ],
59
+ # temperature=0.7,
60
+ # max_tokens=100,
61
+ # )
62
+ # return response.choices[0].message.content
63
  except Exception as e:
64
  return f"Error: {str(e)}"
65
 
 
87
  else:
88
  NY_msg = "✨ May 2025 bring you endless joy, success, and fireworks of happiness! Happy New Year! ✨"
89
  try:
90
+ chat = model.start_chat(generationConfig, safetySettings,
91
+ history=[{"role": "user", "content": "Generate a unique Happy New year wish. Your response should be only the New Year wish."},])
92
+ # response = client.chat.completions.create(
93
+ # model="gpt-4o",
94
+ # messages=[{"role": "user", "content": "Generate a unique Happy New year wish. Your response should be only the New Year wish."}],
95
+ # temperature=0.1,
96
+ # max_tokens=100,
97
+ # )
98
+ NY_msg = response.text #response.choices[0].message.content
99
  except Exception as e:
100
  NY_msg = f"✨ May 2025 bring you endless joy, success, and fireworks of happiness! Happy New Year! ✨"
101