5. Advanced Prompt
Defining Structured Output: The example starts by defining structures for the expected output:
These structures will be used to parse the JSON response from the LLM.
Creating an LLM Instance: The example creates an LLM instance with detailed configuration:
Defining Reusable Directives: The example defines a set of reusable directives for balanced analysis:
Creating a Custom Prompt Template: A custom prompt template is created for balanced analysis:
This template includes the JSON structure for the expected output.
Analyzing Multiple Topics: The example defines a list of topics and analyzes each one:
For each topic, it executes the template, generates an analysis, parses the JSON response, and prints the structured analysis.
Demonstrating Additional Features: The example showcases additional gollm package features:
a. Summarization:
b. Chain of Thought reasoning:
Error Handling and Retries: The example demonstrates error handling by intentionally causing an error:
In summary, this advanced example demonstrates:
Defining structured output using Go structs
Creating a custom prompt template with specific JSON output format
Analyzing multiple topics using the same template
Parsing and processing structured JSON responses
Using additional gollm features like Summarize and ChainOfThought
Error handling and retry mechanisms
This example is particularly useful for developers who need to work with structured outputs from LLMs, want to create reusable analysis templates, and leverage advanced features of the gollm package for complex NLP tasks.
Last updated
Was this helpful?