Developing my first plugin

I recently completed my first plugin and shared my experience on Linked-In and Medium.
The purpose of sharing this is to provide an easy to follow example of how to develop your own plug-in.

My First Plugin - An Article first posted on Linked-In

5 Likes

Wonderful read! Thank you!

1 Like

Few things to note, yaml isn’t required, since you’re using python, just use the openapi.json provided by fastapi and it will just magically work.

Also your endpoints don’t include summary and descriptions so there is no context for the OpenAi plug-in system, this will automatically appear in the json specification created by fastapi

This is an example of how I clone a GitHub repo including an internal prompt


# Clone a GitHub repository
class CloneRepoInput(BaseModel):
    repo_url: str
    local_dir: Optional[str] = None

# Clone a project or single file
@app.post(
    "/clone/{repo_name}/{file_path}",
    summary="Clone a project or single file",
    description="Clones either an entire repository or a single file from the specified GitHub repository. "
                "Provide the repository name in the format 'user/repo' and the file path (or 'all' for the entire repository)."
)
async def clone(repo_name: str, file_path: str, github_api: Github = Depends(get_github_api)):
    repo = github_api.get_repo(repo_name)
    git_url = repo.clone_url
    local_directory = "cloned_repos"
    # Clone the entire project
    if file_path == "all":
        subprocess.run(["git", "clone", git_url, f"{local_directory}/{repo_name}"])
        return {"result": "success"}

    # Clone a single file
    else:
        raw_file_url = f"https://raw.githubusercontent.com/{repo_name}/{repo.default_branch}/{file_path}"
        local_file_directory = os.path.join(local_directory, repo_name, os.path.dirname(file_path))
        os.makedirs(local_file_directory, exist_ok=True)
        response = requests.get(raw_file_url)

        with open(os.path.join(local_file_directory, os.path.basename(file_path)), "wb") as file:
            file.write(response.content)

        return {"result": "success"}

2 Likes

Thanks for the feedback. Since this was my first attempt, I followed the ToDo example provided in the OpenAI documentation as closely as I could, hence the OpenAPI.yaml. I understand from OpenAPI/Swagger documentation that I could have done it as .json instead of .yaml but again I wanted to follow the OpenAI example.

I suspect there is more than one way of doing this all, but even this bare-bones implementation works amazing. Chat GPT fully understands the context of the plugin, that it needs two pieces of information for the order, and providing a user friendly message if I order a product that does not exist.

1 Like

Ok, I’m going to have to learn fastapi. This is much less wordy and spreadout across multiple files then Quart_cors.
I’ve had some trouble getting chatGPT to correctly interpret clean legal endpoint path specs that Quart implements correctly. Ever seen that with fastapi? If not, that would be another plus.

1 Like

I’ve tried flask in python and a few other approaches using JavaScript. fastapi is by far the best and most flexible approach I’ve found.

1 Like

This is wonderful! Thank you for sharing. Do you know if plugin developer access vs plugin user access are two different things or one of the same?

As far as I understand it, there are no users yet, the only ones who have access to chatGPT alpha, outside openAI and its trusted partners, of course, are plugin developers. Over time, chatGPT Alpha will be ‘the’ chatGPT, with the plugin mechanism serving as an ‘app store’ for ‘users’. I imagine the UI around plugins might look very different for users by then

My understanding is the same as Bruce’s (see bruce.dambrosio’s reply). I would add that as a developer I can allow up to 15 users of any plugin I developer, but those “users” must be developers. OpenAI has structured it this way as part of their Alpha testing. This seems a sensible precaution. I suspect OpenAi is taking their time releasing plugin capability, until they better understand the risks.