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

fix: raise botocore exceptions #193

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/aws/langchain_aws/chat_models/bedrock_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def _messages_to_bedrock(
)
bedrock_messages.append(curr)
else:
raise ValueError()
raise ValueError(f"Unsupported message type {type(msg)}")
return bedrock_messages, bedrock_system


Expand Down
4 changes: 3 additions & 1 deletion libs/aws/langchain_aws/embeddings/bedrock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import logging
import os
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -153,7 +154,8 @@ def _embedding_func(self, text: str) -> List[float]:
return response_body.get("embedding")

except Exception as e:
raise ValueError(f"Error raised by inference endpoint: {e}")
logging.error(f"Error raised by inference endpoint: {e}")
raise e

def _normalize_vector(self, embeddings: List[float]) -> List[float]:
"""Normalize the embedding to a unit vector."""
Expand Down
11 changes: 9 additions & 2 deletions libs/aws/langchain_aws/llms/bedrock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import logging
import os
import warnings
from abc import ABC
Expand Down Expand Up @@ -734,7 +735,10 @@ def _prepare_input_and_invoke(
) = LLMInputOutputAdapter.prepare_output(provider, response).values()

except Exception as e:
raise ValueError(f"Error raised by bedrock service: {e}")
logging.error(f"Error raised by bedrock service: {e}")
if run_manager is not None:
run_manager.on_llm_error(e)
raise e

if stop is not None:
text = enforce_stop_tokens(text, stop)
Expand Down Expand Up @@ -854,7 +858,10 @@ def _prepare_input_and_invoke_stream(
response = self.client.invoke_model_with_response_stream(**request_options)

except Exception as e:
raise ValueError(f"Error raised by bedrock service: {e}")
logging.error(f"Error raised by bedrock service: {e}")
if run_manager is not None:
run_manager.on_llm_error(e)
raise e

for chunk in LLMInputOutputAdapter.prepare_output_stream(
provider,
Expand Down
11 changes: 9 additions & 2 deletions libs/aws/langchain_aws/llms/sagemaker_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Sagemaker InvokeEndpoint API."""

import io
import logging
import re
from abc import abstractmethod
from typing import Any, Dict, Generic, Iterator, List, Mapping, Optional, TypeVar, Union
Expand Down Expand Up @@ -338,7 +339,10 @@ def _stream(
run_manager.on_llm_new_token(chunk.text)

except Exception as e:
raise ValueError(f"Error raised by streaming inference endpoint: {e}")
logging.error(f"Error raised by streaming inference endpoint: {e}")
if run_manager is not None:
run_manager.on_llm_error(e)
raise e

def _call(
self,
Expand Down Expand Up @@ -384,7 +388,10 @@ def _call(
**_endpoint_kwargs,
)
except Exception as e:
raise ValueError(f"Error raised by inference endpoint: {e}")
logging.error(f"Error raised by inference endpoint: {e}")
if run_manager is not None:
run_manager.on_llm_error(e)
raise e

text = self.content_handler.transform_output(response["Body"])
if stop is not None:
Expand Down
Loading