Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidOperationException when setting Timeout #57

Open
Ar4ics opened this issue Jan 10, 2025 · 4 comments
Open

InvalidOperationException when setting Timeout #57

Ar4ics opened this issue Jan 10, 2025 · 4 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@Ar4ics
Copy link

Ar4ics commented Jan 10, 2025

image
The problem on the line BaseModel.Client.Timeout = requestOptions.Timeout;
Occurs if you pass requestOptions to the method model.GenerateContent:

var requestOptions = new RequestOptions(null, TimeSpan.FromMinutes(2));
var json = await GetResponse1(model, request, requestOptions);

private static async Task<string> GetResponse1(GenerativeModel model, GenerateContentRequest request, RequestOptions? requestOptions = null)
{
    var response = await model.GenerateContent(request, requestOptions);
    return response.Text ?? string.Empty;
}
@jochenkirstaetter
Copy link
Contributor

Hi @Ar4ics

Thanks for reporting this, I'll have a look.

Cheers, JoKi

@jochenkirstaetter jochenkirstaetter self-assigned this Jan 14, 2025
@jochenkirstaetter jochenkirstaetter added the bug Something isn't working label Jan 14, 2025
@jochenkirstaetter
Copy link
Contributor

Hi @Ar4ics
Ohh, I see. That's a wrong implementation currently and it's related to #2 trying to implement a retry mechanism with timeout limit of retries. The exception is thrown after the static HttpClient has been used the first time.

For now, I'm going to remove those lines actually as their intent is different and the implementation is wrong.

Cheers, JoKi

@jochenkirstaetter
Copy link
Contributor

Eventually this article and approach could help to achieve a request-based timeout instead.

https://thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient/

@jochenkirstaetter
Copy link
Contributor

Hi @Ar4ics

Current implementation has been removed. The RequestOptions are ignored for now.
See Release v2.1.0 for more details.

Let me know if that works for you. Thanks.

Going to focus on #2 to improve the handling.

Cheers, JoKi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants