@gensx/anthropic
Anthropic integration for GenSX - Build AI workflows using JSX.
Installation
npm install @gensx/anthropic
Usage
import * as gensx from "@gensx/core";
import { AnthropicProvider, ChatCompletion } from "@gensx/anthropic";
const ChatBot = gensx.Component(async ({ userInput }) => {
return (
<AnthropicProvider apiKey={process.env.ANTHROPIC_API_KEY!}>
<ChatCompletion
system="You are a helpful assistant."
messages={[
{ role: "user", content: userInput },
]}
model="claude-3-5-sonnet-latest"
temperature={0.7}
/>
</AnthropicProvider>
);
});
const StreamingChat = gensx.Component(async ({ userInput }) => {
return (
<AnthropicProvider apiKey={process.env.ANTHROPIC_API_KEY!}>
<ChatCompletion
system="You are a helpful assistant."
messages={[
{ role: "user", content: userInput },
]}
stream={true}
model="claude-3-5-sonnet-latest"
>
{async (stream) => {
for await (const token of stream) {
process.stdout.write(token);
}
}}
</AnthropicProvider>
</OpenAIProvider>
);
});