Missing - Instructor
The Maybe pattern is a concept in functional programming used for error handling. Instead of raising exceptions or returning None, you can use a Maybe type to encapsulate both the result and potential errors. This pattern is particularly useful when making LLM calls, as providing language models with an escape hatch can effectively reduce hallucinations. Using Pydantic, we'll first define the UserDetail and MaybeUser classes. Notice that MaybeUser has a result field that is an optional UserDetail instance where the extracted data will be stored. The error field is a boolean that indicates whether an error occurred, and the message field is an optional string that contains the error message. Once we have the model defined, we can create a function that uses the Maybe pattern to extract the data. As you can see, when the data is extracted successfully, the result field contains the UserDetail instance. When an error occurs, the error field is set to True, and the message field contains t
Handling Missing Data ¶ The Maybe pattern is a concept in functional programming used for error handling. Instead of raising exceptions or returning None , you can use a Maybe type to encapsulate both the result and potential errors. This pattern is particularly useful when making LLM calls, as providing language models with an escape hatch can effectively reduce hallucinations. Defining the Model ¶ Using Pydantic, we'll first define the UserDetail and MaybeUser classes. from pydantic import BaseModel , Field from typing import Optional class UserDetail ( BaseModel ): age : int name
related reading
- GitHub - 567-labs/instructor: structured outputs for llmsgithub.com
- GitHub - brexhq/prompt-engineering: Tips and tricks for working with Large Language Models like OpenAI's GPT-4.github.com
- The Smol Training Playbook - a Hugging Face Space by HuggingFaceTBhuggingface.co
- Parsed | Custom, interpretable AI systems that continuously learnparsed.com
- What We’ve Learned From A Year of Building with LLMs – Applied LLMsapplied-llms.org
- Implementing Self-Correction with LLM Validator - Instructorpython.useinstructor.com
- Prompt Engineering | Kagglekaggle.com
- Cookbookcookbook.openai.com
- GitHub - rasbt/LLMs-from-scratch: Implement a ChatGPT-like LLM in PyTorch from scratch, step by stepgithub.com
- LangChain: the open agent platform to own your intelligencelangchain.com
- utils/utils/llm/model_registry.py at bb825e88df79267ff5e13f4abd5ec94fa3db4613 · forecastingresearch/utils · GitHubgithub.com
- Welcome to Pydantic | Pydantic Docsdocs.pydantic.dev