Created
June 13, 2025 02:28
-
-
Save wangjohn/fd5cdb777ad1ca48db45a0eeb53bf3d5 to your computer and use it in GitHub Desktop.
LLM fallback article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (agent *LLMAgent) StreamCompletion(ctx context.Context, request *CompletionRequest, tokens chan<- Token) error { | |
| modelsToTry := agent.getModelsToTry() | |
| for i, model := range modelsToTry { | |
| hasReceivedFirstToken, err := agent.tryStreamSingleModel(ctx, request, model, tokens, agent.getModelTimeout()) | |
| if err == nil { | |
| return nil // Success | |
| } | |
| // Only retry if we haven't started streaming and have more models to try | |
| if !hasReceivedFirstToken && i < len(modelsToTry)-1 { | |
| continue // Try next model | |
| } | |
| return err | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment