fix: configure api client graph path

This commit is contained in:
Boris Arzentar 2024-06-12 23:25:33 +02:00
parent 39b346de17
commit 6a69279cb5
6 changed files with 43 additions and 20 deletions

View file

@ -6,6 +6,7 @@
"Fira Mono", "Droid Sans Mono", "Courier New", monospace; "Fira Mono", "Droid Sans Mono", "Courier New", monospace;
--global-background-default: #0D051C; --global-background-default: #0D051C;
--textarea-default-color: #0D051C !important;
} }
* { * {

View file

@ -1,8 +1,7 @@
import { useCallback, useEffect } from 'react'; import { useEffect, useRef } from 'react';
import { CTAButton, Spacer, Stack, Text, useBoolean } from 'ohmy-ui'; import { CTAButton, Stack, Text, useBoolean } from 'ohmy-ui';
import { Divider } from '@/ui/Layout'; import { Divider } from '@/ui/Layout';
import { CognifyLoadingIndicator, LoadingIndicator } from '@/ui/App'; import { CognifyLoadingIndicator } from '@/ui/App';
import { getExplorationGraphUrl } from '@/modules/exploration';
import { WizardHeading } from '@/ui/Partials/Wizard'; import { WizardHeading } from '@/ui/Partials/Wizard';
import cognifyDataset from '@/modules/datasets/cognifyDataset'; import cognifyDataset from '@/modules/datasets/cognifyDataset';
@ -16,9 +15,14 @@ export default function CognifyStep({ onNext, dataset }: ConfigStepProps) {
value: isCognifyRunning, value: isCognifyRunning,
setFalse: stopCognifyIndicator, setFalse: stopCognifyIndicator,
} = useBoolean(true); } = useBoolean(true);
const cognifyPromise = useRef<Promise<void>>()
useEffect(() => { useEffect(() => {
cognifyDataset(dataset) if (cognifyPromise.current) {
return;
}
cognifyPromise.current = cognifyDataset(dataset)
.then(() => { .then(() => {
stopCognifyIndicator(); stopCognifyIndicator();
}); });

View file

@ -1,5 +1,11 @@
export default function getExplorationGraphUrl(dataset: { id: string }) { export default function getExplorationGraphUrl(dataset: { id: string }) {
return fetch(`http://0.0.0.0:8000/datasets/${dataset.id}/graph`) return fetch(`http://0.0.0.0:8000/datasets/${dataset.id}/graph`)
.then(async (response) => {
if (response.status !== 200) {
throw new Error((await response.text()).replaceAll("\"", ""));
}
return response;
})
.then((response) => response.text()) .then((response) => response.text())
.then((text) => text.replace('"', '')); .then((text) => text.replace('"', ''));
} }

View file

@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { Spacer, Stack } from 'ohmy-ui'; import { Spacer, Stack, Text } from 'ohmy-ui';
import { getExplorationGraphUrl } from '@/modules/exploration'; import { getExplorationGraphUrl } from '@/modules/exploration';
import { IFrameView, SearchView } from '@/ui/Partials'; import { IFrameView, SearchView } from '@/ui/Partials';
import { LoadingIndicator } from '@/ui/App'; import { LoadingIndicator } from '@/ui/App';
@ -13,12 +13,17 @@ interface ExplorerProps {
} }
export default function Explorer({ dataset, className, style }: ExplorerProps) { export default function Explorer({ dataset, className, style }: ExplorerProps) {
const [error, setError] = useState<Error | null>(null);
const [graphUrl, setGraphUrl] = useState<string | null>(null); const [graphUrl, setGraphUrl] = useState<string | null>(null);
const exploreData = useCallback(() => { const exploreData = useCallback(() => {
getExplorationGraphUrl(dataset) getExplorationGraphUrl(dataset)
.then((graphUrl) => { .then((graphUrl) => {
setError(null);
setGraphUrl(graphUrl); setGraphUrl(graphUrl);
})
.catch((error) => {
setError(error);
}); });
}, [dataset]); }, [dataset]);
@ -34,12 +39,18 @@ export default function Explorer({ dataset, className, style }: ExplorerProps) {
className={classNames(styles.explorerContent, className)} className={classNames(styles.explorerContent, className)}
> >
<div className={styles.graphExplorer}> <div className={styles.graphExplorer}>
{!graphUrl ? ( {error ? (
<Spacer horizontal="2" wrap> <Text color="red">{error.message}</Text>
<LoadingIndicator />
</Spacer>
) : ( ) : (
<IFrameView src={graphUrl} /> <>
{!graphUrl ? (
<Spacer horizontal="2" wrap>
<LoadingIndicator />
</Spacer>
) : (
<IFrameView src={graphUrl} />
)}
</>
)} )}
</div> </div>
<div className={styles.chat}> <div className={styles.chat}>

View file

@ -69,12 +69,9 @@ async def delete_dataset(dataset_id: str):
@app.get("/datasets/{dataset_id}/graph", response_model=list) @app.get("/datasets/{dataset_id}/graph", response_model=list)
async def get_dataset_graph(dataset_id: str): async def get_dataset_graph(dataset_id: str):
from cognee.shared.utils import render_graph from cognee.shared.utils import render_graph
from cognee.infrastructure.databases.graph import get_graph_config
from cognee.infrastructure.databases.graph.get_graph_client import get_graph_client from cognee.infrastructure.databases.graph.get_graph_client import get_graph_client
try: try:
# graph_config = get_graph_config()
# graph_engine = graph_config.graph_engine
graph_client = await get_graph_client() graph_client = await get_graph_client()
graph_url = await render_graph(graph_client.graph) graph_url = await render_graph(graph_client.graph)
@ -261,6 +258,7 @@ def start_api_server(host: str = "0.0.0.0", port: int = 8000):
from cognee.base_config import get_base_config from cognee.base_config import get_base_config
from cognee.infrastructure.databases.relational import get_relationaldb_config from cognee.infrastructure.databases.relational import get_relationaldb_config
from cognee.infrastructure.databases.vector import get_vectordb_config from cognee.infrastructure.databases.vector import get_vectordb_config
from cognee.infrastructure.databases.graph import get_graph_config
cognee_directory_path = os.path.abspath(".cognee_system") cognee_directory_path = os.path.abspath(".cognee_system")
databases_directory_path = os.path.join(cognee_directory_path, "databases") databases_directory_path = os.path.join(cognee_directory_path, "databases")
@ -272,6 +270,9 @@ def start_api_server(host: str = "0.0.0.0", port: int = 8000):
vector_config = get_vectordb_config() vector_config = get_vectordb_config()
vector_config.vector_db_url = os.path.join(databases_directory_path, "cognee.lancedb") vector_config.vector_db_url = os.path.join(databases_directory_path, "cognee.lancedb")
graph_config = get_graph_config()
graph_config.graph_file_path = os.path.join(databases_directory_path, "cognee.graph")
base_config = get_base_config() base_config = get_base_config()
data_directory_path = os.path.abspath(".data_storage") data_directory_path = os.path.abspath(".data_storage")
base_config.data_root_directory = data_directory_path base_config.data_root_directory = data_directory_path

View file

@ -3,8 +3,8 @@
import os import os
from functools import lru_cache from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
from cognee.infrastructure.databases.relational.config import get_relationaldb_config from cognee.shared.data_models import KnowledgeGraph
from cognee.shared.data_models import GraphDBType, KnowledgeGraph from cognee.root_dir import get_absolute_path
class GraphConfig(BaseSettings): class GraphConfig(BaseSettings):
@ -15,15 +15,16 @@ class GraphConfig(BaseSettings):
graph_database_password: str = "" graph_database_password: str = ""
graph_database_port: int = 123 graph_database_port: int = 123
graph_file_path: str = os.path.join( graph_file_path: str = os.path.join(
get_relationaldb_config().db_path, graph_filename os.path.join(get_absolute_path(".cognee_system"), "databases"),
graph_filename
) )
# graph_engine: object = GraphDBType.NETWORKX
graph_model: object = KnowledgeGraph graph_model: object = KnowledgeGraph
graph_topology_task: bool = False graph_topology_task: bool = False
graph_topology: object = KnowledgeGraph graph_topology: object = KnowledgeGraph
infer_graph_topology: bool = True infer_graph_topology: bool = True
topology_file_path: str = os.path.join( topology_file_path: str = os.path.join(
get_relationaldb_config().db_path, "graph_topology.json" os.path.join(get_absolute_path(".cognee_system"), "databases"),
"graph_topology.json"
) )
model_config = SettingsConfigDict(env_file=".env", extra="allow") model_config = SettingsConfigDict(env_file=".env", extra="allow")
@ -37,7 +38,6 @@ class GraphConfig(BaseSettings):
"graph_database_username": self.graph_database_username, "graph_database_username": self.graph_database_username,
"graph_database_password": self.graph_database_password, "graph_database_password": self.graph_database_password,
"graph_database_port": self.graph_database_port, "graph_database_port": self.graph_database_port,
# "graph_engine": self.graph_engine,
"infer_graph_topology": self.infer_graph_topology, "infer_graph_topology": self.infer_graph_topology,
} }