Skip to content

Commit

Permalink
community[patch]: fix agenerate return value (#14815)
Browse files Browse the repository at this point in the history
Fixed:
  -  `_agenerate` return value in the YandexGPT Chat Model
  - duplicate line in the documentation

Co-authored-by: Dmitry Tyumentsev <[email protected]>
  • Loading branch information
tyumentsev4 and Dmitry Tyumentsev authored Dec 17, 2023
1 parent f1d3f29 commit 78ae276
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docs/docs/integrations/chat/yandex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
"- [API key](https://cloud.yandex.com/en/docs/iam/operations/api-key/create)\n",
" You can specify the key in a constructor parameter `api_key` or in an environment variable `YC_API_KEY`.\n",
"\n",
"In the `model_uri` parameter, specify the model used, see [the documentation](https://cloud.yandex.com/en/docs/yandexgpt/concepts/models#yandexgpt-generation) for more details.\n",
"\n",
"To specify the model you can use `model_uri` parameter, see [the documentation](https://cloud.yandex.com/en/docs/yandexgpt/concepts/models#yandexgpt-generation) for more details.\n",
"\n",
"By default, the latest version of `yandexgpt-lite` is used from the folder specified in the parameter `folder_id` or `YC_FOLDER_ID` environment variable."
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/integrations/llms/yandex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
"- [API key](https://cloud.yandex.com/en/docs/iam/operations/api-key/create)\n",
" You can specify the key in a constructor parameter `api_key` or in an environment variable `YC_API_KEY`.\n",
"\n",
"In the `model_uri` parameter, specify the model used, see [the documentation](https://cloud.yandex.com/en/docs/yandexgpt/concepts/models#yandexgpt-generation) for more details.\n",
"\n",
"To specify the model you can use `model_uri` parameter, see [the documentation](https://cloud.yandex.com/en/docs/yandexgpt/concepts/models#yandexgpt-generation) for more details.\n",
"\n",
"By default, the latest version of `yandexgpt-lite` is used from the folder specified in the parameter `folder_id` or `YC_FOLDER_ID` environment variable."
Expand Down
12 changes: 6 additions & 6 deletions libs/community/langchain_community/chat_models/yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ async def _agenerate(
operation_request, metadata=self._grpc_metadata
)

instruct_response = CompletionResponse()
operation.response.Unpack(instruct_response)
text = instruct_response.alternatives[0].message.text
if stop is not None:
text = enforce_stop_tokens(text, stop)
return text
completion_response = CompletionResponse()
operation.response.Unpack(completion_response)
text = completion_response.alternatives[0].message.text
text = text if stop is None else enforce_stop_tokens(text, stop)
message = AIMessage(content=text)
return ChatResult(generations=[ChatGeneration(message=message)])
6 changes: 3 additions & 3 deletions libs/community/langchain_community/llms/yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ async def _acall(
operation_request, metadata=self._grpc_metadata
)

instruct_response = CompletionResponse()
operation.response.Unpack(instruct_response)
text = instruct_response.alternatives[0].message.text
completion_response = CompletionResponse()
operation.response.Unpack(completion_response)
text = completion_response.alternatives[0].message.text
if stop is not None:
text = enforce_stop_tokens(text, stop)
return text

0 comments on commit 78ae276

Please sign in to comment.