ChatGPT and Crunchbase API: How to Create a Plugin from Scratch

ChatGPT and Crunchbase API: How to Create a Plugin from Scratch

Discover how to create plugins for ChatGPT in this comprehensive step-by-step tutorial. Learn how to extend ChatGPT’s capabilities using the Crunchbase Basic APIs as a data service.

A ChatGPT plugin is essentially an extension that allows the model to interact with APIs, databases, and other third-party services. This allows you to customize and enhance ChatGPT’s responses, enabling it to provide real-time and much more accurate information.

If you want to go straight to the result, here is the repo on GitHub.

Tutorial Objective

The main goal is to guide you through creating a plugin that searches for company information in the Crunchbase database.

We will use:

  • ChatGPT (GPT-4) for code generation.
  • CodeSandbox to quickly deploy our API.
  • Crunchbase Basic API for company data.

Initial Setup

  1. Crunchbase API Key: Register on Crunchbase and generate your API_KEY from “Account Settings” > “Integrations”.
  2. OpenAI Developer: Ensure you have developer access to plugin features in ChatGPT.

API Key Generation

Step 1: Create your API with FastAPI

A plugin consists of three elements: your API, the manifest (ai-plugin.json), and the OpenAPI specification (openapi.json).

We will use the following prompt to ask ChatGPT to generate the API skeleton:

Write a company search and lookup application using FastAPI that lets the user to search for companies...
- Use uvicorn to run it.
- Serve manifest.json at /.well-known/ai-plugin.json.
- Use Crunchbase Search Organizations (POST) endpoint.

Here is the base code we will use:

from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
from fastapi.openapi.utils import get_openapi
from pydantic import BaseModel
import requests
import json
import os

app = FastAPI()

class Company(BaseModel):
    name: str

@app.post("/search")
async def search_company(company: Company):
    user_key = os.getenv('CRUNCHBASE_API_KEY')
    url = f"https://api.crunchbase.com/api/v4/searches/organizations?user_key={user_key}"
    
    data = {
        "field_ids": ["name", "short_description", "website_url", "image_url"],
        "query": [
            {
                "type": "predicate",
                "field_id": "identifier",
                "operator_id": "contains",
                "values": [company.name]
            }
        ],
        "limit": 5
    }
    
    response = requests.post(url, data=json.dumps(data))
    if response.status_code == 200:
        response_data = response.json()
        extracted_data = []
        for entity in response_data['entities']:
            extracted_entity = {
                'company_name': entity['properties'].get('name', None),
                'description': entity['properties'].get('short_description', None),
                'website_url': entity['properties'].get('website_url', None),
                'image_url': entity['properties'].get('image_url', None),
            }
            extracted_data.append(extracted_entity)
        return extracted_data
    else:
        raise HTTPException(status_code=400, detail="Unable to fetch data")

Step 2: Deployment on CodeSandbox

CodeSandbox allows you to deploy Python environments quickly. You just need to:

  1. Create a Python Sandbox.
  2. Add fastapi, uvicorn, and requests to requirements.txt.
  3. Configure the CRUNCHBASE_API_KEY environment variable.

Postman Test

Step 3: The Manifest and Installation

The manifest.json file is crucial for OpenAI to identify your plugin:

{
  "schema_version": "v1",
  "name_for_human": "Crunchbase Plugin",
  "name_for_model": "crunchbase_plugin",
  "description_for_model": "Plugin for company information search. You can search for companies by name...",
  "auth": { "type": "none" },
  "api": { "type": "openapi", "url": "/openai.json" },
  "logo_url": "https://diegoromero.es/logo.png"
}

Installation Sequence in ChatGPT

Once your API is running on CodeSandbox, go to the ChatGPT Plugin Store and choose “Install unverified plugin”. Enter your sandbox URL and follow the steps:

  1. Select Plugins.
  2. Install from URL.
  3. Verify manifest and specification.
  4. Ready to use!

Final Considerations

This exercise shows how to expand AI capabilities by connecting it with real data. Furthermore, with libraries like LangChain or LlamaIndex, these plugins become valuable tools for autonomous agent development.

On a personal level, these tools remove technical barriers, allowing us to focus on innovation and business value.

powered by Crunchbase

Powered by Crunchbase