Skip to content

Commit 97d061d

Browse files
committed
Update docs
1 parent 06ce367 commit 97d061d

File tree

19 files changed

+362
-97
lines changed

19 files changed

+362
-97
lines changed

docs/api-reference.rst

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
API Reference
22
======
3+
4+
Module: common
5+
------
6+
7+
.. autosummary::
8+
9+
danoan.llm_assistant.common.config
10+
danoan.llm_assistant.common.model
11+
danoan.llm_assistant.common.exception
12+
13+
14+
Module: prompt
15+
------
16+
17+
.. autosummary::
18+
19+
danoan.llm_assistant.prompt.core.api
20+
danoan.llm_assistant.prompt.core.model
21+
danoan.llm_assistant.prompt.core.utils
22+
23+
24+
Module: runner
25+
------
26+
327
.. autosummary::
4-
:toctree generated
528

6-
<danoan.llm_assistant.core.api
7-
danoan.llm_assistant.core.cli_drawer
8-
danoan.llm_assistant.core.exception
9-
danoan.llm_assistant.core.model
10-
danoan.llm_assistant.core.task_runner
29+
danoan.llm_assistant.runner.core.api
30+
danoan.llm_assistant.runner.core.exception

docs/getting-started.md

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,177 @@
11
# Getting started with LLM Assistant
22

3-
Collection of simple LLM applications
3+
Collection of tools to work with LLMs.
44

55
## Features
66

7+
- CLI for interactive prompt execution.
8+
- Prompt versioning tool.
9+
- Prompt definition format and general runner.
710

8-
## Examples
11+
12+
## How to use
13+
14+
### Configuring a LLM provider
15+
16+
The first step is to create a `llm-assistannt-config.toml` file
17+
to hold runner and prompt settings.
18+
19+
```toml
20+
[runner]
21+
openai_key = "<OPENAI_KEY>"
22+
model = "gpt-3.5-turbo"
23+
use_cache = true
24+
cache_path = "/home/user/.config/llm-assistant/cache.db"
25+
26+
[prompt]
27+
git_user = "danoan-prompts"
28+
prompt_collection_folder = "/home/user/.config/llm-assistant/cache.db"
29+
30+
[prompt.versioning]
31+
alternative-expression = "v2.0.0"
32+
word-definition = "v1.0.0"
33+
```
34+
35+
**Configuration file search**: The application backtracks the current working directory searching for the
36+
`llm-assistant-config.toml` file starting from CWD. If not such file is found, it searches in the location
37+
specified by the environment variable `LLM_ASSISTANT_CONFIGURATION_FOLDER`.
38+
39+
You can check which configuration file is being used by running
40+
41+
```bash
42+
llm-assistant setup
43+
```
44+
45+
46+
### Running a prompt
47+
48+
Consider the `alternative-expression` prompt configuration file:
49+
50+
```toml
51+
name="Alternative Expressions"
52+
system_prompt='''
53+
You are fluent speaker of the {language} language and your task is to list at most five expressions that encodes the meaning of a sentence or a word enclosed by double angle brackets.
54+
55+
Your response must be given as a json list and the items must be written in {language}.
56+
57+
Examples
58+
--------
59+
60+
Language: English.
61+
Sentence: <<It is an unusual day today.>>
62+
Response: [
63+
"It is an odd day today",
64+
"Today is quite unusual",
65+
"It is an atypical day",
66+
"Today feels out of the ordinary",
67+
"Today stands out differently"
68+
]
69+
--
70+
71+
Language: french
72+
Sentence: <<gentil>>
73+
Response: [
74+
"aimable",
75+
"doux"
76+
]
77+
--
78+
79+
'''
80+
user_prompt='''
81+
Language: {language}
82+
Sentence: <<{message}>>
83+
Response:
84+
'''
85+
```
86+
87+
It is possible to run the prompt in three different ways
88+
89+
```bash
90+
echo "{}" | llm-assistant run alternative-expression --p language portuguese --p message "ganhar a vida"
91+
echo '{"message":"ganhar a vida"}' | llm-assistant run alternative-expression --p language portuguese
92+
echo '{"message":"ganhar a vida", "language":"portuguese"}' | llm-assistant run alternative-expression
93+
```
94+
95+
### Starting an interactive session
96+
97+
To start an interactive session, type:
98+
99+
```bash
100+
llm-assistant session
101+
```
102+
103+
You are invited to select one of the prompts located at `prompt.prompt_collection_folder` and then to load or
104+
create a new instance for the prompt.
105+
106+
**Prompt Instance**: A prompt instance is a subset of pre-defined prompt variables. For example, in the alternative-expression
107+
prompt, we could have a french instance (language=french) and a portuguese instance (language=portuguese).
108+
109+
```bash
110+
╭────────────────────────────────────────────────────────────────────────────────────────╮
111+
│ Select prompt │
112+
╰────────────────────────────────────────────────────────────────────────────────────────╯
113+
1. Alternative Expressions 2. Word Definition
114+
115+
Prompt index: 2
116+
╭────────────────────────────────────────────────────────────────────────────────────────╮
117+
│ Choose an option │
118+
╰────────────────────────────────────────────────────────────────────────────────────────╯
119+
1. New instance 2. Load instance
120+
121+
Option index: 1
122+
Enter the instance name: portuguese
123+
Enter variable assignment: language=portuguese
124+
╭─────────────────────────────────────── New Chat ───────────────────────────────────────╮
125+
│ Prompt: Word Definition │
126+
│ Instance:portuguese │
127+
╰────────────────────────────────────────────────────────────────────────────────────────╯
128+
Enter messaó
129+
Enter message: $$
130+
╭───────────────────────────── Word Definition::portuguese ─────────────────────────────╮
131+
│ borogodó │
132+
╰───────────────────────────────────────────────────────────────────────────────────────╯
133+
╭───────────────────────────── Word Definition::portuguese ─────────────────────────────╮
134+
│ [ │
135+
"Encanto, atração irresistível e misteriosa; charme", │
136+
"Qualidade ou característica que atrai e seduz de maneira peculiar ou especial.", │
137+
"Dom, habilidade natural para seduzir ou encantar as pessoas.", │
138+
"Magia, feitiço; algo que exerce influência sobre os outros de forma inexplicável."
139+
│ ] │
140+
╰───────────────────────────────────────────────────────────────────────────────────────╯
141+
```
142+
143+
### Syncing prompts
144+
145+
The `sync` feature allows to fetch the most recent updates from the remote prompt repository
146+
and to update the local view.
147+
148+
```bash
149+
prompt-manager sync
150+
```
151+
152+
The synchronization is done according with the `prompt.versioning` settings.
153+
154+
```toml
155+
[prompt]
156+
git_user = "danoan-prompts"
157+
prompt_collection_folder = "/home/user/.config/llm-assistant/cache.db"
158+
159+
[prompt.versioning]
160+
alternative-expression = "v2.0.0"
161+
word-definition = "v1.0.0"
162+
```
163+
164+
For the settings above, the sync will seach for the repositories:
165+
166+
- danoan-prompts/alternative-expression
167+
- danoan-prompts/word-definition
168+
169+
on github and then fetch the specified version.
170+
171+
### Push prompt version assistant
172+
173+
The `prompt-manager versioning push` commands guides the user to the creation of a
174+
new prompt version.
9175

10176

11177
## Contributing

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ How-to guides
1717
.. toctree::
1818
:maxdepth: 1
1919

20-
how-to/
20+
how-to/setup-assistant
21+
how-to/run-a-prompt
22+
how-to/sync-and-push-prompts
2123

2224

2325
Reference guides

src/danoan/llm_assistant/common/config.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
from danoan.llm_assistant.common import exception, model
2-
1+
"""
2+
LLM-assistant configuration API.
3+
"""
34

4-
from functools import lru_cache
55
import logging
66
import os
7-
from pathlib import Path
87
import sys
9-
import toml
8+
from functools import lru_cache
9+
from pathlib import Path
1010
from typing import Optional
1111

12+
import toml
13+
14+
from danoan.llm_assistant.common import exception, model
15+
1216
logger = logging.getLogger(__file__)
1317
handler = logging.StreamHandler(sys.stderr)
1418
handler.setLevel(logging.DEBUG)
@@ -34,7 +38,6 @@ def _get_first_configuration_filepath_within_file_hierarchy(
3438
"""
3539
visited = set()
3640
folders_to_visit = [base_dir]
37-
print(base_dir)
3841
while len(folders_to_visit) > 0:
3942
cur_folder = folders_to_visit.pop()
4043
if cur_folder in visited:
@@ -79,6 +82,21 @@ def get_configuration_folder() -> Path:
7982
raise exception.EnvironmentVariableNotDefinedError()
8083

8184

85+
def get_environment_variable_value() -> Path:
86+
f"""
87+
Return the value stored by {LLM_ASSISTANT_ENV_VARIABLE}.
88+
89+
Raises:
90+
EnvironmentVariableNotDefinedError: If the LLM_ASSISTANT_ENV_VARIABLE
91+
is not defined and a configuration file
92+
is not found in the file hierarchy
93+
"""
94+
if LLM_ASSISTANT_ENV_VARIABLE in os.environ:
95+
return Path(os.environ[LLM_ASSISTANT_ENV_VARIABLE]).expanduser()
96+
97+
raise exception.EnvironmentVariableNotDefinedError()
98+
99+
82100
def get_configuration_filepath() -> Path:
83101
"""
84102
Return path to llm-assistant configuration file.
@@ -95,21 +113,29 @@ def get_configuration() -> model.LLMAssistantConfiguration:
95113
raise exception.ConfigurationFileDoesNotExistError()
96114

97115
with open(config_filepath, "r") as f:
98-
return model.LLMAssistantConfiguration(**toml.load(f))
116+
return model.LLMAssistantConfiguration.from_dict(**toml.load(f))
99117

100118

101119
def get_prompt_configuration(prompt_name: str) -> model.PromptConfiguration:
102120
"""
103121
Get prompt configuration object.
104122
105123
It searches the prompt configuration file within the directory specified
106-
by runner.local_folder setting.
124+
by runner.prompt_collection_folder setting.
107125
108126
Raises:
109127
FileNotFoundError: if prompt configuration file is not found.
110128
"""
111129
config = get_configuration()
112-
prompt_config_filepath = config.runner.local_folder / prompt_name / "config.toml"
130+
if config.prompt:
131+
prompt_config_filepath = (
132+
config.prompt.prompt_collection_folder / prompt_name / "config.toml"
133+
)
134+
else:
135+
raise FileNotFoundError(
136+
2, "File not found", "prompt collection folder is not specified"
137+
)
138+
113139
if not prompt_config_filepath.exists():
114140
raise FileNotFoundError(2, "File not found", prompt_config_filepath)
115141
with open(prompt_config_filepath) as f:

src/danoan/llm_assistant/common/exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Shared exceptions between prompt and runner modules.
3+
"""
4+
5+
16
class EnvironmentVariableNotDefinedError(Exception):
27
pass
38

0 commit comments

Comments
 (0)