npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

anthropic-react-native

v0.1.0

Published

Anthropic React Native API Client without polyfills

Downloads

5

Readme

Anthropic React Native Client

The goal of this library is to use React Native SSE instead of polyfills to support calling the Anthropic API directly from React Native with streaming. The package uses the same types and API as the Anthropic Node SDK wherever possible.

[!CAUTION] This package is meant to be used with a proxy to Anthropic like the one Backmesh provides. The baseURL parameter for this Anthropic client is thus mandatory. If you do not use a proxy and set the baseURL to https://api.anthropic.com/v1, you are basically exposing your Anthropic API key on the internet! You should never expose any secrets in the bundle of a web or mobile app. The correct usage of this client is to create an endpoint on a proxy server for communication with Anthropic and then use that endpoint with a user generated auth JWT in your app.

Contributions and Feature Requests

If you would like to contribute or request a feature, please join our Discord and ask questions in the #oss channel or create a pull request or issue.

Setup

Install the package

npm i anthropic-react-native

And then instantiate the client:

import Anthropic from 'anthropic-react-native';

const client = new Anthropic({
  baseURL:
    'https://edge.backmesh.com/v1/proxy/PyHU4LvcdsQ4gm2xeniAFhMyuDl2/yWo35DdTROVMT52N0qs4/',
  // The backmesh proxy uses your auth provider's JWT to authorize access
  apiKey: supabase.auth.session().access_token,
});

Usage

The streaming APIs uses an EventSource from react-native-sse under the hood to provide a required typed event callbacks for each of the Anthropic API Types.

client.messages.stream(
  {
    model: 'claude-3-5-sonnet-20240620',
    messages: [{ role: 'user', content: userInput }],
    max_tokens: 1024,
  },
  {
    onError: (error) => {
      console.error('SSE Error:', error); // Handle any errors here
    },
    onMessageStart: () => {
      setUserInput('');
    },
    onContentBlockDelta: (ev: ContentBlockDeltaEvent) => {
      if (ev.delta.type === 'text_delta')
        setText((prevText) => prevText + (ev.delta as TextDelta).text);
    },
    onMessageStop: () => {
      console.log('SSE connection for completion closed.'); // Handle when the connection is opened
    },
  }
);

Check the example for more details

Coverage

License

MIT