Skip to content

OpenAPI generate function names if operationIds are unavailable #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cloudnautique opened this issue May 6, 2024 · 2 comments
Closed
Assignees

Comments

@cloudnautique
Copy link
Contributor

If operationIds are not provided in the OpenAPI spec, the parser should autogenerate based on "method" and "path" or similar so a consumer an use the spec without having to download and modify it.

@g-linville
Copy link
Member

This one is done @sangee2004

@sangee2004
Copy link
Contributor

gptscript version v0.9.2+0f32a9d8

Able to work with openapi yamls even when there are no operationIds present.

Tested with following openapi yaml which does not have operationIds for list and get methods:

# Adapted from the official example at https://github.com/OAI/OpenAPI-Specification/blob/66fe9db36115bbf5425892aaaac6dba5e3c5df59/examples/v3.0/petstore.yaml
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
paths:
  /pets:
    get:
      summary: List all pets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            maximum: 100
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      maxItems: 100
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Able to see the following script work successfully:

Tools: http://localhost:8080/openapi

List name of all the dogs.
Get info about Pet Id 3

Tool calls gets generated for getPets and getPetsPetid and works fine.

gptscript --disable-cache localpetstore.gpt
16:05:07 started  [main]
16:05:07 sent     [main]
         content  [1] content | Waiting for model response...
         content  [1] content | <tool call> getPets -> {"limit": 100}
         content  [1] content | <tool call> getPetsPetid -> {"petId": "3"}
16:05:08 started  [get_pets(2)] [input={"limit": 100}]
16:05:08 started  [get_pets_petId(3)] [input={"petId": "3"}]
16:05:08 ended    [get_pets_petId(3)] [output={\"id\":3,\"name\":\"Goldie\",\"tag\":\"fish\"}]
16:05:08 ended    [get_pets(2)] [output=[{\"id\":1,\"name\":\"Rex\",\"tag\":\"dog\"},{\"id\":2,\"name\":\"Mittens\",\"tag\":\"cat\"},{\"id\":3,\"name\":\"Goldie\",\"ta...]
16:05:08 continue [main]
16:05:08 sent     [main]
         content  [1] content | Waiting for model response...
         content  [1] content | Names of all the dogs:
         content  [1] content | - Rex
         content  [1] content | - Buddy
         content  [1] content | - Spike
         content  [1] content | - Rusty
         content  [1] content | 
         content  [1] content | Info about Pet Id 3:
         content  [1] content | - Name: Goldie
         content  [1] content | - Tag: fish
16:05:09 ended    [main] [output=Names of all the dogs:\n- Rex\n- Buddy\n- Spike\n- Rusty\n\nInfo about Pet Id 3:\n- Name: Goldie\n- Tag: fis...]
16:05:09 usage    [total=757] [prompt=673] [completion=84]

OUTPUT:

Names of all the dogs:
- Rex
- Buddy
- Spike
- Rusty

Info about Pet Id 3:
- Name: Goldie
- Tag: fish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants