ai
ai copied to clipboard
AnthropicStream - example copy/paste errors
Description
Check the example from: https://sdk.vercel.ai/docs/api-reference/providers/anthropic-stream
Code example
import Anthropic from '@anthropic-ai/sdk'; import { AnthropicStream, StreamingTextResponse } from 'ai'; import { experimental_buildAnthropicPrompt } from 'ai/prompts';
// Create an Anthropic API client (that's edge friendly??) const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY || '', });
// IMPORTANT! Set the runtime to edge export const runtime = 'edge';
export async function POST(req: Request) {
// Extract the prompt
from the body of the request
const { messages } = await req.json();
// Ask Claude for a streaming chat completion given the prompt const response = await anthropic.completions.create({ prompt: experimental_buildAnthropicPrompt(messages), model: 'claude-2', stream: true, max_tokens_to_sample: 300, }); // Convert the response into a friendly text-stream const stream = AnthropicStream(response); // Respond with the stream return new StreamingTextResponse(stream); }
Additional context
Results with Argument of type 'Stream<Completion>' is not assignable to parameter of type 'Response | AsyncIterable<CompletionChunk>'. Type 'Stream<Completion>' is not assignable to type 'AsyncIterable<CompletionChunk>'. The types returned by 'Symbol.asyncIterator.next(...)' are incompatible between these types. Type 'Promise<IteratorResult<Completion, any>>' is not assignable to type 'Promise<IteratorResult<CompletionChunk, any>>'. Type 'IteratorResult<Completion, any>' is not assignable to type 'IteratorResult<CompletionChunk, any>'. Type 'IteratorYieldResult<Completion>' is not assignable to type 'IteratorResult<CompletionChunk, any>'. Type 'IteratorYieldResult<Completion>' is not assignable to type 'IteratorYieldResult<CompletionChunk>'. Type 'Completion' is not assignable to type 'CompletionChunk'.ts(2345)
What is the version of your anthropic SDK? (the docs are for v0.15.0
and newer)
"@anthropic-ai/sdk": "^0.17.1"
also experiencing this issue with "^0.17.1"
v0.15.0 is what's working for me
I'm still experiencing this issue using v0.15.0. what is the version of ai you're using?
I'm still experiencing this issue using v0.15.0. what is the version of ai you're using? am using [email protected]
can confirm [email protected] and v0.15.0 for the anthropic SDK fixes this issue. hopefully this is addressed in the next version of ai.
I just tried to reproduce with v0.18.0
of the anthropic SDK and the build passed for me. Is this still an issue with that version?
"@anthropic-ai/sdk": "^0.18.0" & "ai": "^3.0.12" - it all works now.