Skip to content

Instantly share code, notes, and snippets.

@ruvnet
Last active May 25, 2024 19:28
Show Gist options
  • Save ruvnet/ee5936eec19a16edcc54a48922591d28 to your computer and use it in GitHub Desktop.
Save ruvnet/ee5936eec19a16edcc54a48922591d28 to your computer and use it in GitHub Desktop.
Pygentic Agent Framework
   ___                      _   _      
  / _ \/\_/\__ _  ___ _ __ | |_(_) ___ 
 / /_)/\_ _/ _` |/ _ \ '_ \| __| |/ __|
/ ___/  / \ (_| |  __/ | | | |_| | (__ 
\/      \_/\__, |\___|_| |_|\__|_|\___|
           |___/                       

    Created by rUv

Introduction to Pygentic Framework

Pygentic is an innovative system designed to enhance the capabilities of AI assistants by providing a flexible and standardized API.

Based on the robust architecture of the OpenAI Assistants API, Pygentic abstracts the complexities of integrating with different Large Language Models (LLMs), both local and remote. This abstraction ensures a consistent and seamless interaction regardless of the underlying model.

What is the Pygentic Library?

The Pygentic library acts as a bridge between your application and various LLMs. It simplifies the process of connecting to different AI models by offering a uniform API, eliminating the need to manage the specifics of each model. Whether you're using OpenAI, a local model, or another remote service, Pygentic provides a reliable and consistent interface.

Pygentic Agents

Pygentic introduces the concept of agents—intelligent assistants that can perform a range of tasks. These agents are configured to understand and respond to user inputs, utilizing different LLMs for processing. You can create and manage multiple agents, each tailored to specific functions or tasks, enhancing the versatility and efficiency of your AI-driven applications.

Concurrency

Concurrency in Pygentic ensures that multiple tasks can be handled simultaneously without compromising performance. This is particularly important for applications requiring real-time responses or handling numerous requests at once. Pygentic's design leverages modern asynchronous programming techniques to manage these tasks efficiently, providing a smooth and responsive experience.

Serverless

Pygentic supports serverless architectures, enabling you to deploy your AI applications without the need to manage infrastructure. This approach reduces operational complexity and costs, as the serverless platform handles scaling, monitoring, and resource allocation automatically. You can focus on developing and refining your AI capabilities, while the serverless environment ensures robust and scalable

Open-Interpreter (Multi-Programming Language Support)

The open-interpreter feature of Pygentic allows for multi-programming language support, enabling your agents to understand and generate responses in various programming languages. This expands the reach of your applications, making them compatible with a variety of different software projects. The flexibility to interpret and interact in multiple programming languages enhances the usability and effectiveness of your AI solutions.

Practical Applications

Pygentic can be applied across numerous practical scenarios:

  • Customer Support: Deploy intelligent agents to handle customer queries, providing instant and accurate responses.
  • Content Generation: Use AI to create engaging content in multiple languages, tailored to your audience.
  • Data Analysis: Leverage AI for interpreting and analyzing large datasets, extracting meaningful insights.
  • Personal Assistants: Develop personalized AI assistants to help with daily tasks, scheduling, and information retrieval.

Pygentic empowers developers to harness the power of AI with ease, offering a flexible and scalable solution for integrating advanced language models into various applications. Its consistent API, multi-language support, and serverless capabilities make it a valuable tool for modern AI-driven projects.

Project Architecture

Here's a detailed breakdown of the directory structure and code blocks for each file.

1. Directory Structure

pygentic/
├── app/
│   ├── __init__.py
│   ├── main.py
│   ├── models.py
│   ├── routes/
│   │   ├── __init__.py
│   │   ├── assistants.py
│   │   ├── threads.py
│   │   ├── messages.py
│   │   ├── runs.py
│   └── services/
│       ├── __init__.py
│       ├── llm_service.py
│       ├── serverless_service.py
│       ├── open_interpreter_service.py
│       ├── database.py
├── tests/
│   ├── __init__.py
│   ├── test_assistants.py
│   ├── test_threads.py
│   ├── test_messages.py
│   ├── test_runs.py
├── requirements.txt
└── README.md

Installation

You can install the Pygentic library using pip:

pip install pygentic

Running the Application

After installing the library, you can run the application using the following command:

pygentic

Endpoints

Assistants

  • POST /v1/assistants: Create a new assistant.
  • GET /v1/assistants/{assistant_id}: Retrieve an assistant by ID.

Threads

  • POST /v1/threads: Create a new thread.
  • GET /v1/threads/{thread_id}: Retrieve a thread by ID.

Messages

  • POST /v1/threads/{thread_id}/messages: Add a message to a thread.
  • GET /v1/threads/{thread_id}/messages: Retrieve messages in a thread.

Runs

  • POST /v1/threads/{thread_id}/runs: Run a thread with an assistant.
  • GET /v1/threads/{thread_id}/runs/{run_id}: Retrieve a run by ID.
#!/bin/bash
# Colors for bbs style text UI
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to display the menu
function display_menu {
echo -e "${GREEN}================== Pygentic Setup Menu ==================${NC}"
echo -e "1. 🛠️ Setup Project Structure"
echo -e "2. 📦 Install Dependencies"
echo -e "3. 🧪 Setup Virtual Environment"
echo -e "4. 🔄 Activate Virtual Environment"
echo -e "5. 🔧 Deactivate Virtual Environment"
echo -e "6. ❓ Help"
echo -e "7. 🚪 Exit"
echo -e "${GREEN}========================================================${NC}"
}
# Function to setup project structure
function setup_project_structure {
echo -e "${YELLOW}Setting up project structure...${NC}"
mkdir -p my_assistant_proxy/app/routes my_assistant_proxy/app/services my_assistant_proxy/tests
touch my_assistant_proxy/app/{__init__.py,main.py,models.py}
touch my_assistant_proxy/app/routes/{__init__.py,assistants.py,threads.py,messages.py,runs.py}
touch my_assistant_proxy/app/services/{__init__.py,llm_service.py,serverless_service.py,open_interpreter_service.py,database.py}
touch my_assistant_proxy/tests/{__init__.py,test_assistants.py,test_threads.py,test_messages.py,test_runs.py}
touch my_assistant_proxy/{requirements.txt,README.md}
echo -e "${GREEN}Project structure created successfully.${NC}"
}
# Function to install dependencies
function install_dependencies {
echo -e "${YELLOW}Installing dependencies...${NC}"
pip install fastapi pydantic httpx uvicorn liteLLM pydbantic databases[sqlite]
echo -e "${GREEN}Dependencies installed successfully.${NC}"
}
# Function to setup virtual environment
function setup_virtual_env {
echo -e "${YELLOW}Setting up virtual environment...${NC}"
python3 -m venv venv
echo -e "${GREEN}Virtual environment setup successfully.${NC}"
}
# Function to activate virtual environment
function activate_virtual_env {
echo -e "${YELLOW}Activating virtual environment...${NC}"
source venv/bin/activate
echo -e "${GREEN}Virtual environment activated. Run 'deactivate' to exit.${NC}"
}
# Function to deactivate virtual environment
function deactivate_virtual_env {
echo -e "${YELLOW}Deactivating virtual environment...${NC}"
deactivate
echo -e "${GREEN}Virtual environment deactivated.${NC}"
}
# Function to display help
function display_help {
echo -e "${YELLOW}Help:${NC}"
echo -e "1. Setup Project Structure: Creates necessary directories and placeholder files."
echo -e "2. Install Dependencies: Installs required Python packages."
echo -e "3. Setup Virtual Environment: Creates a virtual environment."
echo -e "4. Activate Virtual Environment: Activates the virtual environment."
echo -e "5. Deactivate Virtual Environment: Deactivates the virtual environment."
echo -e "6. Help: Displays this help message."
echo -e "7. Exit: Exits the setup script."
}
# Main script logic
while true; do
display_menu
read -p "Please choose an option (1-7): " choice
case $choice in
1) setup_project_structure ;;
2) install_dependencies ;;
3) setup_virtual_env ;;
4) activate_virtual_env ;;
5) deactivate_virtual_env ;;
6) display_help ;;
7) echo -e "${RED}Exiting setup script. Goodbye!${NC}"; exit 0 ;;
*) echo -e "${RED}Invalid option, please try again.${NC}" ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment