api-manager icon indicating copy to clipboard operation
api-manager copied to clipboard

[API Chat] Issue when calling multiple connected resources from the API Chat

Open chamilaadhi opened this issue 1 year ago • 3 comments

Description

I have an API with following resources

Screenshot 2024-04-03 at 3 20 50 PM

I issued following query

List all the station_id where city is London and get the platforms for each station_id

The expected outcome is first call /stations and get all the station_id from the payload and then call /stations/{station_id}

But API chat only executes the first part and stops responding (message saying it is trying to fetch rest). See below

Screenshot 2024-04-03 at 3 01 27 PM

Definition and the backend can be found in https://drive.google.com/drive/folders/1NajcZY7E2KOW6sSN7Sp-wzA-E0r64aZe

chamilaadhi avatar Apr 03 '24 10:04 chamilaadhi

For single entry returned from GET /stations, it worked without an issue

ex: List all platforms in station 'Waterloo'

Screenshot 2024-04-03 at 4 45 25 PM

chamilaadhi avatar Apr 03 '24 11:04 chamilaadhi

Addtionally, Noticed in the latest pack, there is a dummy request happening. See below

Screenshot 2024-04-04 at 11 57 19 AM

chamilaadhi avatar Apr 04 '24 06:04 chamilaadhi

These issues were noticed because resource parameters were getting dropped from the API definition when feeding to the LLM. Thereby, the LLM was unaware that such path parameters were needed for API invocation, hence, the hallucinations.

A workaround for this issue is mentioned below.

Instead of having parameters under the path item object like shown below:

  /stations/{station_id}:
    parameters:
      - in: path
        name: station_id
        required: true
        schema:
          type: string
        description: ID of the station to retrieve
    get:
      summary: Get station by ID
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Station'
    put:
      summary: Update station information
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Station'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Station'

Specify parameters within the operation object (i.e. within get, put, post, etc.) like so:

  /stations/{station_id}:
    get:
      summary: Get station by ID
      parameters:
        - in: path
          name: station_id
          required: true
          schema:
            type: string
          description: ID of the station to retrieve
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Station'
    put:
      summary: Update station information
      parameters:
        - in: path
          name: station_id
          required: true
          schema:
            type: string
          description: ID of the station to retrieve
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Station'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Station'

Since the provided API definition is valid, we will have to fix this from our codebase.

ashera96 avatar Apr 30 '24 10:04 ashera96