💬 #ChatGPT Plugin in NET – GetAll and Add, 2 API endpoints in a single PlugIn
Tags: englishpost, chatgpt, net
Published: 2023-07-10 12:58:12

---
title: 💬 #ChatGPT Plugin in NET – GetAll and Add, 2 API endpoints in a single PlugIn
published: true
date: 2023-07-05 13:00:00 UTC
tags: EnglishPost,ChatGPT,EnglishPost,NET
canonical_url: 
---

### ChatGPT NET PlugIn Series

- [Intro to ChatGPT Plugins using NET](https://dev.to/azure/my-1st-net-chatgpt-plugin-demo-included-46l0)
- [Map route handler for manifest file: ai-plugin.json](https://dev.to/elbruno/chatgpt-plugin-in-net-map-route-handler-for-manifest-file-ai-pluginjson-3d8k-temp-slug-2841168)
- [GetAll and Add, 2 API endpoints in a single PlugIn](https://elbruno.com/2023/07/05/%f0%9f%92%ac-chatgpt-plugin-in-net-getall-and-add-2-api-endpoints-in-a-single-plugin/)

Hi!

Moving forward in my PetStore plugin, I decided that my plugin must support several actions:

- List all pets
- Add a new pet
- Search for a pet
- Delete a pet

## GetAll and AddNew Operations

In my current implementation, I have 2 operations to handle GetAll and AddNew. Let’s look at the Swagger def:

![swagger definition with the GetAll and AddPet operations](https://brunocapuano.files.wordpress.com/2023/07/image-2.png?w=920)

It’s also important to remark that the pet uses a specific model that is also part of the Swagger def.

These are the 2 operations. Notice how the AddPet operation uses a typed class to represent a Pet, including pet’s owner information.

```csharp

// return the list of pets
app.MapGet("/GetAllPets", () =>
{
    Console.WriteLine("GET ALL PETS");
    var petsFile = File.ReadAllText("data/pets.json");
    return Results.Json(petsFile);
})
.WithName("GetAllPets")
.WithOpenApi(generatedOperation =>
{
    generatedOperation.Description = "Gets the list of pets available in El Bruno's Pet catalog.";
    return generatedOperation;
});

// add a new pet
app.MapPost("/AddPet", async (Root newPet) =>
{
    Console.WriteLine($"ADDPET / PET info: {newPet.name}");
    var petsFile = File.ReadAllText("data/pets.json");
    var pets = JsonSerializer.Deserialize<List<Root>>(petsFile);
    pets.Add(newPet);
    petsFile = JsonSerializer.Serialize(pets);
    File.WriteAllText("data/pets.json", petsFile);
    return Results.Ok();
})
.WithName("AddPet")
.WithOpenApi(generatedOperation =>
{
    generatedOperation.Description = "Add a new pet to the pet catalog available in El Bruno's Pet catalog. Requires pet and pet's owner information.";
    return generatedOperation;
});

```

## Testing the PlugIn

Ok, not that the plugin have the 2 operations, let’s register it into the plugin list. And let’s ask a cool question:

#### What info is needed to add a new pet?

The output is great. The plugin reads the openapi definition, and from there it suggests the needed info,

![](https://brunocapuano.files.wordpress.com/2023/07/image-3.png?w=905)

Time to test and register a new Pet. Let’s use this prompt.

#### OK, let’s add a new pet. His name is Net, is a calico breed, 17-year-old brown cat. He weighs 3 kilograms. His owner is Bruno Capuano, with the same owner information that you have in the database.

![](https://brunocapuano.files.wordpress.com/2023/07/image-4.png?w=894)

Using a single prompt, I added a new pet. And hey, I didn’t even need to describe all the owner information, I asked ChatGPT to reuse the information from Bruno.

And the expanded Json shows a view of the information posted to the API endpoint. This is especially useful to debug and learn more about how plugins call our functions.

This is super cool. I’ll continue updating [the repo](https://github.com/elbruno/OpenAI-Plugin-NET-Sample) with the demo instructions, and a live session will be scheduled soon!

Happy coding!

Greetings

El Bruno

More posts in my blog [ElBruno.com](https://www.elbruno.com).

More info in [https://beacons.ai/elbruno](https://beacons.ai/elbruno)

* * *