Skip to content

Commit b3d0f33

Browse files
add doc for how it works, installation, initial setup, presets, python module
1 parent 6649cc1 commit b3d0f33

File tree

5 files changed

+266
-1
lines changed

5 files changed

+266
-1
lines changed

docs/how_it_works.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
===============================================
2+
How it works
3+
===============================================
4+
5+
6+
-----------------------------------------------
7+
Running/help
8+
-----------------------------------------------
9+
10+
Get a quick response for one question:
11+
12+
.. image:: https://user-images.githubusercontent.com/43772/249005656-61d79840-8778-4cbd-a229-a0227664cab6.png
13+
:alt: Get a quick response for one question
14+
15+
Run an interactive CLI in the terminal:
16+
17+
.. image:: https://user-images.githubusercontent.com/43772/249005677-097054b7-cd4d-4a07-b297-e1bdb3251998.png
18+
:alt: Run an interactive CLI in the terminal
19+
20+
Get help for a command:
21+
22+
.. image:: https://github.com/mmabrouk/chatgpt-wrapper/assets/43772/1949ffa0-88fe-4292-8437-d7e26bbe7641
23+
:alt: Get help for a command
24+
25+
26+
-----------------------------------------------
27+
Conversations
28+
-----------------------------------------------
29+
30+
Start a new conversation:
31+
32+
.. image:: https://user-images.githubusercontent.com/43772/249010438-d5573aff-6e93-4513-971b-78eb1c2ce961.png
33+
:alt: Start a new conversation
34+
35+
Show last ten of conversation history:
36+
37+
.. image:: https://user-images.githubusercontent.com/43772/249006268-674f1adf-d2ce-4535-a60a-4091a6c6876b.png
38+
:alt: Show last ten of conversation history
39+
40+
Switch to and show an old conversation:
41+
42+
.. image:: https://user-images.githubusercontent.com/43772/249010278-16411fa5-9076-46a3-a9fc-99aa6214b275.png
43+
:alt: Switch to and show an old conversation
44+
45+
46+
-----------------------------------------------
47+
Models/presets
48+
-----------------------------------------------
49+
50+
Show configuration of the current model:
51+
52+
.. image:: https://user-images.githubusercontent.com/43772/249006279-9e6c415a-b3a7-4cb7-866f-e5434329e128.png
53+
:alt: Show configuration of the current model
54+
55+
Set custom temperature on the current model:
56+
57+
.. image:: https://user-images.githubusercontent.com/43772/249006308-f649bf90-71f0-4df9-b0dc-b677afe33db1.png
58+
:alt: Set custom temperature on the current model
59+
60+
List available presets:
61+
62+
.. image:: https://user-images.githubusercontent.com/43772/249006327-7bcd203d-8d59-48b7-98bb-0b9a84f8f955.png
63+
:alt: List available presets
64+
65+
Show configuration of the current preset:
66+
67+
.. image:: https://user-images.githubusercontent.com/43772/249006348-88746adc-cf42-47aa-91a8-dfe000ea35e3.png
68+
:alt: Show configuration of the current preset
69+
70+
71+
-----------------------------------------------
72+
Templates
73+
-----------------------------------------------
74+
75+
List available templates:
76+
77+
.. image:: https://user-images.githubusercontent.com/43772/249006368-22596be0-b85b-4a53-94fe-5799bd91255c.png
78+
:alt: List available templates
79+
80+
Run a template and provide input:
81+
82+
.. image:: https://user-images.githubusercontent.com/43772/249006386-9877218d-5112-46cd-9d89-d3a892515110.png
83+
:alt: Run a template and provide input
84+
85+
86+
-----------------------------------------------
87+
Workflows
88+
-----------------------------------------------
89+
90+
List available workflows:
91+
92+
.. image:: https://user-images.githubusercontent.com/43772/249006404-9b3454f7-4b86-42fd-995a-233b1d52945d.png
93+
:alt: List available workflows
94+
95+
Show a workflow:
96+
97+
.. image:: https://user-images.githubusercontent.com/43772/249006985-bd92f8c2-a19b-4f2e-9508-9d6875a2672a.png
98+
:alt: Show a workflow
99+
100+
Run a workflow:
101+
102+
.. image:: https://user-images.githubusercontent.com/43772/249007169-3917cc85-5bbe-4e87-9f95-f3ab65a1e915.png
103+
:alt: Run a workflow
104+
105+
See :ref:`python_module_doc` for details on using LWE as an API from Python.

docs/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ At its heart, LWE has four main components:
2929
* Save LLM interactions to conversations
3030

3131

32-
3332
.. toctree::
3433
:hidden:
3534
:maxdepth: 2
3635
:caption: Contents:
3736

37+
how_it_works
3838
installation
39+
initial_setup
40+
presets
41+
python_module
3942
modules
4043

4144

docs/initial_setup.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
===============================================
2+
Initial setup
3+
===============================================
4+
5+
6+
-----------------------------------------------
7+
API keys
8+
-----------------------------------------------
9+
10+
Grab an OpenAI API key from https://platform.openai.com/account/api-keys
11+
12+
Export the key into your local environment:
13+
14+
.. code-block:: bash
15+
16+
export OPENAI_API_KEY=<API_KEY>
17+
18+
Windows users, see `here <https://www.computerhope.com/issues/ch000549.htm>`_ for how to edit environment variables.
19+
20+
To tweak the configuration for the current profile, see [Configuration](#configuration)
21+
22+
23+
-----------------------------------------------
24+
Default configuration
25+
-----------------------------------------------
26+
27+
LWE comes with sensible configuration defaults, and most users can start using it immediately.
28+
29+
Still, it's a good idea to know how to view the configuration.
30+
31+
From the command line, simply run:
32+
33+
.. code-block:: bash
34+
35+
lwe config
36+
37+
38+
-----------------------------------------------
39+
Database
40+
-----------------------------------------------
41+
42+
The API backend requires a database server to store conversation data. The wrapper leverages `SQLAlchemy <https://www.sqlalchemy.org/>`_ for this.
43+
44+
The simplest supported database is `SQLite <https://www.sqlite.org/>`_ (which is already installed on most modern operating systems), but you can use any database that is supported by SQLAlchemy.
45+
46+
Check the `database` setting from the :ref:`Default configuration`, which will show you the currently configured connection string for a default SQLite database.
47+
48+
If you're happy with that setting, nothing else needs to be done -- the database will be created automatically in that location when you run the program.
49+
50+
51+
-----------------------------------------------
52+
Initial user creation and login
53+
-----------------------------------------------
54+
55+
Once the database is configured, run the program with no arguments:
56+
57+
.. code-block:: bash
58+
59+
lwe
60+
61+
It will recognize no users have been created, and prompt you to create the first user:
62+
63+
* **Username:** Required, no spaces or special characters
64+
* **Email:** Optional
65+
* **Password:** Optional, if not provided the user can log in without a password
66+
67+
Once the user is created, execute the ``/login`` command with the username:
68+
69+
.. code-block:: bash
70+
71+
/login [username]
72+
73+
Once you're logged in, you have full access to all commands.
74+
75+
**IMPORTANT NOTE:** The user authorization system from the command line is *admin party* -- meaning every logged in user has admin privileges, including editing and deleting other users.
76+
77+
78+
-----------------------------------------------
79+
Setting a per-user default preset
80+
-----------------------------------------------
81+
82+
LWE supports configuring a default preset per user.
83+
84+
To do so, run ``/user-edit`` -- selecting a default preset will be one of the options.
85+
86+
See :ref:`presets_doc` for more information on configuring presets.

docs/presets.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. _presets_doc:
2+
3+
===============================================
4+
Presets
5+
===============================================
6+
7+
Presets allow you to conveniently manage various provider/model configurations.
8+
9+
As you use the CLI, you can execute a combination of ``/provider`` and ``/model``
10+
commands to set up a provider/model configuration to your liking.
11+
12+
Once you have the configuration set up, you can 'capture' it by saving it as a
13+
preset.
14+
15+
To save an existing configuration as a preset:
16+
17+
.. code-block:: bash
18+
19+
/preset-save mypresetname
20+
21+
Later, to load that configuration for use:
22+
23+
.. code-block:: bash
24+
25+
/preset-load mypresetname
26+
27+
See ``/help`` for the various other preset commands.

docs/python_module.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _python_module_doc:
2+
3+
===============================================
4+
Python module
5+
===============================================
6+
7+
You can use the ``ApiBackend`` class to interact directly with the LLMs.
8+
9+
Create an instance of the class and use the ``ask`` method to send a message to the LLM and receive the response. For example:
10+
11+
.. code-block:: python
12+
13+
from lwe import ApiBackend
14+
15+
bot = ApiBackend()
16+
success, response, message = bot.ask("Hello, world!")
17+
if success:
18+
print(response)
19+
else:
20+
raise RuntimeError(message)
21+
22+
The ``ask`` method takes a string argument representing the message to send to the LLM, and returns a tuple with the following values:
23+
24+
#. ``success``: Boolean indicating whether the operation succeeded.
25+
#. ``response``: An object representing the response received *(usually just a string response from the LLM)*
26+
#. ``message``: User message describing the outcome of the operation.
27+
28+
You may also stream the response as it comes in from the API using the ``ask_stream`` method.
29+
30+
To pass custom configuration to the ``ApiBackend``, use the ``Config`` class:
31+
32+
.. code-block:: python
33+
34+
from lwe import ApiBackend
35+
from lwe.core.config import Config
36+
37+
config = Config()
38+
config.set('debug.log.enabled', True)
39+
bot = ApiBackend(config)
40+
success, response, message = bot.ask("Hello, world!")
41+
if success:
42+
print(response)
43+
else:
44+
raise RuntimeError(message)

0 commit comments

Comments
 (0)