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;
--global-background-default: #0D051C;
--textarea-default-color: #0D051C !important;
}
* {

View file

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

View file

@ -1,5 +1,11 @@
export default function getExplorationGraphUrl(dataset: { id: string }) {
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((text) => text.replace('"', ''));
}

View file

@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react';
import classNames from 'classnames';
import { Spacer, Stack } from 'ohmy-ui';
import { Spacer, Stack, Text } from 'ohmy-ui';
import { getExplorationGraphUrl } from '@/modules/exploration';
import { IFrameView, SearchView } from '@/ui/Partials';
import { LoadingIndicator } from '@/ui/App';
@ -13,12 +13,17 @@ interface ExplorerProps {
}
export default function Explorer({ dataset, className, style }: ExplorerProps) {
const [error, setError] = useState<Error | null>(null);
const [graphUrl, setGraphUrl] = useState<string | null>(null);
const exploreData = useCallback(() => {
getExplorationGraphUrl(dataset)
.then((graphUrl) => {
setError(null);
setGraphUrl(graphUrl);
})
.catch((error) => {
setError(error);
});
}, [dataset]);
@ -34,12 +39,18 @@ export default function Explorer({ dataset, className, style }: ExplorerProps) {
className={classNames(styles.explorerContent, className)}
>
<div className={styles.graphExplorer}>
{!graphUrl ? (
<Spacer horizontal="2" wrap>
<LoadingIndicator />
</Spacer>
{error ? (
<Text color="red">{error.message}</Text>
) : (
<IFrameView src={graphUrl} />
<>
{!graphUrl ? (
<Spacer horizontal="2" wrap>
<LoadingIndicator />
</Spacer>
) : (
<IFrameView src={graphUrl} />
)}
</>
)}
</div>
<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)
async def get_dataset_graph(dataset_id: str):
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
try:
# graph_config = get_graph_config()
# graph_engine = graph_config.graph_engine
graph_client = await get_graph_client()
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.infrastructure.databases.relational import get_relationaldb_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")
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.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()
data_directory_path = os.path.abspath(".data_storage")
base_config.data_root_directory = data_directory_path

View file

@ -3,8 +3,8 @@
import os
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
from cognee.infrastructure.databases.relational.config import get_relationaldb_config
from cognee.shared.data_models import GraphDBType, KnowledgeGraph
from cognee.shared.data_models import KnowledgeGraph
from cognee.root_dir import get_absolute_path
class GraphConfig(BaseSettings):
@ -15,15 +15,16 @@ class GraphConfig(BaseSettings):
graph_database_password: str = ""
graph_database_port: int = 123
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_topology_task: bool = False
graph_topology: object = KnowledgeGraph
infer_graph_topology: bool = True
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")
@ -37,7 +38,6 @@ class GraphConfig(BaseSettings):
"graph_database_username": self.graph_database_username,
"graph_database_password": self.graph_database_password,
"graph_database_port": self.graph_database_port,
# "graph_engine": self.graph_engine,
"infer_graph_topology": self.infer_graph_topology,
}