Skip to content

Commit c527344

Browse files
smokestacklightninpmeierpavithraes
authored
[DOC] Add tutorial for adding your own objects (#368)
Co-authored-by: Philip Meier <github.pmeier@posteo.de> Co-authored-by: Pavithra Eswaramoorthy <pavithraes@outlook.com>
1 parent 0cb205f commit c527344

File tree

6 files changed

+488
-39
lines changed

6 files changed

+488
-39
lines changed
Lines changed: 3 additions & 0 deletions
Loading

docs/examples/gallery_streaming.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,7 @@ def answer(self, prompt, sources):
9999

100100
rest_api = ragna_docs.RestApi()
101101

102-
client = rest_api.start(config, authenticate=True)
103-
104-
# %%
105-
# Upload the document.
106-
107-
document_upload = (
108-
client.post("/document", json={"name": document_path.name})
109-
.raise_for_status()
110-
.json()
111-
)
112-
113-
document = document_upload["document"]
114-
115-
parameters = document_upload["parameters"]
116-
client.request(
117-
parameters["method"],
118-
parameters["url"],
119-
data=parameters["data"],
120-
files={"file": open(document_path, "rb")},
121-
).raise_for_status()
102+
client, document = rest_api.start(config, authenticate=True, upload_document=True)
122103

123104
# %%
124105
# Start and prepare the chat
@@ -173,6 +154,6 @@ def answer(self, prompt, sources):
173154

174155
# %%
175156
# Before we close the example, let's stop the REST API and have a look at what would
176-
# have printed in the terminal if we had started it the regular way.
157+
# have printed in the terminal if we had started it with the `ragna api` command.
177158

178159
rest_api.stop()

docs/references/config.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ There are two main ways to generate a configuration file:
3333
## Referencing Python objects
3434

3535
Some configuration options reference Python objects, e.g.
36-
`document = ragna.core.LocalDocument`. You can inject your own objects here and do not
37-
need to rely on the defaults by Ragna. To do so, make sure that the module the object is
38-
defined in is on the
39-
[`PYTHONPATH`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH). The
40-
`document` configuration mentioned before internally is roughly treated as
36+
`document = ragna.core.LocalDocument`. Internally, this is roughly treated as
4137
`from ragna.core import LocalDocument`.
4238

39+
You can inject your own objects here and do not need to rely on the defaults by Ragna.
40+
To do so, make sure that the module the object is defined in is on
41+
[Python's search path](https://docs.python.org/3/library/sys.html#sys.path). There are
42+
multiple ways to achieve this, e.g.:
43+
44+
- Install your module as part of a package in your current environment.
45+
- Set the [`PYTHONPATH`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH)
46+
environment variable to include the directory your module is located in.
47+
4348
## Environment variables
4449

45-
All configuration options can be set or overritten by environment variables by using the
50+
All configuration options can be set or overridden by environment variables by using the
4651
`RAGNA_` prefix. For example, `document = ragna.core.LocalDocument` in the configuration
4752
file is equivalent to setting `RAGNA_DOCUMENT=ragna.core.LocalDocument`.
4853

0 commit comments

Comments
 (0)