Skip to content

Commit

Permalink
Formatting and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Apr 25, 2024
1 parent 3cd1ec3 commit d65d218
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 89 deletions.
4 changes: 1 addition & 3 deletions .vscode/settings.json
Expand Up @@ -9,8 +9,6 @@
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.extraPaths": [
"./llama-index-core"
],
"python.analysis.extraPaths": ["./llama-index-core"],
"python.analysis.autoImportCompletions": true
}
142 changes: 89 additions & 53 deletions docs/prepare_for_build.py
Expand Up @@ -139,23 +139,27 @@
)
if (
toc_path_name
not in mkdocs["nav"][examples_idx]["Examples"][label_idx][label]
not in mkdocs["nav"][examples_idx]["Examples"][label_idx][
label
]
):
mkdocs["nav"][examples_idx]["Examples"][label_idx][label].append(
toc_path_name
)
mkdocs["nav"][examples_idx]["Examples"][label_idx][
label
].append(toc_path_name)
if os.path.isdir(os.path.join(path_name, file_name)):
for root, dirs, files in os.walk(os.path.join(path_name, file_name)):
for root, dirs, files in os.walk(
os.path.join(path_name, file_name)
):
for file in files:
if file.endswith(".ipynb"):
toc_path_name = "./" + os.path.join(
root.replace("docs/docs/", ""), file
)
if (
toc_path_name
not in mkdocs["nav"][examples_idx]["Examples"][label_idx][
label
]
not in mkdocs["nav"][examples_idx]["Examples"][
label_idx
][label]
):
mkdocs["nav"][examples_idx]["Examples"][label_idx][
label
Expand Down Expand Up @@ -196,7 +200,9 @@
elif folder_name == "graph_stores":
folder_name = "storage/graph_stores"

full_path = os.path.join("docs/docs/api_reference", folder_name)
full_path = os.path.join(
"docs/docs/api_reference", folder_name
)
module_name = import_path.split(".")[-1] + ".md"
os.makedirs(full_path, exist_ok=True)
with open(os.path.join(full_path, module_name), "w") as f:
Expand All @@ -212,23 +218,31 @@
if "storage" in folder_name:
label = "Storage"
else:
label = INTEGRATION_FOLDER_TO_LABEL[import_path.split(".")[1]]
label = INTEGRATION_FOLDER_TO_LABEL[
import_path.split(".")[1]
]

label_idx = -1
for idx, item in enumerate(mkdocs["nav"][api_ref_idx]["API Reference"]):
for idx, item in enumerate(
mkdocs["nav"][api_ref_idx]["API Reference"]
):
if label in item:
label_idx = idx
break

if label_idx == -1:
mkdocs["nav"][api_ref_idx]["API Reference"].append({label: []})
mkdocs["nav"][api_ref_idx]["API Reference"].append(
{label: []}
)

toc_path_name = "./" + os.path.join(
"api_reference", folder_name, module_name
)
if (
toc_path_name
not in mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label]
not in mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label]
):
# storage is a special case, multi-level
if label == "Storage":
Expand All @@ -239,36 +253,38 @@
existing_sub_label_idx,
existing_sub_label,
) in enumerate(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
]
mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label]
):
if sub_label in existing_sub_label:
sub_label_idx = existing_sub_label_idx
break

if sub_label_idx == -1:
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
].append({sub_label: []})
mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label].append({sub_label: []})

if (
toc_path_name
not in mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label][sub_label_idx][sub_label]
):
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label].append(toc_path_name)
mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label][sub_label_idx][sub_label].append(
toc_path_name
)

# sort per sub-label
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label][
sub_label_idx
][sub_label] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label],
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label][sub_label_idx][sub_label],
key=lambda x: next(iter(x.keys()))
if isinstance(x, dict)
else x,
Expand All @@ -279,9 +295,15 @@
].append(toc_path_name)

# maintain sorting per label
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label],
key=lambda x: next(iter(x.keys())) if isinstance(x, dict) else x,
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
],
key=lambda x: next(iter(x.keys()))
if isinstance(x, dict)
else x,
)

# add existing api reference pages to nav
Expand All @@ -308,7 +330,9 @@
label = INTEGRATION_FOLDER_TO_LABEL[root.split("/")[-1]]

label_idx = -1
for idx, item in enumerate(mkdocs["nav"][api_ref_idx]["API Reference"]):
for idx, item in enumerate(
mkdocs["nav"][api_ref_idx]["API Reference"]
):
if label in item:
label_idx = idx
break
Expand All @@ -324,7 +348,9 @@
existing_sub_label_idx,
existing_sub_label,
) in enumerate(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label]
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
]
):
if sub_label in existing_sub_label:
sub_label_idx = existing_sub_label_idx
Expand All @@ -337,35 +363,45 @@

if (
toc_path_name
not in mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label]
not in mkdocs["nav"][api_ref_idx]["API Reference"][
label_idx
][label][sub_label_idx][sub_label]
):
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label][
sub_label_idx
][sub_label].append(toc_path_name)
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label].append(toc_path_name)

# sort per sub-label
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label][
sub_label_idx
][sub_label] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label][
sub_label_idx
][sub_label],
key=lambda x: next(iter(x.keys())) if isinstance(x, dict) else x,
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
][sub_label_idx][sub_label],
key=lambda x: next(iter(x.keys()))
if isinstance(x, dict)
else x,
)
elif (
toc_path_name
not in mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label]
not in mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
]
):
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label].append(
toc_path_name
)
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
].append(toc_path_name)

# sort per label
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][label],
key=lambda x: next(iter(x.keys())) if isinstance(x, dict) else x,
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
] = sorted(
mkdocs["nav"][api_ref_idx]["API Reference"][label_idx][
label
],
key=lambda x: next(iter(x.keys()))
if isinstance(x, dict)
else x,
)

# sort the API Reference nav section
Expand All @@ -381,9 +417,9 @@
for search_path in search_paths:
if (
search_path
not in mkdocs["plugins"][i]["mkdocstrings"]["handlers"]["python"][
"paths"
]
not in mkdocs["plugins"][i]["mkdocstrings"]["handlers"][
"python"
]["paths"]
):
mkdocs["plugins"][i]["mkdocstrings"]["handlers"]["python"][
"paths"
Expand Down
Expand Up @@ -127,7 +127,11 @@
{example_output_2.json()}
```
""".replace("{", "{{").replace("}", "}}")
""".replace(
"{", "{{"
).replace(
"}", "}}"
)


SUFFIX = """
Expand Down
6 changes: 5 additions & 1 deletion llama-index-core/llama_index/core/question_gen/prompts.py
Expand Up @@ -65,7 +65,11 @@ def build_tools_text(tools: Sequence[ToolMetadata]) -> str:
{example_output_str}
```
""".replace("{", "{{").replace("}", "}}")
""".replace(
"{", "{{"
).replace(
"}", "}}"
)

SUFFIX = """\
# Example 2
Expand Down
Expand Up @@ -126,7 +126,11 @@
{example_output_2.json()}
```
""".replace("{", "{{").replace("}", "}}")
""".replace(
"{", "{{"
).replace(
"}", "}}"
)


SUFFIX = """
Expand Down
Expand Up @@ -103,9 +103,7 @@ def __init__(
if len(self.pipeline_ids) == 0:
print("No available pipelines. Please create pipelines first.")
else:
assert set(
PIPELINE_TYPES
).issubset(
assert set(PIPELINE_TYPES).issubset(
set(self.pipeline_ids.keys())
), f"Missing pipeline(s): {set(PIPELINE_TYPES) - set(self.pipeline_ids.keys())}"

Expand Down
@@ -1,3 +1,3 @@
# LlamaIndex Llms Integration: Mistral-Rs

Please install the Python bindings according to the guide [here](https://github.com/EricLBuehler/mistral.rs/blob/master/mistralrs-pyo3/README.md).
Please install the Python bindings according to the guide [here](https://github.com/EricLBuehler/mistral.rs/blob/master/mistralrs-pyo3/README.md).
Expand Up @@ -15,7 +15,7 @@
"documents = SimpleDirectoryReader(\"data\").load_data()\n",
"\n",
"# bge embedding model\n",
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")\n"
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")"
]
},
{
Expand Down Expand Up @@ -55,7 +55,7 @@
"source": [
"query_engine = index.as_query_engine()\n",
"response = query_engine.query(\"How do I pronounce graphene?\")\n",
"print(response)\n"
"print(response)"
]
}
],
Expand Down
Expand Up @@ -15,7 +15,7 @@
"documents = SimpleDirectoryReader(\"data\").load_data()\n",
"\n",
"# bge embedding model\n",
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")\n"
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")"
]
},
{
Expand All @@ -24,7 +24,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"Settings.llm = MistralRS(\n",
" which=Which.GGUF(\n",
" tok_model_id=\"mistralai/Mistral-7B-Instruct-v0.1\",\n",
Expand Down Expand Up @@ -58,7 +57,7 @@
"query_engine = index.as_query_engine(streaming=True)\n",
"response = query_engine.query(\"What are non-granular scalings?\")\n",
"for text in response.response_gen:\n",
" print(text,end=\"\")\n",
" print(text, end=\"\")\n",
" sys.stdout.flush()"
]
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
"documents = SimpleDirectoryReader(\"data\").load_data()\n",
"\n",
"# bge embedding model\n",
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")\n"
"Settings.embed_model = resolve_embed_model(\"local:BAAI/bge-small-en-v1.5\")"
]
},
{
Expand All @@ -24,7 +24,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"Settings.llm = MistralRS(\n",
" which=Which.GGUF(\n",
" tok_model_id=\"mistralai/Mistral-7B-Instruct-v0.1\",\n",
Expand Down Expand Up @@ -57,7 +56,7 @@
"source": [
"query_engine = index.as_query_engine()\n",
"response = query_engine.query(\"How do I pronounce graphene?\")\n",
"print(response)\n"
"print(response)"
]
}
],
Expand Down
Expand Up @@ -18,9 +18,6 @@
)
from llama_index.core.llms.callbacks import llm_chat_callback, llm_completion_callback
from llama_index.core.llms.custom import CustomLLM
from llama_index.core.base.llms.generic_utils import (
completion_response_to_chat_response,
)
from llama_index.core.types import BaseOutputParser, PydanticProgramMode

from mistralrs import (
Expand Down

0 comments on commit d65d218

Please sign in to comment.