Skip to content

Commit

Permalink
add async docs
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Apr 27, 2024
1 parent 8cf9f80 commit d53402f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Docs are available [here](https://masci.github.io/banks/).
- [Go meta: create a prompt and `generate` its response](#go-meta-create-a-prompt-and-generate-its-response)
- [Go meta(meta): process a LLM response](#go-metameta-process-a-llm-response)
- [Reuse templates from files](#reuse-templates-from-files)
- [Async support](#async-support)
- [License](#license)

## Installation
Expand Down Expand Up @@ -276,6 +277,24 @@ topic = "retrogame computing"
print(p.text({"topic": topic}))
```

### Async support

To run banks within an `asyncio` loop you have to do two things:
1. set the environment variable `BANKS_ASYNC_ENABLED=true`.
2. use the `AsyncPrompt` class that has an awaitable `run` method.

Example:
```python
from banks import AsyncPrompt

async def main():
p = AsyncPrompt.from_template("blog.jinja")
result = await p.text({"topic": "AI frameworks"})
print(result)

asyncio.run(main())
```

## License

`banks` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
17 changes: 17 additions & 0 deletions docs/async.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Async support

To run banks within an `asyncio` loop you have to do two things:
1. set the environment variable `BANKS_ASYNC_ENABLED=true`.
2. use the `AsyncPrompt` class that has an awaitable `run` method.

Example:
```python
from banks import AsyncPrompt

async def main():
p = AsyncPrompt.from_template("blog.jinja")
result = await p.text({"topic": "AI frameworks"})
print(result)

asyncio.run(main())
```
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ are replaced by actual data provided by the user.
## Features

* Banks currently supports all the features from Jinja2, see [Template Designer Documentation](https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.truncate).
* [Filters](filters.md): useful to manipulate the text during template rendering.
* [Extensions](extensions.md): useful to support custom functions (e.g. text generation via OpenAI).
* [Macros](macros.md): useful to implement complex logic in the template itself instead of Python code.
* [Filters](prompt.md#filters): useful to manipulate the text during template rendering.
* [Extensions](prompt.md#extensions): useful to support custom functions (e.g. text generation via OpenAI).
* [Macros](prompt.md#macros): useful to implement complex logic in the template itself instead of Python code.

## Installation

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nav:
- Home: 'index.md'
- Python API: 'python.md'
- Prompt API: 'prompt.md'
- asyncio support: 'async.md'

plugins:
- search
Expand Down

0 comments on commit d53402f

Please sign in to comment.