Creating Your Own Intelligent GPT Agent: The Coding Wingman (FastAPI + GitHub Search API)
Welcome to my guide on building an API-driven GPT with Coding Wingman! Over the past week since ChatGPT's GPT feature launch, I've delved deep into its capabilities. I've learned how to blend knowledge seamlessly using an integrated document store, craft complex instructions, and navigate third-party APIs.
Beware though, APIs can be quirky - they often prefer JSON-based workflows over traditional URL query parameters. To tackle these nuances, I've embraced a FastAPI approach. This guide is a culmination of my experiences, packed with scripts and strategies to help you create your own GPT powerhouse. Everything you need to get started with a complete API driven GPT.
Let's dive in and explore the potential together!
Revolutionizing with GPTs: A New Era Intelligent Agents
GPTs have transformed how we integrate and apply knowledge, especially notable in:
Overcoming API Quirks with FastAPI
While GPTs are powerful, their API integrations come with quirks. Traditional URL query parameters (?q=search) often hit limitations, and there's a marked preference for JSON-based workflows via POST requests. To navigate these peculiarities, I've developed an innovative approach using FastAPI.
Your Journey to an API-Driven GPT
In this guide, you'll find:
Introduction to Intelligent Agents
Intelligent agents are autonomous software programs capable of performing tasks and making decisions based on AI. They are pivotal in automating complex tasks, making data-driven decisions, and enhancing user experiences.
The Coding Wingman: A FastAPI Gateway to GitHub
The Coding Wingman is a FastAPI-powered interface to GitHub's search API, designed to perform various search operations such as issues, commits, code, users, topics, and repositories.
It represents an AI API data-fabric, a crucial part of modern enterprise architecture, offering a unified and efficient way to interact with diverse data sources and services.
Features of The Coding Wingman
Step 1. Try it
Importance of AI API Data-Fabric
An AI API data-fabric like Coding Wingman integrates various data sources and APIs, providing a seamless layer for AI applications to access and process data. It's an essential part of enterprise architecture, enabling efficient, scalable, and secure data interactions.
This example includes documents, web search, code interpreter, external APIs and prompt logic.
Modular Design and API Compatibility
The modular nature of FastAPI allows easy expansion and management of endpoints, making Coding Wingman adaptable for various APIs like Stripe, Microsoft Graph, or Google's APIs.
Asynchronous Processing and Real-time Task Management
FastAPI's asynchronous capabilities are crucial for handling AI requests that require more processing time, ensuring improved concurrency and system throughput. Support for background tasks and real-time processing makes it suitable for high-demand AI interactions.
I deployed my example on Replit using it's autoscaling capabilities, potentially supporting millions of users.
Security and Access Control
Coding Wingman's security implementations control access, crucial for handling sensitive AI-generated data. It supports advanced OAuth2 flows, allowing secure and evolving applications.
This guide uses a bearer token approach. View the source to see the Oauth options. This is use for GPT that require user registration.
Extensibility and Integration
Developers can extend Coding Wingman to integrate additional APIs, orchestrate complex workflows, and standardize communication protocols, enhancing AI functions like natural language understanding and response generation.
Step 2: Head over to GitHub
Setting up the Python
This is super easy on Replit, just clone the GitHub and setup define the environment variables or do it yourself following the instructions below.
Prerequisites and Installation
领英推荐
Environment Variables (IMPORTANT)
Before running the server, ensure the following environment variables are set:
Installation
Clone the repository and install dependencies:
git clone https://github.com/ruvnet/coding-wingman.git
cd coding-wingman
python -m venv venv
source venv/bin/activate # For Windows: venv\Scripts\activate
pip install -r requirements.txt
Usage
To start the server, run:
uvicorn main:app --reload
Visit https://localhost:8000/docs in your web browser to see the interactive API documentation provided by FastAPI.
You will need a public URL to use the API with ChatGPT.
Endpoints Overview
The following endpoints are available in the API:
To access the endpoints, provide a Bearer token in the Authorization header of your request.
Creating your GPT
Now the exciting part, creating your GPT.
If you need support you can use my GPT Advisor to help with the following process.
Copy Openapi.json into Schema field. You can use mine from the following link: https://github.com/ruvnet/coding-wingman/blob/main/openapi.json
Setting up your Authentication
This application uses the HTTPBearer security scheme. Ensure that only authorized clients can access the API by setting up the API_BEARER_TOKEN environment variable.
Add your API_BEARER_TOKEN you created earlier.
Testing the API Endpoints
GPT Instructions
GPT instructions serve as a guide or directive to customize the capabilities and behavior of a GPT (Generative Pre-trained Transformer) model for specific tasks or use cases.
Here's a detailed explanation of their purpose and how they work:
How GPT Instructions Work
The Coding Wingman, an advanced AI coding assistant with GitHub integration, offers comprehensive support for GitHub API requests. It helps users construct API requests for various GitHub operations, understand API structures, and interpret responses effectively.
I also have a knowledge base of PDFs I can search.
You copy this and deploy your version of the Coding Wingman from our Github
https://github.com/ruvnet/coding-wingman/
Here's a more streamlined description of its capabilities and commands:
Key Features:
API Request Construction: Guides in building GitHub API requests for operations like managing repositories, gists, searching code, commits, issues, labels, repositories, topics, and users.
API Structure Understanding: Explains API endpoints' structures, including paths, methods, and necessary parameters for each operation.
Parameter Clarification: Offers insights into the usage of various API request parameters.
Response Interpretation: Assists in understanding API responses, including status codes and response data.
Security: Provides guidance on OAuth2 authentication and authorization processes for different data types.
Schema Insights: Explains GitHub API schemas, detailing properties and types.
GitHub Code Search Syntax Guide:
Use Bing for queries, with URL structure: https://github.com/search?q=.
Basic Search: https://github.com/search?q=http-push (searches in file content and paths).
Exact Match: Enclose in quotes, e.g., "sparse index".
Escape Characters: Use backslashes, e.g., "name = \"tensorflow\"" or double backslashes \\.
Boolean Operations: Combine terms with AND, OR, NOT.
Using Qualifiers like repo:, org:, user:, language:, path:, symbol:, content:, is: for refined searches.
Regular Expressions: Enclose regex in slashes, e.g., /sparse.*index/.
Separate Search Terms with spaces, except within parentheses.
GitHub API Commands:
/searchCode: Search for code snippets on GitHub.
Example: /searchCode query="FastAPI filename:main.py" page=1 per_page=10
/searchCommits: Search for commits on GitHub.
Example: /searchCommits query="fix bug repo:openai/gpt-3" page=1 per_page=10
/searchIssues: Search for issues on GitHub.
Example: /searchIssues query="bug label:bug" page=1 per_page=10
/searchLabels: Search for labels on GitHub.
Example: /searchLabels query="bug repo:openai/gpt-3" page=1 per_page=10
/searchRepositories: Search for repositories on GitHub.
Example: /searchRepositories query="FastAPI stars:>1000" page=1 per_page=10
/searchTopics: Search for topics on GitHub.
Example: /searchTopics query="machine-learning" page=1 per_page=10
/searchUsers: Search for users on GitHub.
Example: /searchUsers query="ruvnet" page=1 per_page=10
This assistant will continue to assist with coding, debugging, 3D design, and now, with a deeper focus on GitHub API interactions. Always follow the example URL structure for searches, such as https://github.com/search?q=owner%3Aruvnet&type=repositories.
Use a helpful and friendly voice and tone. Use Emojis and bullets. Format text using mark down.
Start - Create introduction Image 16.9 in stylish coding co-pilot style, after Provide Introductions and commands. Explain in simple terms.
Trouble Shooting
Good luck!
Empowering people through kind, intelligent automation | Director at Axelerant
9 个月Many thanks, Reuven, for these helper guides. You're making it easier for my peers to focus on outcomes rather than the many overwhelming hows.
Awesome
Awesome
Many time founder & 5 exits - lots of open source - now working to reimagine cyber security with deep learning
10 个月Your productivity - boosted by chat GPT I know - is insane. Thanks for continuing to build and educate in public. Very cool & insightful stuff.
Leader Specialized in CX, AI, Growth, Marketing & Innovation | Partner to the world's greatest brands, the most awarded agencies. | Founder | Father | Grateful
10 个月Amazing just what I needed!