Skip to content

Commit 953592d

Browse files
authored
1 parent 19fff8c commit 953592d

File tree

8 files changed

+56
-30
lines changed

8 files changed

+56
-30
lines changed

libs/langchain/langchain/agents/agent_iterator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def update_iterations(self) -> None:
147147
self.iterations += 1
148148
self.time_elapsed = time.time() - self.start_time
149149
logger.debug(
150-
f"Agent Iterations: {self.iterations} ({self.time_elapsed:.2f}s elapsed)",
150+
"Agent Iterations: %s (%.2fs elapsed)",
151+
self.iterations,
152+
self.time_elapsed,
151153
)
152154

153155
def make_final_outputs(

libs/langchain/langchain/memory/entity.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,21 @@ def get(self, key: str, default: Optional[str] = None) -> Optional[str]:
146146
or default
147147
or ""
148148
)
149-
logger.debug(f"Upstash Redis MEM get '{self.full_key_prefix}:{key}': '{res}'")
149+
logger.debug(
150+
"Upstash Redis MEM get '%s:%s': '%s'", self.full_key_prefix, key, res
151+
)
150152
return res
151153

152154
def set(self, key: str, value: Optional[str]) -> None:
153155
if not value:
154156
return self.delete(key)
155157
self.redis_client.set(f"{self.full_key_prefix}:{key}", value, ex=self.ttl)
156158
logger.debug(
157-
f"Redis MEM set '{self.full_key_prefix}:{key}': '{value}' EX {self.ttl}",
159+
"Redis MEM set '%s:%s': '%s' EX %s",
160+
self.full_key_prefix,
161+
key,
162+
value,
163+
self.ttl,
158164
)
159165
return None
160166

@@ -249,15 +255,19 @@ def get(self, key: str, default: Optional[str] = None) -> Optional[str]:
249255
or default
250256
or ""
251257
)
252-
logger.debug(f"REDIS MEM get '{self.full_key_prefix}:{key}': '{res}'")
258+
logger.debug("REDIS MEM get '%s:%s': '%s'", self.full_key_prefix, key, res)
253259
return res
254260

255261
def set(self, key: str, value: Optional[str]) -> None:
256262
if not value:
257263
return self.delete(key)
258264
self.redis_client.set(f"{self.full_key_prefix}:{key}", value, ex=self.ttl)
259265
logger.debug(
260-
f"REDIS MEM set '{self.full_key_prefix}:{key}': '{value}' EX {self.ttl}",
266+
"REDIS MEM set '%s:%s': '%s' EX %s",
267+
self.full_key_prefix,
268+
key,
269+
value,
270+
self.ttl,
261271
)
262272
return None
263273

libs/langchain/langchain/retrievers/multi_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def agenerate_queries(
128128
)
129129
lines = response["text"] if isinstance(self.llm_chain, LLMChain) else response
130130
if self.verbose:
131-
logger.info(f"Generated queries: {lines}")
131+
logger.info("Generated queries: %s", lines)
132132
return lines
133133

134134
async def aretrieve_documents(
@@ -194,7 +194,7 @@ def generate_queries(
194194
)
195195
lines = response["text"] if isinstance(self.llm_chain, LLMChain) else response
196196
if self.verbose:
197-
logger.info(f"Generated queries: {lines}")
197+
logger.info("Generated queries: %s", lines)
198198
return lines
199199

200200
def retrieve_documents(

libs/langchain/langchain/retrievers/re_phraser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _get_relevant_documents(
7474
query,
7575
{"callbacks": run_manager.get_child()},
7676
)
77-
logger.info(f"Re-phrased question: {re_phrased_question}")
77+
logger.info("Re-phrased question: %s", re_phrased_question)
7878
return self.retriever.invoke(
7979
re_phrased_question,
8080
config={"callbacks": run_manager.get_child()},

libs/langchain/langchain/retrievers/self_query/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _get_relevant_documents(
320320
config={"callbacks": run_manager.get_child()},
321321
)
322322
if self.verbose:
323-
logger.info(f"Generated Query: {structured_query}")
323+
logger.info("Generated Query: %s", structured_query)
324324
new_query, search_kwargs = self._prepare_query(query, structured_query)
325325
return self._get_docs_with_query(new_query, search_kwargs)
326326

@@ -343,7 +343,7 @@ async def _aget_relevant_documents(
343343
config={"callbacks": run_manager.get_child()},
344344
)
345345
if self.verbose:
346-
logger.info(f"Generated Query: {structured_query}")
346+
logger.info("Generated Query: %s", structured_query)
347347
new_query, search_kwargs = self._prepare_query(query, structured_query)
348348
return await self._aget_docs_with_query(new_query, search_kwargs)
349349

libs/langchain/langchain/smith/evaluation/runner_utils.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _wrap_in_chain_factory(
207207
# It's an arbitrary function, wrap it in a RunnableLambda
208208
user_func = cast(Callable, llm_or_chain_factory)
209209
sig = inspect.signature(user_func)
210-
logger.info(f"Wrapping function {sig} as RunnableLambda.")
210+
logger.info("Wrapping function %s as RunnableLambda.", sig)
211211
wrapped = RunnableLambda(user_func)
212212
return lambda: wrapped
213213
constructor = cast(Callable, llm_or_chain_factory)
@@ -416,7 +416,7 @@ def _validate_example_inputs(
416416
# Otherwise it's a runnable
417417
_validate_example_inputs_for_chain(example, chain, input_mapper)
418418
elif isinstance(chain, Runnable):
419-
logger.debug(f"Skipping input validation for {chain}")
419+
logger.debug("Skipping input validation for %s", chain)
420420

421421

422422
## Shared Evaluator Setup Utilities
@@ -461,16 +461,19 @@ def _determine_input_key(
461461
input_key = config.input_key
462462
if run_inputs and input_key not in run_inputs:
463463
logger.warning(
464-
f"Input key {input_key} not in chain's specified"
465-
f" input keys {run_inputs}. Evaluation behavior may be undefined.",
464+
"Input key %s not in chain's specified input keys %s. "
465+
"Evaluation behavior may be undefined.",
466+
input_key,
467+
run_inputs,
466468
)
467469
elif run_inputs and len(run_inputs) == 1:
468470
input_key = run_inputs[0]
469471
elif run_inputs is not None and len(run_inputs) > 1:
470472
logger.warning(
471-
f"Chain expects multiple input keys: {run_inputs},"
472-
f" Evaluator is likely to fail. Evaluation behavior may be undefined."
473+
"Chain expects multiple input keys: %s,"
474+
" Evaluator is likely to fail. Evaluation behavior may be undefined."
473475
" Specify an input_key in the RunEvalConfig to avoid this warning.",
476+
run_inputs,
474477
)
475478

476479
return input_key
@@ -485,16 +488,19 @@ def _determine_prediction_key(
485488
prediction_key = config.prediction_key
486489
if run_outputs and prediction_key not in run_outputs:
487490
logger.warning(
488-
f"Prediction key {prediction_key} not in chain's specified"
489-
f" output keys {run_outputs}. Evaluation behavior may be undefined.",
491+
"Prediction key %s not in chain's specified output keys %s. "
492+
"Evaluation behavior may be undefined.",
493+
prediction_key,
494+
run_outputs,
490495
)
491496
elif run_outputs and len(run_outputs) == 1:
492497
prediction_key = run_outputs[0]
493498
elif run_outputs is not None and len(run_outputs) > 1:
494499
logger.warning(
495-
f"Chain expects multiple output keys: {run_outputs},"
496-
f" Evaluation behavior may be undefined. Specify a prediction_key"
500+
"Chain expects multiple output keys: %s,"
501+
" Evaluation behavior may be undefined. Specify a prediction_key"
497502
" in the RunEvalConfig to avoid this warning.",
503+
run_outputs,
498504
)
499505
return prediction_key
500506

@@ -820,9 +826,11 @@ async def _arun_llm_or_chain(
820826
result = output
821827
except Exception as e:
822828
logger.warning(
823-
f"{chain_or_llm} failed for example {example.id} "
824-
f"with inputs {example.inputs}"
825-
f"\n{e!r}",
829+
"%s failed for example %s with inputs %s\n%s",
830+
chain_or_llm,
831+
example.id,
832+
example.inputs,
833+
e,
826834
)
827835
result = EvalError(Error=e)
828836
return result
@@ -981,9 +989,12 @@ def _run_llm_or_chain(
981989
except Exception as e:
982990
error_type = type(e).__name__
983991
logger.warning(
984-
f"{chain_or_llm} failed for example {example.id} "
985-
f"with inputs {example.inputs}"
986-
f"\nError Type: {error_type}, Message: {e}",
992+
"%s failed for example %s with inputs %s\nError Type: %s, Message: %s",
993+
chain_or_llm,
994+
example.id,
995+
example.inputs,
996+
error_type,
997+
e,
987998
)
988999
result = EvalError(Error=e)
9891000
return result
@@ -1113,7 +1124,9 @@ def _run_batch_evaluators(self, runs: dict[str, Run]) -> list[dict]:
11131124
project_id=self.project.id,
11141125
)
11151126
except Exception as e:
1116-
logger.error(f"Error running batch evaluator {evaluator!r}: {e}")
1127+
logger.exception(
1128+
"Error running batch evaluator %s: %s", repr(evaluator), e
1129+
)
11171130
return aggregate_feedback
11181131

11191132
def _collect_metrics(self) -> tuple[dict[str, _RowResult], dict[str, Run]]:
@@ -1174,15 +1187,15 @@ def finish(
11741187
agg_feedback = results.get_aggregate_feedback()
11751188
_display_aggregate_results(agg_feedback)
11761189
except Exception as e:
1177-
logger.debug(f"Failed to print aggregate feedback: {e!r}")
1190+
logger.debug("Failed to print aggregate feedback: %s", e, exc_info=True)
11781191
try:
11791192
# Closing the project permits name changing and metric optimizations
11801193
self.client.update_project(
11811194
self.project.id,
11821195
end_time=datetime.now(timezone.utc),
11831196
)
11841197
except Exception as e:
1185-
logger.debug(f"Failed to close project: {e!r}")
1198+
logger.debug("Failed to close project: %s", e, exc_info=True)
11861199
return results
11871200

11881201
@classmethod

libs/langchain/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ select = [
159159
"FA", # flake8-future-annotations
160160
"FBT", # flake8-boolean-trap
161161
"FLY", # flake8-flynt
162+
"G", # flake8-logging-format
162163
"I", # isort
163164
"ICN", # flake8-import-conventions
164165
"INT", # flake8-gettext

libs/langchain/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)