Welcome

Hi! I’m Timo. This is my blog.

Enforce and Validate LLM Output with Pydantic

Large Language Models (LLMs) excel in generating text but often struggle to produce structured output. By leveraging Pydantic’s type validation and prompt engineering, we can enforce and validate the output generated by LLMs. All code examples in this blog post are written in Python. The LLM used is OpenAI’s gpt-3.5-turbo. Query the LLM To query the LLM, we use the following function: import openai def query(prompt: str) -> str: """Query the LLM with the given prompt....

August 7, 2023 · 5 min · 891 words

A Terminal Spinner in Python

We are going to build a spinning status indicator that runs while other code is executing. It will look like this: Why? You’ve got some code that takes a while to run. import time import random def slow_func(): seconds = random.randint(2, 5) time.sleep(seconds) print("Done!") if __name__ == '__main__': slow_func() Now, when you execute this, you’ll see the following: You’ll wonder whether your code or your system is working correctly or frozen....

June 25, 2022 · 4 min · 682 words