diff --git a/backend/app/main.py b/backend/app/main.py index 2645684..07a78b0 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -754,6 +754,10 @@ def graphrag_setup_endpoint(): api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") graphrag_api_keys = {"geminiKey": api_key} provider = "gemini" # Map to GraphRAG service provider name + elif provider == "gemini": + # Support direct "gemini" provider selection from frontend + api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") + graphrag_api_keys = {"geminiKey": api_key} elif provider == "anthropic": api_key = api_keys.get("anthropicKey") or config_manager.get("ai_providers.anthropic.api_key", "") graphrag_api_keys = {"anthropicKey": api_key} @@ -881,6 +885,10 @@ def graphrag_change_provider_endpoint(): api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") graphrag_api_keys = {"geminiKey": api_key} provider = "gemini" # Map to GraphRAG service provider name + elif provider == "gemini": + # Support direct "gemini" provider selection from frontend + api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") + graphrag_api_keys = {"geminiKey": api_key} elif provider == "anthropic": api_key = api_keys.get("anthropicKey") or config_manager.get("ai_providers.anthropic.api_key", "") graphrag_api_keys = {"anthropicKey": api_key} @@ -1125,6 +1133,10 @@ def graphrag_endpoint(): api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") graphrag_api_keys = {"geminiKey": api_key} provider = "gemini" # Map to GraphRAG service provider name + elif provider == "gemini": + # Support direct "gemini" provider selection from frontend + api_key = api_keys.get("geminiKey") or config_manager.get("ai_providers.google_genai.api_key", "") + graphrag_api_keys = {"geminiKey": api_key} elif provider == "anthropic": api_key = api_keys.get("anthropicKey") or config_manager.get("ai_providers.anthropic.api_key", "") graphrag_api_keys = {"anthropicKey": api_key} diff --git a/src/lib/config.ts b/src/lib/config.ts index c4566c2..b04a9a8 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1,5 +1,9 @@ // Backend API configuration -export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL; +// Use environment var if provided; otherwise default to same-origin +const ENV_API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string | undefined; +export const API_BASE_URL = (ENV_API_BASE_URL && ENV_API_BASE_URL.trim() !== "") + ? ENV_API_BASE_URL + : window.location.origin; // API endpoints @@ -12,4 +16,15 @@ export const API_ENDPOINTS = { GENERATE_GRAPH_WITH_EDGES: `${API_BASE_URL}/api/generate-graph-with-edges`, GET_UNIQUE_REPOS: `${API_BASE_URL}/api/get-unique-repos`, CREATE_EDGES_ON_GRAPH: `${API_BASE_URL}/api/create-edges-on-graph`, + // GraphRAG endpoints + GRAPHRAG_HEALTH: `${API_BASE_URL}/api/graphrag-health`, + GRAPHRAG_SETUP: `${API_BASE_URL}/api/graphrag-setup`, + GRAPHRAG_PROGRESS: `${API_BASE_URL}/api/graphrag-progress`, + GRAPHRAG_RESET_PROGRESS: `${API_BASE_URL}/api/graphrag-reset-progress`, + GRAPHRAG_CHANGE_PROVIDER: `${API_BASE_URL}/api/graphrag-change-provider`, + GRAPHRAG_UPDATE_README: `${API_BASE_URL}/api/graphrag-update-readme`, + GRAPHRAG_FIX_SCHEMA: `${API_BASE_URL}/api/graphrag-fix-schema`, + GRAPHRAG_QUERY: `${API_BASE_URL}/api/graphrag`, + GRAPHRAG_CLEANUP: `${API_BASE_URL}/api/graphrag-cleanup`, + GRAPHRAG_CHECK_CHANGES: `${API_BASE_URL}/api/graphrag-check-changes`, } as const; \ No newline at end of file diff --git a/src/views/GraphRAGPanel.tsx b/src/views/GraphRAGPanel.tsx index aebf746..dd4f704 100644 --- a/src/views/GraphRAGPanel.tsx +++ b/src/views/GraphRAGPanel.tsx @@ -8,6 +8,7 @@ import { Tooltip } from 'bootstrap'; import { GraphContext } from "../lib/context"; import { useNotifications } from "../lib/notifications"; +import { API_ENDPOINTS } from "../lib/config"; import { ANIMATION_DURATION } from "../lib/consts"; import { Coordinates } from "sigma/types"; @@ -108,7 +109,7 @@ const GraphRAGPanel: FC = () => { try { const sessionId = sessionStorage.getItem('graphrag_session_id') || ''; if (sessionId) { - const response = await fetch('/api/graphrag-cleanup', { + const response = await fetch(API_ENDPOINTS.GRAPHRAG_CLEANUP, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -264,7 +265,7 @@ const GraphRAGPanel: FC = () => { const checkBackendHealth = async () => { if (graphragState.isReady) { try { - const response = await fetch('http://localhost:5002/api/graphrag-health', { + const response = await fetch(API_ENDPOINTS.GRAPHRAG_HEALTH, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -613,7 +614,7 @@ const GraphRAGPanel: FC = () => { const sessionId = `graphrag_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; sessionStorage.setItem('graphrag_session_id', sessionId); - const response = await fetch('http://localhost:5002/api/graphrag-setup', { + const response = await fetch(API_ENDPOINTS.GRAPHRAG_SETUP, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -707,7 +708,7 @@ const GraphRAGPanel: FC = () => { updateState({ messages: newMessages }); try { - const response = await fetch("/api/graphrag", { + const response = await fetch(API_ENDPOINTS.GRAPHRAG_QUERY, { method: "POST", headers: { "Content-Type": "application/json",