A tool to generate python code with GenAI RestAPIs.
Project description
GenAI REST Builder
The GenAI REST Builder is a tool that helps create RESTful services around AI models using a YAML configuration file. It automates the setup of FastAPI endpoints, configurations, and environment files for easy deployment of AI-powered services.
Key Features
- Service Configuration with Custom Prompts: Define each service's prompt, model configuration, and provider-specific details in YAML format.
- Cloud Provider Compatibility: Supports major providers, including AWS and Azure.
- Automated Code Generation: Quickly create FastAPI service endpoints based on YAML configurations.
Installation
-
Install the GenAI REST Builder Tool:
Start by installing the
genai-rest-builder
package:pip install genai-rest-builder
-
Generate Project Structure:
Use the command below to generate the full project structure with REST APIs for all defined services based on your YAML configuration file:
genai-rest-proj-build
This reads from
prompt_service.yaml
(user needs to create it with prompt details) and creates a structured project with service files, configuration settings, and the main FastAPI application. -
Install Project Dependencies:
Once the project structure is generated, install the required dependencies:
pip install -r requirements.txt
-
Run the Server:
Launch the FastAPI server using
serve_app.py
:python serve_app.py
The server will start based on the host and port specified in the
.env
file, defaulting tolocalhost:8080
if not configured otherwise.
Example YAML - prompt_service.yaml
Configuration File
Here’s the structure of a sample YAML configuration file that defines services:
PromptServices:
- <servicename>:
prompt: <prompt template>
model:
provider: [aws, azure]
modelId: <model id>
temperature: <temperature>
maxTokens: <maximum tokens>
YAML Configuration Details
- servicename: Unique identifier for the service.
- prompt: Template for the AI model’s prompt.
- model: Contains model details such as:
- provider: Cloud provider (either
aws
orazure
). - modelId: ID for the specific model.
- temperature: Controls randomness in the output.
- maxTokens: Specifies the maximum tokens the model should generate.
- provider: Cloud provider (either
Project Structure
The following structure is generated after running the project build command:
.
├── service_chains/
│ ├── <servicename>_chain.py # Generated service chain files for each service
│ ├── __init__.py # Package initialization file
├── serve_app.py # Main FastAPI application
├── .env # Environment configuration file
├── requirements.txt # Dependencies file
├── prompt_service.yaml # YAML configuration file (user-defined)
Accessing API Documentation
After starting the server, the OpenAPI documentation is available at:
http://<GENAI_SERVER_HOST>:<GENAI_SERVER_PORT>/docs
This page provides an interactive UI to explore and test the API endpoints.
Invoking Services
Each service can be accessed via its unique REST API path, structured as follows:
http://<GENAI_SERVER_HOST>:<GENAI_SERVER_PORT>/<service>/invoke
Replace <service>
with the name defined in the YAML configuration file to make requests to that 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
Built Distribution
File details
Details for the file genai_rest_builder-0.1.0.tar.gz
.
File metadata
- Download URL: genai_rest_builder-0.1.0.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04fff47c9a0ea667591ba19eb06bbf4a0c4f5b40edf4998faa5c3bb34f580dbb |
|
MD5 | f97f53671a0b2d1ddd3275df8bf56d0f |
|
BLAKE2b-256 | 4d3d845cf976dec222e1ccbc8ee8c5a1d4f3aafaadcf61ba0a2e497856bcf8fb |
File details
Details for the file genai_rest_builder-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: genai_rest_builder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 52.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a316c937e3b8b00884b4785f3dae38f1706c93011d1ba223b80bdf3abf4eca20 |
|
MD5 | 53993152a9c8b790881b0e0dc1a048ea |
|
BLAKE2b-256 | aa373f59df2b1a2019e43d78cacd4bf53660281f0af87998538d38775c970c37 |