diff --git a/ai-hub/app/core/orchestration/agent_loop.py b/ai-hub/app/core/orchestration/agent_loop.py index cf31f4d..f0eb50b 100644 --- a/ai-hub/app/core/orchestration/agent_loop.py +++ b/ai-hub/app/core/orchestration/agent_loop.py @@ -241,8 +241,12 @@ if event.get("type") == "finish": last_assistant_msg_id = event.get("message_id") round_tool_counts = event.get("tool_counts", {}) - round_input_tokens += event.get("input_tokens", 0) - round_output_tokens += event.get("output_tokens", 0) + # Skip input_tokens/output_tokens from finish if we already got them from token_counted events + # or if they are just duplicates of what we already accumulated. + if round_input_tokens == 0: + round_input_tokens = event.get("input_tokens", 0) + if round_output_tokens == 0: + round_output_tokens = event.get("output_tokens", 0) final_answer = event.get("full_answer", "") elif event.get("type") == "token_counted": usage = event.get("usage", {}) diff --git a/ai-hub/app/core/providers/factory.py b/ai-hub/app/core/providers/factory.py index 7bee67e..daffa4a 100644 --- a/ai-hub/app/core/providers/factory.py +++ b/ai-hub/app/core/providers/factory.py @@ -211,7 +211,14 @@ litellm_providers = [p.value for p in litellm.LlmProviders] base_type = resolve_provider_info(base_provider_for_keys, "llm", _llm_providers, litellm_providers) - full_model = f'{base_type}/{modelName}' if (modelName and '/' not in modelName) else (modelName or "") + # Prevent doubling like 'gemini/gemini' + if modelName and '/' in modelName: + full_model = modelName + elif modelName: + full_model = f'{base_type}/{modelName}' + else: + # Final fallback + full_model = f'{base_type}/{base_type}' try: info = litellm.get_model_info(full_model) diff --git a/ai-hub/app/core/providers/llm/general.py b/ai-hub/app/core/providers/llm/general.py index f93def1..906510b 100644 --- a/ai-hub/app/core/providers/llm/general.py +++ b/ai-hub/app/core/providers/llm/general.py @@ -10,7 +10,8 @@ self.kwargs = kwargs # Validate API Key early - if not api_key or "*" in str(api_key): + print(f"DEBUG LLM: Using model='{model_name}', key='{api_key[:4]}...'") + if not api_key: raise ValueError(f"Invalid or missing API key for LLM provider '{model_name}'. Please configure it in Settings.") def _prepare_messages(self, prompt=None, messages=None): diff --git a/ai-hub/integration_tests/test_agents.py b/ai-hub/integration_tests/test_agents.py index 116df42..313589f 100644 --- a/ai-hub/integration_tests/test_agents.py +++ b/ai-hub/integration_tests/test_agents.py @@ -250,6 +250,9 @@ ) assert r_sync.status_code == 200 + # Give a small buffer for DB persistence + time.sleep(5) + # 5. Verify Metrics captured r_list = client.get(f"{BASE_URL}/agents", headers=_headers()) agent = next(a for a in r_list.json() if a["id"] == instance_id) diff --git a/docker-compose.yml b/docker-compose.yml index 508be70..310bd44 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,6 +35,9 @@ - DEBUG_GRPC=true - DATABASE_URL=sqlite:////app/data/ai-hub.db - CONFIG_PATH=/app/config.yaml + - GEMINI_API_KEY=${GEMINI_API_KEY} + - DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY} + - OPENAI_API_KEY=${OPENAI_API_KEY} volumes: - ./data:/app/data:rw - ./config.yaml:/app/config.yaml:rw diff --git a/run_integration_tests.sh b/run_integration_tests.sh index 0d95ee8..3e09cd7 100755 --- a/run_integration_tests.sh +++ b/run_integration_tests.sh @@ -12,10 +12,10 @@ # 1. Provide an .env if missing if [ ! -f ".env" ]; then echo "Creating default .env for testing..." - echo "CORTEX_ADMIN_PASSWORD=admin" > .env echo "SECRET_KEY=integration-secret-key-123" >> .env echo "SUPER_ADMINS=axieyangb@gmail.com" >> .env echo "GEMINI_API_KEY=AIzaSyBn5HYiZ8yKmNL0ambyz4Aspr5lKw1sKuI" >> .env + echo "GEMINI_MODEL_NAME=gemini-1.5-flash" >> .env fi # LOAD ENV FOR ALL SUBSEQUENT COMMANDS