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
| type ResponseCleaner interface { | |
| Clean(context.Context, string) (string, []ResponseDetails, error) | |
| } | |
| type ResponseDetails struct { | |
| DetailType string `json:"detail_type"` | |
| Content interface{} `json:"content"` | |
| } |
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
| type CitedSourceCleaner struct{} | |
| func (c CitedSourceCleaner) Clean(ctx context.Context, message string) (string, []ResponseDetails, error) { | |
| sourceRegex := regexp.MustCompile(`\[(Source|Ref):\s*([^\]]+)\]`) | |
| var citations []ResponseDetails | |
| matches := sourceRegex.FindAllStringSubmatch(message, -1) | |
| for i, match := range matches { | |
| citations = append(citations, ResponseDetails{ | |
| DetailType: "citation", |
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
| type ModelCategory string | |
| const ( | |
| Fast ModelCategory = "fast" | |
| Smart ModelCategory = "smart" | |
| Reasoning ModelCategory = "reasoning" | |
| ) | |
| func GetModelForCategory(category ModelCategory, platform ModelPlatform) ModelType { | |
| switch platform { |
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
| var GlobalFallbackOrder = []ModelPlatform{ | |
| ModelPlatformOpenAI, // Primary choice | |
| ModelPlatformAnthropic, // Secondary | |
| ModelPlatformGemini, // Tertiary | |
| } |
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) CreateCompletion(ctx context.Context, request *CompletionRequest) (*Response, error) { | |
| // Build list of primary model + fallbacks for same category | |
| modelsToTry := []ModelType{agent.primaryModel} | |
| for _, platform := range GlobalFallbackOrder { | |
| if platform != agent.primaryPlatform { | |
| fallbackModel := GetModelForCategory(agent.category, platform) | |
| modelsToTry = append(modelsToTry, fallbackModel) | |
| } | |
| } |
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 | |
| } |
OlderNewer