Skip to content

Commit

Permalink
Linting/formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal Patil committed Jan 31, 2025
1 parent 9aa996c commit 68105c8
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
4 changes: 3 additions & 1 deletion libs/aws/langchain_aws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
InMemoryVectorStore,
)


def setup_logging():
import logging
import os

if os.environ.get("LANGCHAIN_AWS_DEBUG", "FALSE").lower() in ["true", "1"]:
DEFAULT_LOG_FORMAT = (
"%(asctime)s %(levelname)s | [%(filename)s:%(lineno)s]"
"%(asctime)s %(levelname)s | [%(filename)s:%(lineno)s]"
"| %(name)s - %(message)s"
)
log_formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
Expand All @@ -30,6 +31,7 @@ def setup_logging():
logging.getLogger("langchain_aws").addHandler(log_handler)
logging.getLogger("langchain_aws").setLevel(logging.DEBUG)


setup_logging()

__all__ = [
Expand Down
5 changes: 1 addition & 4 deletions libs/aws/langchain_aws/chains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
create_neptune_sparql_qa_chain,
)

__all__ = [
"create_neptune_opencypher_qa_chain",
"create_neptune_sparql_qa_chain"
]
__all__ = ["create_neptune_opencypher_qa_chain", "create_neptune_sparql_qa_chain"]
5 changes: 1 addition & 4 deletions libs/aws/langchain_aws/chains/graph_qa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from .neptune_cypher import create_neptune_opencypher_qa_chain
from .neptune_sparql import create_neptune_sparql_qa_chain

__all__ = [
"create_neptune_opencypher_qa_chain",
"create_neptune_sparql_qa_chain"
]
__all__ = ["create_neptune_opencypher_qa_chain", "create_neptune_sparql_qa_chain"]
2 changes: 1 addition & 1 deletion libs/aws/langchain_aws/chains/graph_qa/neptune_cypher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from typing import Any, Optional, Union
from typing import Optional, Union

from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts.base import BasePromptTemplate
Expand Down
4 changes: 2 additions & 2 deletions libs/aws/langchain_aws/chat_models/bedrock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from collections import defaultdict
from operator import itemgetter
Expand Down Expand Up @@ -53,9 +54,8 @@
get_num_tokens_anthropic,
get_token_ids_anthropic,
)
import logging

logger = logging.getLogger("langchain_aws")
logger = logging.getLogger(__name__)


def _convert_one_message_to_text_llama(message: BaseMessage) -> str:
Expand Down
6 changes: 3 additions & 3 deletions libs/aws/langchain_aws/chat_models/bedrock_converse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
import logging
import os
import re
from operator import itemgetter
Expand Down Expand Up @@ -53,9 +54,8 @@
from typing_extensions import Self

from langchain_aws.function_calling import ToolsOutputParser
import logging

logger = logging.getLogger("langchain_aws")
logger = logging.getLogger(__name__)
_BM = TypeVar("_BM", bound=BaseModel)

_DictOrPydanticClass = Union[Dict[str, Any], Type[_BM], Type]
Expand Down Expand Up @@ -519,7 +519,7 @@ def _generate(
stop=stop, **_snake_to_camel_keys(kwargs, excluded_keys={"inputSchema"})
)
logger.debug(f"Input params: {params}")
logger.info(f"Using Bedrock Converse API to generate response")
logger.info("Using Bedrock Converse API to generate response")
response = self.client.converse(
messages=bedrock_messages, system=system, **params
)
Expand Down
4 changes: 2 additions & 2 deletions libs/aws/langchain_aws/graphs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__all__ = [
"BaseNeptuneGraph",
"NeptuneAnalyticsGraph",
"NeptuneAnalyticsGraph",
"NeptuneGraph",
"NeptuneRdfGraph"
"NeptuneRdfGraph",
]
15 changes: 9 additions & 6 deletions libs/aws/langchain_aws/graphs/neptune_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def _format_triples(triples: List[dict]) -> List[str]:
triple_template = "(:`{a}`)-[:`{e}`]->(:`{b}`)"
triple_schema = []
for t in triples:
triple = triple_template.format(
a=t["~from"], e=t["~type"], b=t["~to"]
)
triple = triple_template.format(a=t["~from"], e=t["~type"], b=t["~to"])
triple_schema.append(triple)

return triple_schema
Expand All @@ -21,7 +19,9 @@ def _format_node_properties(n_labels: dict) -> List:
for label, props_item in n_labels.items():
props = props_item["properties"]
np = {
"properties": [{"property": k, "type": v["datatypes"][0]} for k, v in props.items()],
"properties": [
{"property": k, "type": v["datatypes"][0]} for k, v in props.items()
],
"labels": label,
}
node_properties.append(np)
Expand All @@ -36,7 +36,9 @@ def _format_edge_properties(e_labels: dict) -> List:
props = props_item["properties"]
np = {
"type": label,
"properties": [{"property": k, "type": v["datatypes"][0]} for k, v in props.items()],
"properties": [
{"property": k, "type": v["datatypes"][0]} for k, v in props.items()
],
}
edge_properties.append(np)

Expand Down Expand Up @@ -210,7 +212,7 @@ def __init__(
graph_identifier: str,
client: Any = None,
credentials_profile_name: Optional[str] = None,
region_name: Optional[str] = None
region_name: Optional[str] = None,
) -> None:
"""Create a new Neptune Analytics graph wrapper instance."""

Expand Down Expand Up @@ -331,6 +333,7 @@ def _refresh_schema(self) -> None:
{triple_schema}
"""


class NeptuneGraph(BaseNeptuneGraph):
"""Neptune wrapper for graph operations.
Expand Down
5 changes: 2 additions & 3 deletions libs/aws/langchain_aws/llms/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
get_num_tokens_anthropic,
get_token_ids_anthropic,
)
import logging

logger = logging.getLogger("langchain_aws")
logger = logging.getLogger(__name__)

AMAZON_BEDROCK_TRACE_KEY = "amazon-bedrock-trace"
GUARDRAILS_BODY_KEY = "amazon-bedrock-guardrailAction"
Expand Down Expand Up @@ -828,7 +827,7 @@ def _prepare_input_and_invoke(

try:
logger.debug(f"Request body sent to bedrock: {request_options}")
logger.info(f"Using Bedrock Invoke API to generate response")
logger.info("Using Bedrock Invoke API to generate response")
response = self.client.invoke_model(**request_options)

(
Expand Down

0 comments on commit 68105c8

Please sign in to comment.