Metadata-Version: 2.1
Name: genai_rest_builder
Version: 0.2.0
Summary: A tool to generate python code with GenAI RestAPIs.
Author-email: Biprajeet Kar <biprokvs@gmail.com>
Maintainer-email: Biprajeet Kar <biprokvs@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Biprajeet Kar
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: click


# GenAI REST Builder

The **GenAI REST Builder** is a tool for rapidly creating RESTful services around AI models, allowing you to define service configurations in a YAML file and generate a FastAPI-based project structure to deploy AI-powered endpoints.

## Key Features

- **Service Configuration with Custom Prompts**: Easily define each service's prompt, model configuration, and provider-specific details in YAML format.
- **Cloud Provider Compatibility**: Supports major providers, including AWS and Azure, to integrate directly with cloud-based AI services.
- **Automated Code and Endpoint Generation**: Generates FastAPI service endpoints, configuration files, and utility scripts based on YAML specifications.

## Installation

1. **Install the GenAI REST Builder Tool**:

   Begin by installing the `genai-rest-builder` package:

   ```bash
   pip install pyyaml genai-rest-builder
   ```

2. **Generate Project Structure**:

   Use the command below to generate the project structure with REST APIs for all defined services based on the YAML configuration file:

   ```bash
   genai-rest-proj-build
   ```

   This reads from `prompt_service.yaml` (to be created by the user with service definitions) and generates the required project files, configurations, and the main FastAPI application.

3. **Install Project Dependencies**:

   After generating the project structure, install the necessary dependencies:

   ```bash
   pip install -r requirements.txt
   ```

4. **Run the Server**:

   Launch the FastAPI server with `serve_app.py`:

   ```bash
   python serve_app.py
   ```

   By default, the server runs on `localhost:8080` unless overridden in the `.env` file.

## Example YAML - `prompt_service.yaml` Configuration File

Below is an example structure for defining services in the YAML configuration file:

```yaml
PromptServices:
  - <servicename>:
      prompt: <prompt template>
      model:
        provider: [aws, azure]
        modelId: <model id>
        temperature: <temperature>
        maxTokens: <maximum tokens>
        apiVersion: <api version>  # Required for Azure provider
```

### YAML Configuration Details

- **servicename**: Unique identifier for the service.
- **prompt**: Template text for the AI model’s prompt.
- **model**: Contains model details:
  - **provider**: Cloud provider (`aws` or `azure`).
  - **modelId**: Identifier for the specific model.
  - **temperature**: Controls the randomness of the model's output.
  - **maxTokens**: Maximum tokens to be generated by the model.
  - **apiVersion**: _(Azure only)_ Specifies the API version of the Azure model.

## Project Structure

After running the project build command, the following structure will be created:

```
.
├── service_chains/
│   ├── <servicename>_chain.py           # Generated chain files for each service
│   ├── utils.py                         # Helper functions to load service configurations
│   ├── __init__.py                      # Package initialization file
├── serve_app.py                         # Main FastAPI application
├── .env                                 # Environment configuration file with host/port settings
├── requirements.txt                     # Project dependencies file
├── prompt_service.yaml                  # YAML configuration file (user-defined)
```

## Accessing API Documentation

Once the server is running, OpenAPI documentation is available at:

```
http://<GENAI_SERVER_HOST>:<GENAI_SERVER_PORT>/docs
```

This page provides an interactive interface to test and explore the API endpoints.

## Invoking Services

Each service can be accessed via a unique REST API path based on the service name:

```
http://<GENAI_SERVER_HOST>:<GENAI_SERVER_PORT>/<service>
```

Replace `<service>` with the name specified in the YAML configuration file to send requests to the corresponding service.
