Skip to content
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

Generate accurate search requests based on conversation history using Instructor.js #63

Open
5 tasks
ravi-prakash-v opened this issue Apr 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ravi-prakash-v
Copy link
Collaborator

ravi-prakash-v commented Apr 6, 2024

Description

The beckn-action-bot currently uses a custom function to generate a structured search request by identifying preferences and booking information from the conversation history.

The get_beckn_request_from_text function in services/ai.js generates the Beckn message object which in the full request looks like this.

{
  "context": {
    ...
  },
  "message": {
    ...
  }
}

This function is highly unreliable and produces erroneous results in most use cases.

There are three types of search requests that can potentially be generated in the scope of this issue

Search by Item name

{
  "context": {
    "action": "search",
    "domain": "retail:1.1.0"
  },
  "message": {
    "intent": {
      "item": {
        "descriptor": {
          "name": "Raincoats"
        }
      }
    }
  }
}

Search by Location and Tags

{
  "context": {
    "action": "search",
    "domain": "uei:charging"
  },
  "message": {
    "intent": {
      "item": {
        "tags": [
          {
            "list": [
              {
                "descriptor": {
                  "code": "vehicle-type"
                },
                "value": "4-wheeler"
              },
              {
                "descriptor": {
                  "code": "connector-type"
                },
                "value": "CCS"
              }
            ]
          }
        ]
      },
      "fulfillment": {
        "stops": [
          {
            "location": {
              "gps": "44.428,-110.5885"
            }
          }
        ]
      }
    }
  }
}

Search by Location, Time and Tags

{
  "context": {
    "action": "search",
    "intent": "hospitality"
  },
  "message": {
    "intent": {
      "item": {
        "tags": [
          {
            "list": [
              {
                "descriptor": {
                  "code": "pet-friendly"
                },
                "value": "yes"
              },
              {
                "descriptor": {
                  "code": "ev-charging"
                },
                "value": "yes"
              },
              {
                "descriptor": {
                  "code": "accomodation-type"
                },
                "value": "campsite"
              }
            ]
          }
        ]
      },
      "fulfillment": {
        "stops": [
          {
            "type": "check-in",
            "location": {
              "gps": "44.428,-110.5885"
            },
            "time": {
              "timestamp": "2024-04-12"
            }
          },
          {
            "type": "check-out",
            "location": {
              "gps": "44.428,-110.5885"
            },
            "time": {
              "timestamp": "2024-04-14"
            }
          }
        ]
      }
    }
  }
}

Note: The "context" object is generated via a different function that is outside the scope of this issue

Goals

  • Create test case to simulate a conversation that leads to an itinerary. A sample test case can be found at : /beckn-action-bot/tests/apis/bot.test.js : ‘Test cases for trip planning workflow’
  • Update get_beckn_request_from_text function to use instructor.js library instead of custom prompt to map specific data points obtained from the conversation history into a structured search request

Expected Outcome

The get_beckn_request_from_text should accurately generate the above three requests based on the conversation.

Acceptance Criteria

  • The get_beckn_request_from_text should generate a structured "Search by item name" request based on a conversation involving a retail purchase
  • The get_beckn_request_from_text should generate a structured "Search by location and tags" request based on a conversation involving discovering EV charging
  • The get_beckn_request_from_text should generate a structured "Search by location, time, and tags" request based on a conversation involving discovering hotels

Implementation Details

  • The application uses a NodeJS backend
  • It is expected to use Instructor.js
@ravi-prakash-v ravi-prakash-v added the bug Something isn't working label Apr 6, 2024
@Govind-S-B
Copy link

Can I get a sample on the context that is passed to the function

instruction, context = (...), beckn_context(...)_schema={"profile":(...)}
I saw these variables being passed into the function but got no reference I could read up that shows a clear demo of what data goes in and what data goes out. Providing that could help me attempt fixing it

Example Input:

You are a cataloging expert that can identify tags and other elements from  (... complete your prompt).

Chat History <enter history>
Users Current Query : <query>
Output Schema explanation
Example formats -> <example schema x3 for various scenarios>

If the proper samples of input data is provided in a text file or something I will try to help out with fixing your prompt and messing with a few regex.

I also need to add this: I might not be able to respond back fast enough with other projects that I have on my plate. So I cannot promise any assured outcome, just that I volunteer to help when I have free time.

@vishakh-abhayan
Copy link

@ravi-prakash-v Update get_beckn_request_from_text function to use instructor.js library instead of custom prompt to map specific data points obtained from the conversation history into a structured search request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants