diff --git a/gptme/message.py b/gptme/message.py index 1810fdc8..f8cda6f0 100644 --- a/gptme/message.py +++ b/gptme/message.py @@ -112,7 +112,7 @@ def _content_files_list( # anthropic limit is 5MB # TODO: use compression to reduce file size # print(f"{len(data)=}") - if len(data) > 5_000_000: + if len(data_bytes) > 5_000_000: # base64 encoding increases the size by approximately 33%, discrepancy with API numbers noted content.append( { "type": "text", @@ -233,7 +233,7 @@ def get_codeblocks(self) -> list[Codeblock]: content_str = "\n" + content_str # check if message contains a code block - backtick_count = content_str.count("\n```") + backtick_count = content_str.count("\n\`\`\`") if backtick_count < 2: return [] @@ -265,14 +265,14 @@ def format_msgs( else: multiline = len(msg.content.split("\n")) > 1 output += "\n" + indent * " " if multiline else "" - for i, block in enumerate(msg.content.split("```")): + for i, block in enumerate(msg.content.split("\`\`\`")): if i % 2 == 0: output += textwrap.indent(block, prefix=indent * " ") continue elif highlight: lang = block.split("\n")[0] block = rich_to_str(Syntax(block.rstrip(), lang)) - output += f"```{block.rstrip()}\n```" + output += f"\`\`\`{block.rstrip()}\n\`\`\`" outputs.append(f"{userprefix}: {output.rstrip()}") return outputs @@ -353,4 +353,4 @@ def len_tokens(content: str | Message | list[Message], model: str = "gpt-4") -> return sum(len_tokens(msg.content, model) for msg in content) if isinstance(content, Message): return len_tokens(content.content, model) - return len(get_tokenizer(model).encode(content)) + return len(get_tokenizer(model).encode(content)) \ No newline at end of file