Skip to content

Gemini 429 Error not being caught #162

@isaacrlevin

Description

@isaacrlevin

Follow up from #144 (comment)

I am using Mscc.GenerativeAI.Microsoft to be able to map Gemini calls via the Microsoft.Extension.AI package and I am getting severely delayed responses due to the timeouts. Here is what I am doing per the sample

        try
        {
           var chatClient = new GeminiChatClient(apiKey: settings.GoogleApiKey, model: settings.GoogleApiModel);

            var messages = new List<Microsoft.Extensions.AI.ChatMessage>
            {
                new(ChatRole.User, "Hi")
            };

            var options = new ChatOptions
            {
                MaxOutputTokens = 10
            };

            var response = await chatClient.GetResponseAsync(messages, options);
            
            var text = response.Text;

        }
        catch (GeminiApiTimeoutException ex)
        {
            var error = $"Google Gemini API error: {ex.Message}";            
        }
        catch (TimeoutException ex)
        {
            var error = $"Google Gemini API error: {ex.Message}";            
        }
        catch (GeminiApiException ex)
        {
            var error = $"Google Gemini API error: {ex.Message}";
        }
        catch (Exception ex)
        {
            var error = $"Google Gemini API error: {ex.Message}";
        }

My question is how can I control the RequestOptions property if I am using IChatClient? Do I need to build a custom wrapper for GetResponseAsync() and etc? I would have assumed I can add RequestOptions directly to GeminiChatClient

Metadata

Metadata

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions