Skip to content
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

Closed
bcholewa opened this issue Mar 7, 2024 · 9 comments
Closed

AnthropicStream - example copy/paste errors #1124

bcholewa opened this issue Mar 7, 2024 · 9 comments
Assignees

Comments

@bcholewa
Copy link

bcholewa commented Mar 7, 2024

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' 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)

@lgrammel
Copy link
Collaborator

lgrammel commented Mar 8, 2024

What is the version of your anthropic SDK? (the docs are for v0.15.0 and newer)

@bcholewa
Copy link
Author

bcholewa commented Mar 8, 2024

"@anthropic-ai/sdk": "^0.17.1"

@GoldinGuy
Copy link

GoldinGuy commented Mar 13, 2024

also experiencing this issue with "^0.17.1"

@Gitnock
Copy link

Gitnock commented Mar 13, 2024

v0.15.0 is what's working for me

@GoldinGuy
Copy link

GoldinGuy commented Mar 14, 2024

I'm still experiencing this issue using v0.15.0. what is the version of ai you're using?

@Gitnock
Copy link

Gitnock commented Mar 14, 2024

I'm still experiencing this issue using v0.15.0. what is the version of ai you're using?
am using ai@3.1.0-canary.1

@GoldinGuy
Copy link

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.

@lgrammel lgrammel self-assigned this Mar 15, 2024
@lgrammel
Copy link
Collaborator

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?

@bcholewa
Copy link
Author

"@anthropic-ai/sdk": "^0.18.0" & "ai": "^3.0.12" - it all works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants