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

The baseUrl passed to ChatGoogleGenerativeAI does not work #627

Open
1 of 12 tasks
fanenr opened this issue Dec 25, 2024 · 2 comments
Open
1 of 12 tasks

The baseUrl passed to ChatGoogleGenerativeAI does not work #627

fanenr opened this issue Dec 25, 2024 · 2 comments
Labels
p:langchain_google langchain_google package. t:bug Something isn't working

Comments

@fanenr
Copy link

fanenr commented Dec 25, 2024

System Info

langchain: 0.7.7+1
langchain_google: 0.6.4+1

dart: 3.5.4
flutter: 3.24.5

Related Components

  • doc-loaders
  • doc-transformers
  • prompts
  • llms
  • chat-models
  • output-parsers
  • chains
  • memory
  • stores
  • embeddings
  • retrievers
  • agents

Reproduction

Here's my code (with a few things omitted):

final apiUrl = 'abc';
final apiKey = '...';
final model = 'gemini-1.5-flash-002';

final llm = ChatGoogleGenerativeAI(
  apiKey: apiKey,
  baseUrl: apiUrl,
  defaultOptions: ChatGoogleGenerativeAIOptions(
    model: model,
  ),
);

final res = llm.invoke(...);

I set the baseUrl to 'abc' (an incorrect Url), but llm.invoke returns the message just fine. I'm guessing that llm isn't using the baseUrl I set to initiate the request.

Expected behavior

As stated above, the custom baseUrl should take effect.

I only tested ChatGoogleGenerativeAI and found this issue. I'm not sure if other components (e.g. GoogleGenerativeAI...) also have this problem.

Thanks again for creating langchain_dart.

@fanenr fanenr added the t:bug Something isn't working label Dec 25, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in LangChain.dart Dec 25, 2024
@fanenr fanenr changed the title The baseUrl passed when creating ChatGoogleGenerativeAI doesn't work The baseUrl passed to ChatGoogleGenerativeAI does not work Dec 25, 2024
@davidmigloz davidmigloz added the p:langchain_google langchain_google package. label Dec 25, 2024
@Nana-Kwame-bot
Copy link
Contributor

Nana-Kwame-bot commented Dec 26, 2024

I was just about to create an issue for this I can't use a proxy with GoogleGenerativeAIEmbeddings and it seems the same applies to ChatGoogleGenerativeAI. We're validating the api key even when we want to use a proxy and I'm seeing this error now.

[        ] I/flutter ( 6522): │ API key not valid. Please pass a valid API key.
[   +7 ms] I/flutter ( 6522):
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
[        ] I/flutter ( 6522): │ #0   parseBatchEmbedContentsResponse (package:google_generative_ai/src/api.dart:631:38)
[        ] I/flutter ( 6522): │ #1   <asynchronous suspension>
[        ] I/flutter ( 6522): │ #2   GoogleGenerativeAIEmbeddings.embedDocuments.<anonymous closure>
(package:langchain_google/src/embeddings/google_ai/google_ai_embeddings.dart:162:22)
[        ] I/flutter ( 6522): │ #3   <asynchronous suspension>
[        ] I/flutter ( 6522): │ #4   Future.wait.<anonymous closure> (dart:async/future.dart:520:21)
[        ] I/flutter ( 6522): │ #5   <asynchronous suspension>
[        ] I/flutter ( 6522): │ #6   GoogleGenerativeAIEmbeddings.embedDocuments
(package:langchain_google/src/embeddings/google_ai/google_ai_embeddings.dart:160:49)
[        ] I/flutter ( 6522): │ #7   <asynchronous suspension>

Error seems to be coming from here:

BatchEmbedContentsResponse parseBatchEmbedContentsResponse(Object jsonObject) {
  return switch (jsonObject) {
    {'embeddings': final List<Object?> embeddings} =>
      BatchEmbedContentsResponse(
          embeddings.map(_parseContentEmbedding).toList()),
    {'error': final Object error} => throw parseError(error),
    _ => throw unhandledFormat('EmbedContentResponse', jsonObject)
  };
}

and here:

GenerativeAIException parseError(Object jsonObject) {
  return switch (jsonObject) {
    {
      'message': final String message,
      'details': [{'reason': 'API_KEY_INVALID'}, ...]
    } =>
      InvalidApiKey(message),
    {'message': UnsupportedUserLocation._message} => UnsupportedUserLocation(),
    {'message': final String message} => ServerException(message),
    _ => throw unhandledFormat('server error', jsonObject)
  };
}

It was working fine about a month ago, the proxy that is.

@davidmigloz
Copy link
Owner

davidmigloz commented Dec 28, 2024

I'll take a look. I remember I had to use a custom http client to override the base url as the google_generative_ai package was not allowing to change it. Not sure if they allow it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p:langchain_google langchain_google package. t:bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants