Commit ·
52ee99e
1
Parent(s): 1de837f
Adding Google Gemini 2.5 flash lite
Browse files- Config_files/message_system_config.json +3 -2
- Messaging_system/LLM.py +43 -1
- Messaging_system/PromptEng.py +36 -1
- messaging_main_test.py +1 -1
Config_files/message_system_config.json
CHANGED
|
@@ -21,12 +21,13 @@
|
|
| 21 |
"AI_phrases_singeo": ["your voice deserves more"],
|
| 22 |
"header_limit": 30,
|
| 23 |
"message_limit": 110,
|
| 24 |
-
"LLM_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-mini", "gpt-3.5-turbo", "o4-mini", "o1-mini", "o3-mini", "claude-3-5-haiku-latest", "google/gemma-3-27b-instruct/bf-16", "meta-llama/llama-3.2-11b-instruct/fp-16"],
|
| 25 |
"openai_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-nano", "gpt-3.5-turbo", "gpt-4.1-mini"],
|
| 26 |
"reasoning": ["o1", "o4-mini", "o1-mini", "o3-mini"],
|
| 27 |
"ollama_models": ["deepseek-r1:1.5b", "gemma3:4b", "deepseek-r1:7b", "gemma3:4b"],
|
| 28 |
"claude_models": ["claude-3-5-haiku-latest"],
|
| 29 |
-
"inference_models": ["google/gemma-3-27b-instruct/bf-16", "meta-llama/llama-3.2-11b-instruct/fp-16"]
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
|
|
|
|
| 21 |
"AI_phrases_singeo": ["your voice deserves more"],
|
| 22 |
"header_limit": 30,
|
| 23 |
"message_limit": 110,
|
| 24 |
+
"LLM_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-mini", "gpt-3.5-turbo", "o4-mini", "o1-mini", "o3-mini", "claude-3-5-haiku-latest", "google/gemma-3-27b-instruct/bf-16", "meta-llama/llama-3.2-11b-instruct/fp-16", "gemini-2.5-flash-lite-preview-06-17"],
|
| 25 |
"openai_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-nano", "gpt-3.5-turbo", "gpt-4.1-mini"],
|
| 26 |
"reasoning": ["o1", "o4-mini", "o1-mini", "o3-mini"],
|
| 27 |
"ollama_models": ["deepseek-r1:1.5b", "gemma3:4b", "deepseek-r1:7b", "gemma3:4b"],
|
| 28 |
"claude_models": ["claude-3-5-haiku-latest"],
|
| 29 |
+
"inference_models": ["google/gemma-3-27b-instruct/bf-16", "meta-llama/llama-3.2-11b-instruct/fp-16"],
|
| 30 |
+
"google_models": ["gemini-2.5-flash-lite-preview-06-17"]
|
| 31 |
}
|
| 32 |
|
| 33 |
|
Messaging_system/LLM.py
CHANGED
|
@@ -12,6 +12,8 @@ import re
|
|
| 12 |
import anthropic
|
| 13 |
import os
|
| 14 |
import streamlit as st
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
|
|
@@ -35,6 +37,8 @@ class LLM:
|
|
| 35 |
response = self.get_message_inference(prompt, instructions)
|
| 36 |
elif self.model_type == "claude":
|
| 37 |
response = self.get_message_claude(prompt, instructions)
|
|
|
|
|
|
|
| 38 |
else:
|
| 39 |
raise f"Invalid model type : {self.model_type}"
|
| 40 |
|
|
@@ -49,9 +53,11 @@ class LLM:
|
|
| 49 |
if self.Core.model in self.Core.config_file["openai_models"]:
|
| 50 |
self.model_type = "openai"
|
| 51 |
|
| 52 |
-
|
| 53 |
self.model_type = "inference"
|
| 54 |
|
|
|
|
|
|
|
| 55 |
|
| 56 |
elif self.Core.model in self.Core.config_file["ollama_models"]:
|
| 57 |
self.model_type = "ollama"
|
|
@@ -149,6 +155,42 @@ class LLM:
|
|
| 149 |
print("Max retries exceeded. Returning empty response.")
|
| 150 |
return None
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# =========================================================================
|
| 153 |
|
| 154 |
def get_message_openai(self, prompt, instructions, max_retries=4):
|
|
|
|
| 12 |
import anthropic
|
| 13 |
import os
|
| 14 |
import streamlit as st
|
| 15 |
+
from google.genai import types
|
| 16 |
+
from google import genai
|
| 17 |
|
| 18 |
|
| 19 |
|
|
|
|
| 37 |
response = self.get_message_inference(prompt, instructions)
|
| 38 |
elif self.model_type == "claude":
|
| 39 |
response = self.get_message_claude(prompt, instructions)
|
| 40 |
+
elif self.model_type == "google":
|
| 41 |
+
response = self.get_message_google(prompt, instructions)
|
| 42 |
else:
|
| 43 |
raise f"Invalid model type : {self.model_type}"
|
| 44 |
|
|
|
|
| 53 |
if self.Core.model in self.Core.config_file["openai_models"]:
|
| 54 |
self.model_type = "openai"
|
| 55 |
|
| 56 |
+
elif self.Core.model in self.Core.config_file["inference_models"]:
|
| 57 |
self.model_type = "inference"
|
| 58 |
|
| 59 |
+
elif self.Core.model in self.Core.config_file["google_models"]:
|
| 60 |
+
self.model_type = "google"
|
| 61 |
|
| 62 |
elif self.Core.model in self.Core.config_file["ollama_models"]:
|
| 63 |
self.model_type = "ollama"
|
|
|
|
| 155 |
print("Max retries exceeded. Returning empty response.")
|
| 156 |
return None
|
| 157 |
|
| 158 |
+
# =========================================================================
|
| 159 |
+
def get_message_google(self, prompt, instructions, max_retries=4):
|
| 160 |
+
|
| 161 |
+
client = genai.Client(api_key=self.get_credential("Google_API"))
|
| 162 |
+
|
| 163 |
+
for attempt in range(max_retries):
|
| 164 |
+
try:
|
| 165 |
+
response = client.models.generate_content(
|
| 166 |
+
model=self.Core.model,
|
| 167 |
+
contents=prompt,
|
| 168 |
+
config=types.GenerateContentConfig(
|
| 169 |
+
thinking_config=types.ThinkingConfig(thinking_budget=0),
|
| 170 |
+
system_instruction=instructions,
|
| 171 |
+
temperature=self.Core.temperature,
|
| 172 |
+
response_mime_type="application/json"
|
| 173 |
+
))
|
| 174 |
+
|
| 175 |
+
output = json.loads(str(response.text))
|
| 176 |
+
|
| 177 |
+
if 'message' not in output or 'header' not in output:
|
| 178 |
+
print(f"'message' or 'header' is missing in response on attempt {attempt + 1}. Retrying...")
|
| 179 |
+
continue # Continue to next attempt
|
| 180 |
+
|
| 181 |
+
else:
|
| 182 |
+
if len(output["header"].strip()) > self.Core.config_file["header_limit"] or len(
|
| 183 |
+
output["message"].strip()) > self.Core.config_file["message_limit"]:
|
| 184 |
+
print(
|
| 185 |
+
f"'header' or 'message' is more than specified characters in response on attempt {attempt + 1}. Retrying...")
|
| 186 |
+
continue
|
| 187 |
+
return output
|
| 188 |
+
|
| 189 |
+
except json.JSONDecodeError:
|
| 190 |
+
print(f"Invalid JSON from LLM on attempt {attempt + 1}. Retrying...")
|
| 191 |
+
except Exception as e:
|
| 192 |
+
print(f"Error in attempt {attempt}: {e}")
|
| 193 |
+
|
| 194 |
# =========================================================================
|
| 195 |
|
| 196 |
def get_message_openai(self, prompt, instructions, max_retries=4):
|
Messaging_system/PromptEng.py
CHANGED
|
@@ -7,6 +7,8 @@ from openai import OpenAI
|
|
| 7 |
from Messaging_system.LLM import LLM
|
| 8 |
import os
|
| 9 |
import streamlit as st
|
|
|
|
|
|
|
| 10 |
|
| 11 |
class PromptEngine:
|
| 12 |
|
|
@@ -52,7 +54,7 @@ output the new prompt as text without any additional information.
|
|
| 52 |
final_prompt = self.get_openai_response(prompt)
|
| 53 |
return final_prompt
|
| 54 |
|
| 55 |
-
|
| 56 |
final_prompt = self.get_inference_response(prompt)
|
| 57 |
return final_prompt
|
| 58 |
|
|
@@ -60,6 +62,10 @@ output the new prompt as text without any additional information.
|
|
| 60 |
final_prompt = self.get_claude_response(prompt, self.llm_instructions())
|
| 61 |
return final_prompt
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# ============================================================
|
| 64 |
def llm_instructions(self):
|
| 65 |
|
|
@@ -199,6 +205,34 @@ output the new prompt as text without any additional information.
|
|
| 199 |
return prompt # returns original prompt if needed
|
| 200 |
|
| 201 |
# ==========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
|
| 204 |
def get_claude_response(self, prompt, instructions, max_retries=4):
|
|
@@ -231,3 +265,4 @@ output the new prompt as text without any additional information.
|
|
| 231 |
print("Max retries exceeded. Returning empty response.")
|
| 232 |
return prompt # returns original prompt if needed
|
| 233 |
|
|
|
|
|
|
| 7 |
from Messaging_system.LLM import LLM
|
| 8 |
import os
|
| 9 |
import streamlit as st
|
| 10 |
+
from google.genai import types
|
| 11 |
+
from google import genai
|
| 12 |
|
| 13 |
class PromptEngine:
|
| 14 |
|
|
|
|
| 54 |
final_prompt = self.get_openai_response(prompt)
|
| 55 |
return final_prompt
|
| 56 |
|
| 57 |
+
elif self.Core.model in self.Core.config_file["inference_models"]:
|
| 58 |
final_prompt = self.get_inference_response(prompt)
|
| 59 |
return final_prompt
|
| 60 |
|
|
|
|
| 62 |
final_prompt = self.get_claude_response(prompt, self.llm_instructions())
|
| 63 |
return final_prompt
|
| 64 |
|
| 65 |
+
elif self.Core.model in self.Core.config_file["google_models"]:
|
| 66 |
+
final_prompt = self.get_gemini_response(prompt)
|
| 67 |
+
return final_prompt
|
| 68 |
+
|
| 69 |
# ============================================================
|
| 70 |
def llm_instructions(self):
|
| 71 |
|
|
|
|
| 205 |
return prompt # returns original prompt if needed
|
| 206 |
|
| 207 |
# ==========================================================================
|
| 208 |
+
def get_gemini_response(self, prompt, max_retries=4):
|
| 209 |
+
"""
|
| 210 |
+
Send prompt to Google Gemini LLM and get back the response
|
| 211 |
+
:param prompt:
|
| 212 |
+
:param max_retries:
|
| 213 |
+
:return:
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
client = genai.Client(api_key=self.get_credential("Google_API"))
|
| 217 |
+
|
| 218 |
+
for attempt in range(max_retries):
|
| 219 |
+
try:
|
| 220 |
+
response = client.models.generate_content(
|
| 221 |
+
model=self.Core.model,
|
| 222 |
+
contents=prompt,
|
| 223 |
+
config=types.GenerateContentConfig(
|
| 224 |
+
thinking_config=types.ThinkingConfig(thinking_budget=0),
|
| 225 |
+
system_instruction=self.llm_instructions(),
|
| 226 |
+
temperature=self.Core.temperature,
|
| 227 |
+
response_mime_type = "text/plain" # application/json
|
| 228 |
+
))
|
| 229 |
+
|
| 230 |
+
output = str(response.text)
|
| 231 |
+
return output
|
| 232 |
+
except Exception as e:
|
| 233 |
+
print(f"Error in attempt {attempt}: {e}")
|
| 234 |
+
|
| 235 |
+
# ==========================================================================
|
| 236 |
|
| 237 |
|
| 238 |
def get_claude_response(self, prompt, instructions, max_retries=4):
|
|
|
|
| 265 |
print("Max retries exceeded. Returning empty response.")
|
| 266 |
return prompt # returns original prompt if needed
|
| 267 |
|
| 268 |
+
|
messaging_main_test.py
CHANGED
|
@@ -163,7 +163,7 @@ if __name__ == "__main__":
|
|
| 163 |
# o3-mini o1-mini o4-mini o1
|
| 164 |
|
| 165 |
users_message = permes.create_personalize_messages(session=session,
|
| 166 |
-
model="
|
| 167 |
users=users,
|
| 168 |
brand=brand,
|
| 169 |
config_file=config_file,
|
|
|
|
| 163 |
# o3-mini o1-mini o4-mini o1
|
| 164 |
|
| 165 |
users_message = permes.create_personalize_messages(session=session,
|
| 166 |
+
model="gemini-2.5-flash-lite-preview-06-17",
|
| 167 |
users=users,
|
| 168 |
brand=brand,
|
| 169 |
config_file=config_file,
|