Skip to main content

A tool to generate python code with GenAI RestAPIs.

Project description

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:

    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:

    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:

    pip install -r requirements.txt
    
  4. Run the Server:

    Launch the FastAPI server with serve_app.py:

    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:

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/  
│   ├── base_chains/                     # Base and provider-specific chain definitions  
│   │   ├── base_chain.py                # Abstract base class for chains  
│   │   ├── aws_chain.py                 # AWS-specific chain implementation  
│   │   ├── azure_chain.py               # Azure-specific chain implementation  
│   │   ├── __init__.py                  # Exports for base_chains module  
│   ├── <servicename>_chain.py           # Service-specific chain implementation  
│   ├── utils.py                         # Utility functions for service configurations  
│   ├── __init__.py                      # Package initialization file for service_chains  
├── 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genai_rest_builder-0.2.1.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

genai_rest_builder-0.2.1-py3-none-any.whl (54.8 kB view details)

Uploaded Python 3

File details

Details for the file genai_rest_builder-0.2.1.tar.gz.

File metadata

  • Download URL: genai_rest_builder-0.2.1.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for genai_rest_builder-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3ac5732aa3db862b07ac5081781d78301a47fb5b5230eea181e10fb35ec8108a
MD5 1d0ebc0738fa1333a7a2add1a3d1f084
BLAKE2b-256 4aa29eea459bacff86cf557ff38b434ef3b45df4e7edda89e2e740c4356e5c0c

See more details on using hashes here.

File details

Details for the file genai_rest_builder-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for genai_rest_builder-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 790739609ca7c8c6eef469004c08da9474054f8e606dc2cf600fd7e5cc0a63f4
MD5 526b2f7434568e321e72cb977e0c8c23
BLAKE2b-256 40282a4e386c1fef9eda7cf1e1ad87751d58f3e2d9d054cb2df39b391af8c8a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page