zed icon indicating copy to clipboard operation
zed copied to clipboard

Error when pasting image in AI assistant chat

Open erik-balfe opened this issue 1 year ago • 4 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

I get error popup from LLM request about Anthropic cache blocks number. a maximum of 4 blocks with cache_conrol may be provider. Found 5 Happens when have long conversation with tens of messages using Zed AI anthropic sonnet 3.5. An image was pasted in the latest message. It looks image message always has the cache_control flag on it. So it leads to exceeding the limit for cached blocks in anthropic API.

Environment

Zed: v0.161.2 (Zed) OS: Linux Wayland bluefin 41 Memory: 31 GiB Architecture: x86_64 GPU: Intel(R) Xe Graphics (TGL GT2) || Intel open-source Mesa driver || Mesa 24.2.4

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No response

erik-balfe avatar Nov 17 '24 20:11 erik-balfe

Can you provide steps to reproduce this? I tried pasting many images and in distinct conversational sides, but was unable to trigger it.

notpeter avatar Dec 03 '24 18:12 notpeter

I cannot afford to play with it to find the exact case, as it costs money to use Sonnet with many messages and images. However, three times that I faced the issue, it was with multiple messages in the chat, so some of them might have been cached (I don’t know how caching works in Zed IDE). In my latest message, I wanted to insert an image, so I pasted it via Ctrl-V, and when launching the request, it threw the error about cached blocks limit.

Once, in such a case, I just switched to gpt-4o-mini, and the assistant returned the expected output normally.

I suppose I closed and reopened the IDE between chat starts, as it was a long dialogue with the assistant spread over several days. Maybe that's what you don't do when trying to manually reproduce the bug. I also could have opened it in several instances of the IDE.

erik-balfe avatar Dec 05 '24 14:12 erik-balfe

I can confirm that this currently happens with pasted images in the prompt when using the default Zed Anthropic provider with Sonnet 3.5 and 3.7.

The original error that I had:

cloud language model completion failed with status 400 Bad Request: A maximum of 4 blocks with cache_control may be provided. Found 5.

This is what my original prompt looked like:

Help me build an app drawer/modal that lets users add a new security token in the main page.
\`\`\`svelte /src/routes/+page.svelte
<script>
	import { PlusIcon, Settings } from 'lucide-svelte';
	import TokenList from '$lib/components/tokens/TokenList.svelte';
	
                                 <<< ....... first code block. >>>
\`\`\`

Requirements:
1. Clicking on the `+` icons, opens the drawer. Clicking outside of the drawer should dismiss the drawer.
2. You can take design inspiration from the given screenshot:

<<< First pasted image >>>

3. Users can either fill in the token details manually, or scan a QR code to import a token.
4. Note that clicking on the Scan QR code button loads a camera feed to scan a QR code.  
 a. We can skip the actual implementation of the QR code scanning for now; simply ask for camera permission and show the feed.
  b. If the camera permission is denied or not available, simply go back to showing the Scan QR code button.

<<< Second pasted image >>>

You can also take inspiration from already built components:
src/lib/components/ui    <<<<< - this a folder containing two files
\`\`\`svelte src/lib/components/ui/Editable.svelte
<script>
	let { class: className, value, onEdit = undefined, children = undefined } = $props();
	let initialValue = value;
</script>

<div
                                 <<< ....... second code block. >>>
\`\`\`

\`\`\`svelte src/lib/components/ui/Switch.svelte
<script>
	let {
		/** @type {boolean | undefined} */ checked = $bindable(undefined),
		/** @type {boolean | undefined} */ disabled = undefined,
		/** @type {string} */ class: className = '',
		/** @type {((checked: boolean) => void) | undefined} */ onCheckedChange = undefined
	} = $props();

	function handleClick() {
		checked = !checked;

                                 <<< ....... third code block. >>>
\`\`\`

Notice that the original prompt had two pasted images and three markdown code blocks, so maybe those are getting cached?

I managed to solve this by moving the last paragraph + code block together with the first paragraph and code block (effectively making it one big paragraph with no empty lines in-between). But after the first response from the model, any follow up questions are now causing the same error.

babhishek21 avatar Mar 03 '25 15:03 babhishek21

Perhaps related:

  • #31438

notpeter avatar May 28 '25 16:05 notpeter

I am no longer able to reproduce this. Closing as stale.

notpeter avatar Sep 03 '25 21:09 notpeter