Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding logging #391

Merged
merged 14 commits into from
Feb 8, 2023
Merged
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ __pycache__/

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
etc/
include/
lib/
lib64/
parts/
sdist/
share/
var/
wheels/
pip-wheel-metadata/
Expand Down Expand Up @@ -111,6 +115,7 @@ venv/
ENV/
env.bak/
venv.bak/
pyvenv.cfg

# Spyder project settings
.spyderproject
Expand Down
27 changes: 20 additions & 7 deletions docs/getting_started/starter_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Here is a starter example for using GPT Index. Make sure you've followed the [installation](installation.md) steps first.


### Download
GPT Index examples can be found in the `examples` folder of the GPT Index repository.
We first want to download this `examples` folder. An easy way to do this is to just clone the repo:

GPT Index examples can be found in the `examples` folder of the GPT Index repository.
We first want to download this `examples` folder. An easy way to do this is to just clone the repo:

```bash
$ git clone https://github.com/jerryjliu/gpt_index.git
Expand All @@ -22,16 +22,16 @@ Makefile experimental/ requirements.txt
README.md gpt_index/ setup.py
```


We now want to navigate to the following folder:

```bash
$ cd examples/paul_graham_essay
```

This contains GPT Index examples around Paul Graham's essay, ["What I Worked On"](http://paulgraham.com/worked.html). A comprehensive set of examples are already provided in `TestEssay.ipynb`. For the purposes of this tutorial, we can focus on a simple example of getting GPT Index up and running.


### Build and Query Index

Create a new `.py` file with the following:

```python
Expand All @@ -43,13 +43,28 @@ index = GPTSimpleVectorIndex(documents)
```

This builds an index over the documents in the `data` folder (which in this case just consists of the essay text). We then run the following

```python
response = index.query("What did the author do growing up?")
print(response)
```

You should get back a response similar to the following: `The author wrote short stories and tried to program on an IBM 1401.`

### Viewing Queries and Events Using Logging

In a Jupyter notebook, you can view info and/or debugging logging using the following snippet:

```python
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
```

You can set the level to `DEBUG` for verbose output, or use `level=logging.INFO` for less.

### Saving and Loading

To save to disk and load from disk, do
Expand All @@ -61,9 +76,7 @@ index.save_to_disk('index.json')
index = GPTSimpleVectorIndex.load_from_disk('index.json')
```


### Next Steps

That's it! For more information on GPT Index features, please check out the numerous "How-To Guides" to the left.
Additionally, if you would like to play around with Example Notebooks, check out [this link](/reference/example_notebooks.rst).

24 changes: 19 additions & 5 deletions examples/composable_indices/ComposableIndices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
"# Composable Indices Demo"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa0e62b6",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand Down Expand Up @@ -322,11 +336,11 @@
"metadata": {},
"outputs": [],
"source": [
"# set Logging to DEBUG for more detailed outputs\n",
"# ask it a question about NYC \n",
"response = graph.query(\n",
" \"What is the climate of New York City like? How cold is it during the winter?\", \n",
" query_configs=query_configs,\n",
" verbose=True\n",
" query_configs=query_configs\n",
")"
]
},
Expand Down Expand Up @@ -436,9 +450,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "gpt_retrieve_venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "gpt_retrieve_venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -450,7 +464,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
18 changes: 15 additions & 3 deletions examples/data_connectors/DatabaseReaderDemo.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -162,7 +175,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -176,9 +189,8 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.7"
"version": "3.11.1"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "bd5508c2ffc7f17f7d31cf4086cc872f89e96996a08987e995649e5fbe85a3a4"
Expand Down
23 changes: 19 additions & 4 deletions examples/data_connectors/DiscordDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
"Demonstrates our Discord data connector"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5fb15bc4",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -65,7 +79,8 @@
"metadata": {},
"outputs": [],
"source": [
"response = index.query(\"<query_text>\", verbose=True)"
"# set Logging to DEBUG for more detailed outputs\n",
"response = index.query(\"<query_text>\")"
]
},
{
Expand All @@ -81,9 +96,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "gpt_retrieve_venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "gpt_retrieve_venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -95,7 +110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
23 changes: 19 additions & 4 deletions examples/data_connectors/FaissDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
"# Faiss Demo"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4026b434",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -112,7 +126,8 @@
"metadata": {},
"outputs": [],
"source": [
"response = index.query(\"<query_text>\", verbose=True)"
"# set Logging to DEBUG for more detailed outputs\n",
"response = index.query(\"<query_text>\")"
]
},
{
Expand All @@ -128,9 +143,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:conda_gpt_env]",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "conda-env-conda_gpt_env-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -142,7 +157,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
19 changes: 17 additions & 2 deletions examples/data_connectors/GoogleDocsDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
"Demonstrates our Google Docs data connector"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6b62adf",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -50,7 +64,8 @@
"metadata": {},
"outputs": [],
"source": [
"response = index.query(\"<query_text>\", verbose=True)"
"# set Logging to DEBUG for more detailed outputs\n",
"response = index.query(\"<query_text>\")"
]
},
{
Expand Down Expand Up @@ -80,7 +95,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.4"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
23 changes: 19 additions & 4 deletions examples/data_connectors/MakeDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
"We show how GPT Index can fit with your Make.com workflow by sending the GPT Index response to a scenario webhook."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2289d27",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -39,9 +53,10 @@
"metadata": {},
"outputs": [],
"source": [
"# set Logging to DEBUG for more detailed outputs\n",
"# query index\n",
"query_str = \"What did the author do growing up?\"\n",
"response = index.query(query_str, verbose=True)"
"response = index.query(query_str)"
]
},
{
Expand All @@ -63,9 +78,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "gpt_retrieve_venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "gpt_retrieve_venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -77,7 +92,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.1"
}
},
"nbformat": 4,
Expand Down
Loading