beckn / transactional-ai-bap

MIT License
6 stars 3 forks source link

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

Open ravi-prakash-v opened 6 months ago

ravi-prakash-v commented 6 months ago

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

Expected Outcome

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

Acceptance Criteria

Implementation Details

Govind-S-B commented 6 months ago

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 commented 5 months ago

@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