AI Agent commited on
Commit ·
0d4a982
1
Parent(s): d6bc7f9
Fix keyring module not found and add model name to metrics
Browse files- agents/crew.py +2 -0
- agents/llm.py +1 -0
- requirements.txt +1 -0
- requirements_hf.txt +1 -0
- templates/index.html +1 -0
agents/crew.py
CHANGED
|
@@ -347,12 +347,14 @@ def run_query_crew(query: str, top_k: int = None, max_tokens: int = None, use_ve
|
|
| 347 |
# Track token usage from LocalLLM's last call (stored internally)
|
| 348 |
total_prompt_tokens += getattr(llm, "_last_prompt_tokens", 0)
|
| 349 |
total_completion_tokens += getattr(llm, "_last_completion_tokens", 0)
|
|
|
|
| 350 |
|
| 351 |
end_time = time.time()
|
| 352 |
total_tokens = total_prompt_tokens + total_completion_tokens
|
| 353 |
carbon_kg = (total_tokens / 1000) * 0.0003
|
| 354 |
|
| 355 |
metrics = {
|
|
|
|
| 356 |
"tokens_in": total_prompt_tokens,
|
| 357 |
"tokens_out": total_completion_tokens,
|
| 358 |
"time_seconds": end_time - start_time,
|
|
|
|
| 347 |
# Track token usage from LocalLLM's last call (stored internally)
|
| 348 |
total_prompt_tokens += getattr(llm, "_last_prompt_tokens", 0)
|
| 349 |
total_completion_tokens += getattr(llm, "_last_completion_tokens", 0)
|
| 350 |
+
model_used = getattr(llm, "_last_model_name", "unknown")
|
| 351 |
|
| 352 |
end_time = time.time()
|
| 353 |
total_tokens = total_prompt_tokens + total_completion_tokens
|
| 354 |
carbon_kg = (total_tokens / 1000) * 0.0003
|
| 355 |
|
| 356 |
metrics = {
|
| 357 |
+
"model_name": model_used,
|
| 358 |
"tokens_in": total_prompt_tokens,
|
| 359 |
"tokens_out": total_completion_tokens,
|
| 360 |
"time_seconds": end_time - start_time,
|
agents/llm.py
CHANGED
|
@@ -62,6 +62,7 @@ class LocalLLM(BaseLLM):
|
|
| 62 |
# Store token counts so callers can read them without CrewAI usage_metrics
|
| 63 |
self._last_prompt_tokens = usage.get("prompt_tokens", 0)
|
| 64 |
self._last_completion_tokens = usage.get("completion_tokens", 0)
|
|
|
|
| 65 |
if usage:
|
| 66 |
self._track_token_usage_internal(usage)
|
| 67 |
return data["choices"][0]["text"].strip()
|
|
|
|
| 62 |
# Store token counts so callers can read them without CrewAI usage_metrics
|
| 63 |
self._last_prompt_tokens = usage.get("prompt_tokens", 0)
|
| 64 |
self._last_completion_tokens = usage.get("completion_tokens", 0)
|
| 65 |
+
self._last_model_name = data.get("model", self.model)
|
| 66 |
if usage:
|
| 67 |
self._track_token_usage_internal(usage)
|
| 68 |
return data["choices"][0]["text"].strip()
|
requirements.txt
CHANGED
|
@@ -60,3 +60,4 @@ rank_bm25
|
|
| 60 |
spacy>=3.7.0
|
| 61 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl
|
| 62 |
Flask-Limiter>=3.0.0
|
|
|
|
|
|
| 60 |
spacy>=3.7.0
|
| 61 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl
|
| 62 |
Flask-Limiter>=3.0.0
|
| 63 |
+
keyring>=24.0.0
|
requirements_hf.txt
CHANGED
|
@@ -59,3 +59,4 @@ rank_bm25
|
|
| 59 |
spacy>=3.7.0
|
| 60 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl
|
| 61 |
Flask-Limiter>=3.0.0
|
|
|
|
|
|
| 59 |
spacy>=3.7.0
|
| 60 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl
|
| 61 |
Flask-Limiter>=3.0.0
|
| 62 |
+
keyring>=24.0.0
|
templates/index.html
CHANGED
|
@@ -740,6 +740,7 @@
|
|
| 740 |
diag.info(`Generation metrics:`, data.metrics);
|
| 741 |
const metricsHtml = `
|
| 742 |
<div style="font-size: 0.85rem; color: #666; margin-top: 15px; border-top: 1px dashed var(--border-color); padding-top: 10px;">
|
|
|
|
| 743 |
Analysis took ${data.metrics.time_seconds?.toFixed(1) || '?'} seconds.
|
| 744 |
Tokens: ${data.metrics.tokens_in || '?'} in, ${data.metrics.tokens_out || '?'} out.
|
| 745 |
</div>
|
|
|
|
| 740 |
diag.info(`Generation metrics:`, data.metrics);
|
| 741 |
const metricsHtml = `
|
| 742 |
<div style="font-size: 0.85rem; color: #666; margin-top: 15px; border-top: 1px dashed var(--border-color); padding-top: 10px;">
|
| 743 |
+
<span style="font-weight: bold; margin-right: 10px;">${data.metrics.model_name || 'LLM'}</span>
|
| 744 |
Analysis took ${data.metrics.time_seconds?.toFixed(1) || '?'} seconds.
|
| 745 |
Tokens: ${data.metrics.tokens_in || '?'} in, ${data.metrics.tokens_out || '?'} out.
|
| 746 |
</div>
|