Skip to content

Commit 1d0e76f

Browse files
committed
fixes
1 parent 5f9c9c7 commit 1d0e76f

File tree

7 files changed

+27
-38
lines changed

7 files changed

+27
-38
lines changed

docs/examples/index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
vector store so that it can be used to provide context to an LLM for code generation.
1919

2020
It uses LangChain and `langchain-graph-retriever` with a custom traversal Strategy
21-
to in order to improve LLM generated code output. It shows that using GraphRAG can
22-
provide a significant increase in quality over using either a LLM alone or standard
21+
in order to improve LLM generated code output. It shows that using GraphRAG can
22+
provide a significant increase in quality over using either an LLM alone or standard
2323
RAG.
2424

25-
GraphRAG is traverses through the documentation in a way similar to how a
26-
software engineer would, in order to determine how to solve a coding problem.
25+
GraphRAG traverses cross references in the documentation like a software engineer
26+
would, in order to determine how to solve a coding problem.
2727

2828
[:material-fast-forward: Code Generation Example](code-generation.ipynb)
2929
</div>

docs/examples/lazy-graph-rag.ipynb

-7
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@
7171
"The last package -- `graph-rag-example-helpers` -- includes some helpers for setting up environment helpers and allowing the loading of wikipedia data to be restarted if it fails."
7272
]
7373
},
74-
{
75-
"cell_type": "code",
76-
"execution_count": null,
77-
"metadata": {},
78-
"outputs": [],
79-
"source": []
80-
},
8174
{
8275
"cell_type": "code",
8376
"execution_count": null,
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
from ...examples.code_generation.format import add_tabs, format_docs, format_document
21
from .fetch import fetch_documents
32

43
__all__ = [
54
"fetch_documents",
6-
"add_tabs",
7-
"format_document",
8-
"format_docs",
95
]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from .format import add_tabs, format_docs, format_document
1+
from .format import format_docs, format_document
22

33
__all__ = [
4-
"add_tabs",
54
"format_document",
65
"format_docs",
76
]

packages/graph-rag-example-helpers/src/graph_rag_example_helpers/examples/code_generation/converter.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import json
33
import os
44
import typing
5+
from textwrap import indent
56
from typing import Any
67

78
import griffe
89

9-
from graph_rag_example_helpers.utils import add_tabs
10-
1110

1211
def convert(
1312
package_name: str,
@@ -165,7 +164,7 @@ def _format_parameter(self, el: dict[str, str]) -> str:
165164
if "default" in el:
166165
text += f" = {el['default']}"
167166
if "description" in el:
168-
desc = add_tabs(el["description"])
167+
desc = indent(el["description"], "\t")
169168
text += f"\n\t{desc}"
170169
return text
171170

@@ -174,7 +173,7 @@ def _format_return(self, el: dict[str, str]) -> str:
174173
if "type" in el:
175174
items.append(el["type"])
176175
if "description" in el:
177-
items.append(add_tabs(el["description"]))
176+
items.append(indent(el["description"], "\t"))
178177
return "\n\t".join(items)
179178

180179
def _extract_common(self, obj: griffe.Object) -> dict[str, Any]:

packages/graph-rag-example-helpers/src/graph_rag_example_helpers/examples/code_generation/format.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from textwrap import indent
2+
13
from langchain_core.documents import Document
24

3-
from graph_rag_example_helpers.utils import add_tabs
5+
6+
def _add_tabs(text: str) -> str:
7+
return indent(text, "\t")
48

59

610
def _format_parameter(el: dict[str, str]) -> str:
@@ -13,7 +17,7 @@ def _format_parameter(el: dict[str, str]) -> str:
1317
if "default" in el:
1418
text += f" = {el['default']}"
1519
if "description" in el:
16-
desc = add_tabs(el["description"])
20+
desc = _add_tabs(el["description"])
1721
text += f"\n\t{desc}"
1822
return text
1923

@@ -23,7 +27,7 @@ def _format_return(el: dict[str, str]) -> str:
2327
if "type" in el:
2428
items.append(el["type"])
2529
if "description" in el:
26-
items.append(add_tabs(el["description"]))
30+
items.append(_add_tabs(el["description"]))
2731
return "\n\t".join(items)
2832

2933

@@ -36,30 +40,31 @@ def format_document(doc: Document, debug: bool = False) -> str:
3640

3741
for key in ["bases", "exports", "implemented_by"]:
3842
if key in metadata:
39-
values = '\n'.join(metadata[key])
40-
text += f"{key}: \n\t{add_tabs(values)}\n\n"
43+
values = "\n".join(metadata[key])
44+
text += f"{key}: \n\t{_add_tabs(values)}\n\n"
4145

4246
if "properties" in metadata:
4347
props = [f"{k}: {v}" for k, v in metadata["properties"].items()]
44-
text += f"properties: \n\t{add_tabs('\n'.join(props))}\n\n"
48+
values = "\n".join(props)
49+
text += f"properties: \n\t{_add_tabs(values)}\n\n"
4550

4651
if doc.page_content != "":
47-
text += f"description: \n\t{add_tabs(doc.page_content)}\n\n"
52+
text += f"description: \n\t{_add_tabs(doc.page_content)}\n\n"
4853
elif "value" in metadata:
4954
text += f"{metadata['value']}\n\n"
5055

5156
for key in ["attributes", "parameters"]:
5257
if key in metadata:
53-
values = '\n\n'.join([_format_parameter(v) for v in metadata[key]])
54-
text += f"{key}: \n\t{add_tabs(values)}\n\n"
58+
values = "\n\n".join([_format_parameter(v) for v in metadata[key]])
59+
text += f"{key}: \n\t{_add_tabs(values)}\n\n"
5560

5661
for key in ["returns", "yields"]:
5762
if key in metadata:
58-
values = '\n\n'.join([_format_return(v) for v in metadata[key]])
59-
text += f"{key}: \n\t{add_tabs(values)}\n\n"
63+
values = "\n\n".join([_format_return(v) for v in metadata[key]])
64+
text += f"{key}: \n\t{_add_tabs(values)}\n\n"
6065

6166
for key in ["note", "example"]:
62-
text += f"{key}: \n\t{add_tabs(metadata[key])}\n\n"
67+
text += f"{key}: \n\t{_add_tabs(metadata[key])}\n\n"
6368

6469
if debug:
6570
if "imports" in metadata:
@@ -70,12 +75,12 @@ def format_document(doc: Document, debug: bool = False) -> str:
7075
else:
7176
imports.append(f"{real_name} as {as_name}")
7277
values = "\n".join(imports)
73-
text += f"imports: \n\t{add_tabs(values)}\n\n"
78+
text += f"imports: \n\t{_add_tabs(values)}\n\n"
7479

7580
for key in ["references", "gathered_types"]:
7681
if key in metadata:
7782
values = "\n".join(metadata[key])
78-
text += f"{key}: \n\t{add_tabs(values)}\n\n"
83+
text += f"{key}: \n\t{_add_tabs(values)}\n\n"
7984

8085
if "parent" in metadata:
8186
text += f"parent: {metadata['parent']}\n\n"

packages/graph-rag-example-helpers/src/graph_rag_example_helpers/utils.py

-3
This file was deleted.

0 commit comments

Comments
 (0)