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

YandexGPT client returns an error when invoked #25575

Closed
5 tasks done
nktpv opened this issue Aug 20, 2024 · 5 comments
Closed
5 tasks done

YandexGPT client returns an error when invoked #25575

nktpv opened this issue Aug 20, 2024 · 5 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@nktpv
Copy link
Contributor

nktpv commented Aug 20, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

pip install -U langchain langchain-community yandexcloud
from langchain_community.llms import YandexGPT
from langchain_core.prompts import PromptTemplate
from langchain.chains import LLMChain

os.environ['YC_API_KEY'] = 'xxxxxxx'
os.environ['YC_FOLDER_ID'] = 'xxxxxxx'
llm = YandexGPT()

template = "What is the capital of {country}?"
prompt = PromptTemplate.from_template(template)
llm_chain = LLMChain(prompt=prompt, llm=llm)
country = "Russia"

llm_chain.invoke(country)

raises an error:

Error Message and Stack Trace (if applicable)

WARNING:langchain_community.llms.yandex:Retrying langchain_community.llms.yandex.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised _MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {created_time:"2024-08-20T07:41:09.86231059+00:00", grpc_status:16, grpc_message:"IAM token or API key has to be passed in request"}"
>.
WARNING:langchain_community.llms.yandex:Retrying langchain_community.llms.yandex.completion_with_retry.<locals>._completion_with_retry in 2.0 seconds as it raised _MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {created_time:"2024-08-20T07:41:11.58718279+00:00", grpc_status:16, grpc_message:"IAM token or API key has to be passed in request"}"
>.
WARNING:langchain_community.llms.yandex:Retrying langchain_community.llms.yandex.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised _MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {created_time:"2024-08-20T07:41:14.337100847+00:00", grpc_status:16, grpc_message:"IAM token or API key has to be passed in request"}"
>.
WARNING:langchain_community.llms.yandex:Retrying langchain_community.llms.yandex.completion_with_retry.<locals>._completion_with_retry in 8.0 seconds as it raised _MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {grpc_message:"IAM token or API key has to be passed in request", grpc_status:16, created_time:"2024-08-20T07:41:19.077443222+00:00"}"
>.
WARNING:langchain_community.llms.yandex:Retrying langchain_community.llms.yandex.completion_with_retry.<locals>._completion_with_retry in 16.0 seconds as it raised _MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {created_time:"2024-08-20T07:41:27.822608895+00:00", grpc_status:16, grpc_message:"IAM token or API key has to be passed in request"}"
>.
---------------------------------------------------------------------------
_MultiThreadedRendezvous                  Traceback (most recent call last)
[<ipython-input-11-91d22ce65899>](https://localhost:8080/#) in <cell line: 16>()
     14 country = "Russia"
     15 
---> 16 llm_chain.invoke(country)

22 frames
[/usr/local/lib/python3.10/dist-packages/grpc/_channel.py](https://localhost:8080/#) in _next(self)
    967                     raise StopIteration()
    968                 elif self._state.code is not None:
--> 969                     raise self
    970 
    971 

_MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = "IAM token or API key has to be passed in request"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:158.160.54.160:443 {grpc_message:"IAM token or API key has to be passed in request", grpc_status:16, created_time:"2024-08-20T07:41:44.933096923+00:00"}"
>

Description

I’m trying to use the langchain library to invoke a YandexGPT model. I expected to see a successful response from the model. Instead, I receive an StatusCode.UNAUTHENTICATED error with the message.

Previously, I encountered a similar issue where the error was AttributeError: 'YandexGPT' object has no attribute '_grpc_metadata'. I resolved this by modifying the _BaseYandexGPT class to make _grpc_metadata accessible in child classes, which fixed the issue. However, recent changes to the repository reverted my fix by reintroducing the _grpc_metadata parameter as protected and setting its default value to None.

This change has led to the current issue, where the authentication details are not being passed correctly, resulting in the StatusCode.UNAUTHENTICATED error. The original fix, which made _grpc_metadata accessible, resolved the issue and allowed the code to work as expected. Reverting these changes has introduced a new error without solving the original problem.

System Info

System Information
------------------
> OS:  Linux
> OS Version:  #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024
> Python Version:  3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0]

Package Information
-------------------
> langchain_core: 0.2.33
> langchain: 0.2.14
> langchain_community: 0.2.12
> langsmith: 0.1.99
> langchain_text_splitters: 0.2.2

Optional packages not installed
-------------------------------
> langgraph
> langserve
@langcarl langcarl bot added the investigate label Aug 20, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Aug 20, 2024
@nktpv nktpv changed the title Reverting _grpc_metadata to protected status introduces StatusCode.UNAUTHENTICATED error YandexGPT client returns an error when invoked Aug 20, 2024
@mkhludnev
Copy link
Contributor

may #25617 fix it?

@mkhludnev
Copy link
Contributor

Hi @nktpv , could you please check if #25617 fixes this issue?

@nktpv
Copy link
Contributor Author

nktpv commented Aug 26, 2024

Hi @nktpv , could you please check if #25617 fixes this issue?

yes, this PR contains a solution to the issue described

@mkhludnev
Copy link
Contributor

@nktpv thanks for confirming.
Can you consult me about Pydantic? I have to drop leading underscore changing from private field, but what's the better approach?

@nktpv
Copy link
Contributor Author

nktpv commented Aug 27, 2024

@nktpv thanks for confirming. Can you consult me about Pydantic? I have to drop leading underscore changing from private field, but what's the better approach?

I believe your solution is the best possible one, because to make the grpc_metadata field visible to subclasses, you can only either remove the protected access modifier or directly assign a value to the field through cls. Since the second option isn’t great, I think we can stay with your approach to solving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants