Skip to content

Commit

Permalink
address comments left by @ErikBjare on #188 (fix: limit image size, f…
Browse files Browse the repository at this point in the history
…ixes exception when viewing large images (#185));
  • Loading branch information
ellipsis-dev[bot] authored Oct 9, 2024
1 parent 9a4d2f6 commit 8d909e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gptme/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 []

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))

0 comments on commit 8d909e9

Please sign in to comment.