-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnthropicStream - example copy/paste errors #1124
Comments
What is the version of your anthropic SDK? (the docs are for |
"@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? |
|
can confirm ai@3.1.0-canary.1 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 |
"@anthropic-ai/sdk": "^0.18.0" & "ai": "^3.0.12" - it all works now. |
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 requestconst { 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' is not assignable to parameter of type 'Response | AsyncIterable'.
Type 'Stream' is not assignable to type 'AsyncIterable'.
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' is not assignable to type 'IteratorResult<CompletionChunk, any>'.
Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'.
Type 'Completion' is not assignable to type 'CompletionChunk'.ts(2345)
The text was updated successfully, but these errors were encountered: