Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- sync_path_microservice.py +15 -10
sync_path_microservice.py
CHANGED
|
@@ -143,6 +143,10 @@ def classify_ticket_with_gemini(ticket: Ticket):
|
|
| 143 |
# 3. Call Gemini
|
| 144 |
try:
|
| 145 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
response = model.generate_content(
|
| 147 |
prompt,
|
| 148 |
generation_config=genai.GenerationConfig(
|
|
@@ -151,6 +155,10 @@ def classify_ticket_with_gemini(ticket: Ticket):
|
|
| 151 |
)
|
| 152 |
)
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
# 4. Parse the JSON
|
| 155 |
# The response.text *is* the JSON string
|
| 156 |
result_json_str = response.text
|
|
@@ -159,7 +167,11 @@ def classify_ticket_with_gemini(ticket: Ticket):
|
|
| 159 |
# 5. Add to memory *after* a successful classification
|
| 160 |
add_to_memory(ticket.summary, result_json_str)
|
| 161 |
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
except google.api_core.exceptions.NotFound as e:
|
| 165 |
print(f"!!! Model not found error: {e}")
|
|
@@ -172,16 +184,9 @@ def classify_ticket_with_gemini(ticket: Ticket):
|
|
| 172 |
def sync_ticket(ticket: Ticket):
|
| 173 |
print(f"Received sync ticket (GEMINI RAG MODE): {ticket.summary}")
|
| 174 |
|
| 175 |
-
start_time = time.time()
|
| 176 |
-
|
| 177 |
try:
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
processing_time = time.time() - start_time
|
| 181 |
-
|
| 182 |
-
# Add the new fields to the response
|
| 183 |
-
result_data["processing_time"] = processing_time
|
| 184 |
-
result_data["retrieved_context"] = retrieved_context
|
| 185 |
|
| 186 |
return result_data
|
| 187 |
|
|
|
|
| 143 |
# 3. Call Gemini
|
| 144 |
try:
|
| 145 |
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 146 |
+
|
| 147 |
+
# --- TIMER FIX: Start timer *just* before the API call ---
|
| 148 |
+
start_time = time.time()
|
| 149 |
+
|
| 150 |
response = model.generate_content(
|
| 151 |
prompt,
|
| 152 |
generation_config=genai.GenerationConfig(
|
|
|
|
| 155 |
)
|
| 156 |
)
|
| 157 |
|
| 158 |
+
# --- TIMER FIX: End timer *immediately* after the API call ---
|
| 159 |
+
processing_time = time.time() - start_time
|
| 160 |
+
print(f"Gemini API processing time: {processing_time:.2f}s")
|
| 161 |
+
|
| 162 |
# 4. Parse the JSON
|
| 163 |
# The response.text *is* the JSON string
|
| 164 |
result_json_str = response.text
|
|
|
|
| 167 |
# 5. Add to memory *after* a successful classification
|
| 168 |
add_to_memory(ticket.summary, result_json_str)
|
| 169 |
|
| 170 |
+
# Add the *correct* processing time to the result
|
| 171 |
+
result_data["processing_time"] = processing_time
|
| 172 |
+
result_data["retrieved_context"] = context_str
|
| 173 |
+
|
| 174 |
+
return result_data
|
| 175 |
|
| 176 |
except google.api_core.exceptions.NotFound as e:
|
| 177 |
print(f"!!! Model not found error: {e}")
|
|
|
|
| 184 |
def sync_ticket(ticket: Ticket):
|
| 185 |
print(f"Received sync ticket (GEMINI RAG MODE): {ticket.summary}")
|
| 186 |
|
|
|
|
|
|
|
| 187 |
try:
|
| 188 |
+
# The processing time is now correctly calculated *inside* this function
|
| 189 |
+
result_data = classify_ticket_with_gemini(ticket)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
return result_data
|
| 192 |
|