Author: Carlos J. Ramirez
Based on the oTtomator Python agent code from: Cole Medin
The GSAM Python FastAPI agent, is a tool to help on the software development process for any Application. It allows to generate application ideas, app description, database estructures, and presentation content from a text prompt, and kick start code to be used with the GenericSuite library. It's compatible with the OTTomator Live Agent Studio.
This AI-powered agent provides:
- Innovative App Ideas Generation: Craft mind-blowing web/mobile app concepts emphasizing unique features, target audiences, and potential uses.
- Names Generation: Propose catchy, creative names for software applications.
- PowerPoint Content Creation: Draft content for presentation slides and suggest prompts for generating presentation images.
- App Description and Table Definitions: Develop comprehensive application descriptions and detailed table definitions.
- CRUD JSON and Python Code Generation: Produce generic CRUD editor configuration JSON and corresponding Python code using Langchain Tools for specified operations.
It also:
- Process natural language queries
- Maintain conversation history
- Integrate with external AI models
- Store and retrieve conversation data
- Handle authentication and security
The agent comes in two variants:
- Supabase Version (
gsam_supabase_agent.py
): Uses Supabase client for database operations - Postgres Version (
gsam_postgres_agent.py
): Uses direct PostgreSQL connection via asyncpg
- Python 3.11 or higher
- pip (Python package manager)
- PostgreSQL database or Supabase account
- Basic understanding of:
- FastAPI and async Python
- RESTful APIs
- Pydantic models
- Environment variables
- PostgreSQL (for Postgres version)
The main application is built using FastAPI, providing:
-
Authentication
- Bearer token validation via environment variables
- Secure endpoint protection
- Customizable security middleware
-
Request Handling
- Async endpoint processing
- Structured request validation
- Error handling and HTTP status codes
-
Database Integration
- Supabase connection management
- Message storage and retrieval
- Session-based conversation tracking
class AgentRequest(BaseModel):
query: str # The user's input text
user_id: str # Unique identifier for the user
request_id: str # Unique identifier for this request
session_id: str # Current conversation session ID
class AgentResponse(BaseModel):
success: bool # Indicates if the request was processed successfully
The agent uses Supabase tables with the following structure:
messages (
id: uuid primary key
created_at: timestamp with time zone
session_id: text
message: jsonb {
type: string # 'human' or 'assistant'
content: string # The message content
data: jsonb # Optional additional data
}
)
-
Clone Repository
# Clone the repository git clone git clone https://github.com/tomkat-cr/genericsuite-app-maker.git cd genericsuite-app-maker # Copy example environment file cp .env.example .env # Edit .env with your credentials nano .env # or use your preferred editor
-
Configure Environment Variables
⚠️ Important: For Docker, do not wrap environment variable values in quotes, even if they contain special characters. Docker will handle the values correctly without quotes.Required environment variables in
.env
file (do not use quotes around values):SUPABASE_URL=your-project-url SUPABASE_SERVICE_KEY=your-service-key API_BEARER_TOKEN=your-token-here
Required environment variables:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname API_BEARER_TOKEN=your-chosen-token
The DATABASE_URL format is:
postgresql://[user]:[password]@[host]:[port]/[database_name]
OPENROUTER_API_KEY=your-api-key-here OPENROUTER_MODEL_NAME=your-model-name-here
# to use HuggingFace and Flux HUGGINGFACE_API_KEY=your-api-key-here
# to use Rhymes Allegro RHYMES_ALLEGRO_API_KEY=your-api-key-here
-
Create Database Tables For both Supabase and PostgreSQL, you'll need to create the following tables:
-- Enable the pgcrypto extension for UUID generation
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE messages (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
session_id TEXT NOT NULL,
message JSONB NOT NULL
);
CREATE INDEX idx_messages_session_id ON messages(session_id);
CREATE INDEX idx_messages_created_at ON messages(created_at);
ALTER publication supabase_realtime ADD TABLE messages;
Note: If you're using Supabase, the
pgcrypto
extension is already enabled by default.
- Build the base images
cd genericsuite-app-maker/gsam_ottomator_agent
make install
- Run the container:
cd genericsuite-app-maker/gsam_ottomator_agent
make run
The agent will be available at http://localhost:8001
.
To restart the container:
cd genericsuite-app-maker/gsam_ottomator_agent
make restart
To Stop and destroy the container:
cd genericsuite-app-maker/gsam_ottomator_agent
make stop
- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
- Run the agent:
For Supabase version:
Set the SUPABASE_URL
and SUPABASE_SERVICE_KEY
environment variables in your .env
file, then run:
uvicorn gsam_ottomator_agent_app:app --host 0.0.0.0 --port 8001
For PostgreSQL version:
Set the DATABASE_URL
environment variable and leave SUPABASE_URL
and SUPABASE_SERVICE_KEY
empty in your .env
file, then run:
uvicorn gsam_ottomator_agent_app:app --host 0.0.0.0 --port 8001
The agent uses environment variables for configuration. You can set these variables in a .env
file or using your operating system's environment variable settings.
Test your agent using curl or any HTTP client:
curl -X POST http://localhost:8001/api/gsam-supabase-agent \
-H "Authorization: Bearer your-token-here" \
-H "Content-Type: application/json" \
-d '{
"query": "Hello, agent!",
"user_id": "test-user",
"request_id": "test-request-1",
"session_id": "test-session-1"
}'
curl -X POST http://localhost:8001/api/gsam-postgres-agent \
-H "Authorization: Bearer your-token-here" \
-H "Content-Type: application/json" \
-d '{
"query": "Hello, agent!",
"user_id": "test-user",
"request_id": "test-request-1",
"session_id": "test-session-1"
}'
Common issues and solutions:
-
Authentication Errors
- Verify bearer token in environment
- Check Authorization header format
- Ensure token matches exactly
-
Database Connection Issues
- For Supabase:
- Verify Supabase credentials
- Validate table permissions
- For PostgreSQL:
- Check DATABASE_URL format
- Verify database user permissions
- Ensure database is running and accessible
- Check if tables are created correctly
- For Supabase:
-
Performance Problems
- Check database query performance
- Consider caching frequently accessed data
- For PostgreSQL:
- Monitor connection pool usage
- Adjust pool size if needed (default is reasonable for most cases)
This project is developed and maintained by Carlos J. Ramirez. For more information or to contribute to the project, visit GenericSuite App Maker on GitHub.
Happy Coding!