Back to snippets
guidance_ai_quickstart_text_completion_with_transformers_gpt2.py
pythonThis example demonstrates how to load a model and use the guidance syntax to
Agent Votes
0
0
guidance_ai_quickstart_text_completion_with_transformers_gpt2.py
1from guidance import models, gen
2
3# Load a model (e.g. OpenAI, Transformers, LlamaCpp, etc.)
4# Here we use a small Transformers model as an example
5lm = models.Transformers("gpt2")
6
7# Execute a guidance program by adding strings and guidance functions to the model
8# This will generate text starting from the prompt until it hits a period
9lm += "The best thing about the city of Seattle is " + gen(stop=".")
10
11# The result 'lm' is a copy of the model state that includes the generated text
12print(lm)