From 926241cbefb4d7c82d72a1c0de815917c60344fe Mon Sep 17 00:00:00 2001 From: emrgnt-cmplxty <68796651+emrgnt-cmplxty@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:59:38 -0700 Subject: [PATCH] Feature/fix stream format (#1243) * denote findings * up * up * up --- py/core/pipes/retrieval/streaming_rag_pipe.py | 1 - py/pyproject.toml | 2 +- py/sdk/ingestion.py | 3 +- py/sdk/restructure.py | 8 ++- py/shared/utils/base_utils.py | 2 +- .../web-app/components/SearchResults.tsx | 57 ++++++++++++++++--- .../web-app/pages/api/agent.ts | 1 - .../web-app/pages/index.tsx | 1 + 8 files changed, 59 insertions(+), 16 deletions(-) diff --git a/py/core/pipes/retrieval/streaming_rag_pipe.py b/py/core/pipes/retrieval/streaming_rag_pipe.py index 9f9d3cd47..4924cc459 100644 --- a/py/core/pipes/retrieval/streaming_rag_pipe.py +++ b/py/core/pipes/retrieval/streaming_rag_pipe.py @@ -66,7 +66,6 @@ async def _run_logic( # type: ignore result = format_search_results_for_stream(search_results) yield result gen_context = format_search_results_for_llm(search_results) - print("gen_context = ", gen_context) context += gen_context messages = self.prompt_provider._get_message_payload( diff --git a/py/pyproject.toml b/py/pyproject.toml index 490ca312d..948240d4d 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "r2r" readme = "README.md" -version = "3.1.44" +version = "3.1.45" description = "SciPhi R2R" authors = ["Owen Colegrove "] license = "MIT" diff --git a/py/sdk/ingestion.py b/py/sdk/ingestion.py index a7a5072de..462a9bd5d 100644 --- a/py/sdk/ingestion.py +++ b/py/sdk/ingestion.py @@ -73,7 +73,7 @@ async def ingest_files( ) if metadatas: data["metadatas"] = json.dumps(metadatas) - + if chunking_config: data["chunking_config"] = ( chunking_config.model_dump() # type: ignore @@ -81,7 +81,6 @@ async def ingest_files( else chunking_config ) - return await client._make_request( "POST", "ingest_files", data=data, files=files_tuples ) diff --git a/py/sdk/restructure.py b/py/sdk/restructure.py index a435294c2..40209c344 100644 --- a/py/sdk/restructure.py +++ b/py/sdk/restructure.py @@ -26,7 +26,9 @@ async def create_graph( if document_ids: data["document_ids"] = document_ids if kg_creation_settings: - data["kg_creation_settings"] = kg_creation_settings + if isinstance(kg_creation_settings, KGCreationSettings): + kg_creation_settings = kg_creation_settings.dict() + data["kg_creation_settings"] = kg_creation_settings # type: ignore response = await client._make_request( "POST", "create_graph", json=data @@ -60,7 +62,9 @@ async def enrich_graph( if force_enrichment: data["force_enrichment"] = force_enrichment if kg_enrichment_settings: - data["kg_enrichment_settings"] = kg_enrichment_settings + if isinstance(kg_enrichment_settings, KGEnrichmentSettings): + kg_enrichment_settings = kg_enrichment_settings.dict() + data["kg_enrichment_settings"] = kg_enrichment_settings # type: ignore response = await client._make_request( "POST", "enrich_graph", json=data diff --git a/py/shared/utils/base_utils.py b/py/shared/utils/base_utils.py index 46412d9be..b52c2211a 100644 --- a/py/shared/utils/base_utils.py +++ b/py/shared/utils/base_utils.py @@ -24,7 +24,7 @@ def format_search_results_for_llm( formatted_results += "KG Local Results:\n" for j, kg_result in enumerate(results.kg_search_results): formatted_results += ( - f"Source [{j+1}]: Name - {kg_result.content.name}\n" + f"Source [{j+i+1}]: Name - {kg_result.content.name}\n" ) formatted_results += ( f"Description - {kg_result.content.description}\n" diff --git a/templates/ycombinator_graphrag/web-app/components/SearchResults.tsx b/templates/ycombinator_graphrag/web-app/components/SearchResults.tsx index ebd2368ac..64b374b1a 100644 --- a/templates/ycombinator_graphrag/web-app/components/SearchResults.tsx +++ b/templates/ycombinator_graphrag/web-app/components/SearchResults.tsx @@ -41,22 +41,63 @@ const VectorSearchResultItem: FC<{ ); }; +// const KGSearchResultItem: FC<{ entity: KGSearchResult; index: number }> = ({ +// entity, +// index, +// }) => { +// const { content } = entity; + +// return ( +//
+//
+//
+//

+// [{index}] {content.name} +//

+//
+ +//

{content.description}

+//
+//
+// ); +// }; + const KGSearchResultItem: FC<{ entity: KGSearchResult; index: number }> = ({ entity, index, }) => { - const { content } = entity; + const { content, metadata } = entity; + const findings = metadata?.findings; return ( -
-
-
-

+
+
+ {/* Title */} +
+

[{index}] {content.name}

+

Summary:

+ + {/* Description */} + {content.description && ( +

{content.description}

+ )} -

{content.description}

+ {/* Findings */} + {findings && findings.length > 0 && ( +
+

Findings:

+
    + {findings.map((finding: string, idx: number) => ( +
  • + {finding} +
  • + ))} +
+
+ )}
); @@ -113,8 +154,8 @@ export const SearchResults: React.FC = ({ className="text-zinc-900 w-full max-w-2xl" > - KG Entities - KG Communities + KG Communities + KG Entities Vector Search diff --git a/templates/ycombinator_graphrag/web-app/pages/api/agent.ts b/templates/ycombinator_graphrag/web-app/pages/api/agent.ts index 1a0e53dba..b999572df 100644 --- a/templates/ycombinator_graphrag/web-app/pages/api/agent.ts +++ b/templates/ycombinator_graphrag/web-app/pages/api/agent.ts @@ -38,7 +38,6 @@ export default async function handler(req: Request) { // kg_search_type: "local", // kg_search_type ?? 'local', }; - console.log('searchParams = ', searchParams); const kgSearchParams = use_kg_search ? { use_kg_search: true, kg_search_type: 'local' } diff --git a/templates/ycombinator_graphrag/web-app/pages/index.tsx b/templates/ycombinator_graphrag/web-app/pages/index.tsx index 9206568db..939d6d6d2 100644 --- a/templates/ycombinator_graphrag/web-app/pages/index.tsx +++ b/templates/ycombinator_graphrag/web-app/pages/index.tsx @@ -10,6 +10,7 @@ const Index: React.FC = () => { const router = useRouter(); const [query, setQuery] = useState(''); const [agentUrl] = useState('https://infra.sciphi.ai'); + // const [agentUrl] = useState('http://0.0.0.0:7272'); const [isStreaming, setIsStreaming] = useState(false); const contentAreaRef = useRef(null); const [messages, setMessages] = useState([]);