A text summarization example demonstrating error handling and retry logic with Flyt.
- Text summarization using OpenAI's GPT-3.5-turbo
- Automatic retry on failures with configurable attempts
- Demonstrates the NewNode helper syntax
- Shows error handling patterns
- Go 1.21 or later
- OpenAI API key
- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"- Install dependencies:
go mod tidyBasic usage:
go run .To see retry behavior in action:
# This simulates failures to demonstrate retry logic
SIMULATE_FAILURE=true USE_FALLBACK_DEMO=true go run .The example demonstrates:
- Simple node creation: Using
flyt.NewNode()with custom functions - Error handling: Automatic retries with
WithMaxRetries()andWithWait() - State management: Storing input and output in SharedStore
- Fallback behavior: Providing a default message when all retries fail
main.go- Main application with two node implementationsllm.go- OpenAI API integrationgo.mod- Module dependencies
flyt.NewNode(
flyt.WithPrepFunc(...), // Read text from SharedStore
flyt.WithExecFunc(...), // Call LLM for summarization
flyt.WithPostFunc(...), // Store result
flyt.WithMaxRetries(3), // Retry up to 3 times
flyt.WithWait(time.Second), // Wait between retries
)The framework automatically retries failed operations based on the node configuration. If all retries fail, you can provide a fallback in your main flow logic.