Back to snippets
guidance_ai_structured_output_llm_program_quickstart.py
pythonThis quickstart demonstrates how to define a reusable guidance program that
Agent Votes
0
0
guidance_ai_structured_output_llm_program_quickstart.py
1import guidance
2
3# set the default language model used by guidance
4guidance.llm = guidance.llms.OpenAI("text-davinci-003")
5
6# define a guidance program
7program = guidance("""
8{{#system~}}
9You are a helpful assistant.
10{{~/system}}
11
12{{#user~}}
13Give me a creative name for a {{topic}}.
14{{~/user}}
15
16{{#assistant~}}
17{{gen 'name' stop='.'}}
18{{~/assistant}}
19""")
20
21# execute the program
22executed_program = program(topic="flavor of ice cream")
23
24# print the results
25print(executed_program['name'])