FormulaMonks / kurt

A wrapper for AI SDKs, for building LLM-agnostic structured AI applications in Typescript
MIT License
2 stars 0 forks source link

In case an error is thrown during the structured data flow, capture the text value that failed #43

Closed theoremonemehdi closed 2 months ago

theoremonemehdi commented 3 months ago

In some cases, Kurt fails during a structured data flow for the following reasons:

  1. The LLM response breaks a Zod constraint (i.e. a number between 0 and 100, or a missing key…)
  2. The LLM response is not a JSON structure (basically JSON.parse fails)

In order to build a follow-up prompt for the LLM, we need to capture the returned text value that failed. Maybe expose the text value inside a KurtStructuredDataError

theoremonemehdi commented 3 months ago

@jemc noticed this: { index: 0, delta: {}, logprobs: null, finish_reason: 'length' } Basically, the LLM response exceeded the remaining available tokens that's why JSON.parse is failing. This is the successful finish_reason { index: 0, delta: {}, logprobs: null, finish_reason: 'stop' }

jemc commented 3 months ago

@theoremonemehdi - thinking through the different use cases here... How does this sound for developer experience?

jemc commented 2 months ago

This has been resolved in tickets #48 and #49.