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

Adding logging #391

Merged
merged 14 commits into from
Feb 8, 2023
Merged
Prev Previous commit
Next Next commit
cr
  • Loading branch information
Jerry Liu committed Feb 8, 2023
commit acce8bd12818b7a1c8dd89f702cc06695c9b75ee
2 changes: 1 addition & 1 deletion examples/vector_indices/index_simple.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gpt_index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@
import logging
from logging import NullHandler

# best practices for library logging: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
# best practices for library logging:
# https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
logging.getLogger(__name__).addHandler(NullHandler())
3 changes: 2 additions & 1 deletion gpt_index/indices/query/keyword_table/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def _get_nodes_for_response(
if logging.getLogger(__name__).getEffectiveLevel() == logging.DEBUG:
for chunk_idx, node in zip(sorted_chunk_indices, sorted_nodes):
logging.debug(
f"> Querying with idx: {chunk_idx}: {truncate_text(node.get_text(), 50)}"
f"> Querying with idx: {chunk_idx}: "
f"{truncate_text(node.get_text(), 50)}"
)

return sorted_nodes
Expand Down
4 changes: 3 additions & 1 deletion gpt_index/indices/query/tree/leaf_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ def _query_level(
f">[Level {level}] Selected node: "
f"[{number}]/[{','.join([str(int(n)) for n in numbers])}]"
)
debug_str = " ".join(selected_node.get_text().splitlines())
logging.debug(
f">[Level {level}] Node "
f"[{number}] Summary text: { truncate_text(' '.join(selected_node.get_text().splitlines()), 100) }"
f"[{number}] Summary text: "
f"{ truncate_text(debug_str, 100) }"
)
result_response = self._query_with_selected_node(
selected_node,
Expand Down
2 changes: 1 addition & 1 deletion gpt_index/indices/query/vector_store/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _get_nodes_for_response(
if similarity_tracker is not None:
similarity_tracker.add(node, match.score)

if logging.logger.getEffectiveLevel() == logging.DEBUG:
if logging.getLogger(__name__).getEffectiveLevel() == logging.DEBUG:
fmt_txts = []
for node_idx, node_similarity, node in zip(
top_k_ids, top_k_scores, top_k_nodes
Expand Down
2 changes: 1 addition & 1 deletion gpt_index/indices/query/vector_store/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _get_nodes_for_response(
nodes = nodes[: self.similarity_top_k]
node_idxs = [str(i) for i in range(len(nodes))]

if logging.logger.getEffectiveLevel() == logging.DEBUG:
if logging.getLogger(__name__).getEffectiveLevel() == logging.DEBUG:
fmt_txts = []
for node_idx, node in zip(node_idxs, nodes):
fmt_txt = f"> [Node {node_idx}] {truncate_text(node.get_text(), 100)}"
Expand Down
4 changes: 2 additions & 2 deletions gpt_index/readers/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def _read_message(self, channel_id: str, message_ts: str) -> str:
next_cursor = result["response_metadata"]["next_cursor"]
except SlackApiError as e:
if e.response["error"] == "ratelimited":
logger.error(
logging.error(
"Rate limit error reached, sleeping for: {} seconds".format(
e.response.headers["retry-after"]
)
)
time.sleep(int(e.response.headers["retry-after"]))
else:
logger.error("Error parsing conversation replies: {}".format(e))
logging.error("Error parsing conversation replies: {}".format(e))

return "\n\n".join(messages_text)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"transformers",
"nltk",
"numpy",
"tenacity",
"tenacity<8.2.0",
"pandas",
]

Expand Down