Skip to content

Commit 4dde673

Browse files
TLSDCgasse
authored andcommitted
Tuning warning down to info in BaseMessage (#136)
* switching warning to info * making warning optionnal
1 parent 95f423d commit 4dde673

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/agentlab/agents/dynamic_prompting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def fit_tokens(
260260
)
261261
prompt_str = "\n".join([p["text"] for p in prompt if p["type"] == "text"])
262262
elif isinstance(prompt, BaseMessage):
263-
prompt_str = str(prompt)
263+
prompt_str = prompt.__str__(warn_if_image=False)
264264
else:
265265
raise ValueError(f"Unrecognized type for prompt: {type(prompt)}")
266266
n_token = count_tokens(prompt_str, model=model_name)

src/agentlab/llm/llm_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,16 @@ def __init__(self, role: str, content: Union[str, list[dict]]):
328328
self["role"] = role
329329
self["content"] = deepcopy(content)
330330

331-
def __str__(self) -> str:
331+
def __str__(self, warn_if_image=False) -> str:
332332
if isinstance(self["content"], str):
333333
return self["content"]
334334
if not all(elem["type"] == "text" for elem in self["content"]):
335-
logging.warning(
336-
"The content of the message has images, which are not displayed in the string representation."
337-
)
335+
msg = "The content of the message has images, which are not displayed in the string representation."
336+
if warn_if_image:
337+
logging.warning(msg)
338+
else:
339+
logging.info(msg)
340+
338341
return "\n".join([elem["text"] for elem in self["content"] if elem["type"] == "text"])
339342

340343
def add_content(self, type: str, content: Any):

0 commit comments

Comments
 (0)