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

Demo v2: Auto-correct JSON format via loop #23

Closed
wants to merge 27 commits into from
Closed

Conversation

tholor
Copy link
Member

@tholor tholor commented Sep 20, 2023

Motivation

Pipelines in Haystack 2.0 are more flexible and more robust than ever.
They allow you now to run loops within your pipeline. Let's look at why this matters.

Exemplary Use Case: Validate & auto-correct the output format of an LLM

Let's imagine you want to extract structured information from a document in JSON format.
As your further processing steps depend on the correctness of this JSON format, you want to make sure that the LLM really produces it in a robust way.

Approach

We validate the output of the LLM against a pydantic schema. If the output is valid, we return it to the user. If not, we create another prompt that leverages the generated output + error message. To avoid infinite loops we limit it to max. 5 iterations.

parser_loop

Demo: Colab

To Dos:

  • We need optional variables in PromptTemplates (we are using a haystack branch so far)
  • Allow three variables in the prompt template so that we can include the error message (so far only the wrongly generated output is used)

Copy link
Contributor

@ZanSara ZanSara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two small fixes that make this work on Canals 0.10

auto_fixing_parser_v2/auto_fix_parser.py Outdated Show resolved Hide resolved
auto_fixing_parser_v2/auto_fix_parser.py Outdated Show resolved Hide resolved
tholor and others added 4 commits November 21, 2023 14:59
Co-authored-by: ZanSara <sara.zanzottera@deepset.ai>
Co-authored-by: ZanSara <sara.zanzottera@deepset.ai>
@tholor tholor requested a review from bilgeyucel November 23, 2023 16:25
@bilgeyucel
Copy link
Contributor

@bilgeyucel bilgeyucel closed this Feb 7, 2024
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

Successfully merging this pull request may close these issues.

5 participants