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 | |
| } |
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
| 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
| 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
| 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 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
| import ( | |
| "github.com/sashabaranov/go-openai" | |
| "github.com/sashabaranov/go-openai/jsonschema" | |
| ) | |
| type SupportResponse struct { | |
| Answer string `json:"answer"` | |
| RelatedDocs []string `json:"related_docs"` | |
| } |
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 ParallelSearch(query string) []SearchResult { | |
| ctx, cancel := context.WithTimeout(context.Background(), 750*time.Millisecond) | |
| defer cancel() | |
| resultsChan := make(chan []SearchResult, len(backends)) | |
| var wg sync.WaitGroup | |
| for _, backend := range backends { | |
| wg.Add(1) | |
| go func(backend func(string) ([]SearchResult, error)) { |
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
| Help me write a comprehensive set of unit tests in Typescript for the following function: | |
| <function_to_test> | |
| function romanToInt(roman: string): number { | |
| const romanNumerals: { [key: string]: number } = { | |
| 'I': 1, | |
| 'V': 5, | |
| 'X': 10, | |
| 'L': 50, | |
| 'C': 100, |
NewerOlder