Skip to content

Commit

Permalink
Update documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aboubakar authored and Zorin95670 committed Dec 3, 2024
1 parent d88103a commit f626940
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 43 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DECRYPTION_KEY=123456789
103 changes: 77 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ In order to handle a new AI, you need to add it to:
- Create a new handler in `handlers` folder and in the new handler class should inherit from `BaseHandler`.
- Currently you need to implement the `generate` method.
- Add the new handler in the factory `handlers/Factory.py`.
- Add a section in `configuration/configurationManager.py` with the name of the new AI and its settings.
- Add a file called `configuration_description.json` that will describe the new AI settings and how to configure it.

### Example of Handler

Expand Down Expand Up @@ -129,46 +129,97 @@ class Factory:

### Example of configuration

Finally, you need to add the new AI in the `configuration.json` file.
Finally, you will have a `configuration` similar to:

```json
{
"pluginPreferences":{
"default": "ollama"
},
"ai-models":{
"ollama":
{
"base_url": "http://localhost:11434/api",
"models": ["mistral"],
"defaultModel": "mistral",
"modelFiles": {
"generate": {
"default": "default-mistral-modelfile_generate",
"@ditrit/kubernator-plugin": "default-kubernetes-mistral-modelfile_generate",
"@ditrit/githubator-plugin": "default-githubactions-mistral-modelfile_generate"
},
"message": {
"default": "default-mistral-modelfile_message",
"@ditrit/kubernator-plugin": "default-kubernetes-mistral-modelfile_message",
"@ditrit/githubator-plugin": "default-githubactions-mistral-modelfile_message"
}
"ollama":
{
"base_url": "http://localhost:11434/api",
"models": ["mistral"],
"defaultModel": "mistral",
"modelFiles": {
"generate": {
"default": "default-mistral-modelfile_generate",
"@ditrit/kubernator-plugin": "default-kubernetes-mistral-modelfile_generate",
"@ditrit/githubator-plugin": "default-githubactions-mistral-modelfile_generate"
},
"message": {
"default": "default-mistral-modelfile_message",
"@ditrit/kubernator-plugin": "default-kubernetes-mistral-modelfile_message",
"@ditrit/githubator-plugin": "default-githubactions-mistral-modelfile_message"
}
},
"MyAI": {
"base_url": "http://localhost:8080/api",
"otherSetting": "value"
}
}
},
"MyAI": {
"base_url": "http://localhost:8080/api",
"otherSetting": "value"
}
}
```

A configuration_description.json file is essential for integrating any AI system with Leto-Modelizer-Admin, as it defines the fields administrators must fill out to configure the AI properly.

Here are the description of the configuration fields:

- **`handler`**
- **Purpose**: Identifies the AI system or plugin this configuration belongs to (e.g., "ollama").
- **Use**: Associates the field with a specific handler or module.

- **`key`**
- **Purpose**: A unique identifier for the field used internally by the system.
- **Use**: Represents the configuration parameter (e.g., `base_url`, `defaultModel`).

- **`type`**
- **Purpose**: Specifies the type of input expected in the UI.
- **Values**:
- `"text"`: Single-line text input.
- `"select"`: To create a dropdown menu.
- `"textarea"`: Multi-line input for longer text.

- **`values`**
- **Purpose**: Defines predefined selectable options (e.g., dropdown menu).
- **Use**: Empty if free-form input is allowed; can be populated for fixed choices.

- **`defaultValue`**
- **Purpose**: The pre-filled value shown to the user when the field is displayed.
- **Use**: Ensures default configurations or suggested values are provided (e.g., `http://localhost:11434/api`).

- **`label`**
- **Purpose**: The user-facing name of the field displayed in the UI.
- **Use**: Briefly explains what the field represents (e.g., "Ollama server URL").

- **`title`**
- **Purpose**: A short explanatory tooltip shown when hovering over the field in the UI.
- **Use**: Provides additional context (e.g., "Define the URL of the Ollama server").

- **`description`**
- **Purpose**: A detailed explanation of the field's purpose or expected input.
- **Use**: Guides users on how to fill the field, especially for complex settings.

- **`pluginDependent`**
- **Purpose**: Indicates whether the field is specific to a plugin.
- **Values**:
- `true`: Applies only to a specific plugin (e.g., plugin-specific instructions).
- `false`: Applies globally.

- **`required`**
- **Purpose**: Specifies if the field must be completed for the configuration to be valid.
- **Values**:
- `true`: Field is mandatory.
- `false`: Field is optional.


See the `configuration_description.json` of Ollama for an example.

### Adding a new Ollama model file

First add your modelfile in the `src/handlers/Ollama/ModelFiles` folder.
You can find how to create your model file [here](https://github.com/ollama/ollama/blob/main/docs/modelfile.md)

Then add your model file in the `configuration.json` file, in the `ai-models.ollama.modelFiles` section.
Then add your model file in the `description_configuration.json` file, then through Leto-Modelizer-Admin you can configure it.

## How to launch e2e tests with Behave

Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ Built on top of Python's robust web framework, the Leto-Modelizer Proxy API offe

Currently this project use Ollama or Gemini in order to generate code.

## .env

In order to configure the API, you need to create a `.env` file in the root of the project.
You can find an example of this file [here](.env.example).

The `.env` file should contain the following variables:

| Variable | Description |
| -------------- | ------------------------------------ |
| DECRYPTION_KEY | Key for decrypting the configuration |


## Configuration

To configure the API, you need to edit the `configuration/configuration.json` file (default location).
Or you can set the environment variables `API_CONFIGURATION` and put the `configuration.json` file in that path`.
To configure the Proxy API, you need to have the **Leto-Modelizer-Admin running**.
Then, you have to go in the 'AI settings' section to configure the Proxy API.

Currently the configuration has the following settings:

Expand All @@ -26,7 +38,7 @@ Currently the configuration has the following settings:
| ollama | A dictionary containing the ollama configuration (cf: next section). |
| Gemini | A dictionary containing the Gemini configuration (cf: next section). |

Here is an example of the `configuration.json` file:
Here is an example of the `configuration`:

```json
{
Expand Down Expand Up @@ -71,7 +83,8 @@ Here is an example of the `configuration.json` file:
```

The mandatory `default` key is used to specify which AI model to use by default for every plugin.
Moreover, the AI precised for each plugin in the `pluginPreferences` key must exist in the `configuration.json`.
Moreover, the AI precised for each plugin in the `pluginPreferences` key must exist in the configuration.


### Ollama

Expand All @@ -90,7 +103,7 @@ Currently only the default model is used. But later, we will be able to handle m
### Gemini

Gemini can be found here: https://github.com/google-gemini/
**Don't forget to set the `key` in the `configuration.json` by creating an account and getting an API key.**
**Don't forget to set the `key` in the configuration by creating an account and getting an API key.**
Gemini has the following settings:

| Setting | Description |
Expand Down Expand Up @@ -137,7 +150,7 @@ cf: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/ins
### Gemini API

For Gemini, you need to create an account and get an API key, on this website: https://ai.google.dev/
Then you just need to add it in the `configuration.json` file, in the `ai-models` section.
Then you just need to add it in the `configuration`, in the `gemini` section of the Leto-Modelizer-Admin.


## How to launch the API using hypercorn
Expand Down Expand Up @@ -206,8 +219,9 @@ docker build -t leto-modelizer-ai-proxy .
Then run the image:

```sh
docker compose up -f docker-compose-nvidia.yaml
docker compose --env-file .env -f docker-compose-nvidia.yaml up
```
**NOTE:** Even using Ollama with docker, you have to pull the model files first (connect to the container then) using the command ```ollama pull mistral```.

### Without NVIDIA GPU

Expand All @@ -220,7 +234,7 @@ docker build -t leto-modelizer-ai-proxy .
Then run the image:

```sh
docker compose up -f docker-compose.yaml
docker compose --env-file .env -f docker-compose.yaml up
```

The initialize script initializes everything the handlers needs in order to work (for instance the Ollama handler needs to be initialized with the model files).
Expand All @@ -231,6 +245,7 @@ python3 initialize.py
Once your docker is running and initialized, you can request it on this url: ```http://localhost:8585/```

**NOTE:** You do not need to launch the initialize script everytime you launch the API with docker, once is enough since it target the AI (i.e model files for Ollama).
**NOTE:** Even using Ollama with docker, you have to pull the model files first (connect to the container then) using the command ```ollama pull mistral```.

## Endpoint

Expand Down
24 changes: 15 additions & 9 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Added

- Configuration is now handle through the Leto-Modelizer-Admin, the user give the configuration for the AIs and not through the file anymore.

## [1.0.0] - 2024/10/15

### Added

- Setup the project
- Create Ollama handler in order to generate code through the /api/diagram route
- Handle Modelfiles for Ollama (terraform, kubernetes and github actions)
- Migrate to python 3.12
- Migrate from uvicorn to hypercorn
- Add new Ollama model files (for generate and message)
- Handle new /api/message endpoint for Ollama, that send messages to the Ollama AI and get a response with the associated context
- Setup the project.
- Create Ollama handler in order to generate code through the /api/diagram route.
- Handle Modelfiles for Ollama (terraform, kubernetes and github actions).
- Migrate to python 3.12.
- Migrate from uvicorn to hypercorn.
- Add new Ollama model files (for generate and message).
- Handle new /api/message endpoint for Ollama, that send messages to the Ollama AI and get a response with the associated context.
- Added new Gemini model files (for generate and message). Conversation with a context is not supported.
- Added Docker compose (works only with nvidia gpu)
- Added Docker compose (works only with nvidia gpu).
- The initialize script is now separated from the main script. It can be launched from the root folder, anytime.
- Add health endpoint
- Add health endpoint.

[1.0.0]: https://github.com/ditrit/leto-modelizer-ai-proxy/blob/main/changelog.md#1.0.0

0 comments on commit f626940

Please sign in to comment.