4.0.3 • Published 2 months ago

@charisma-ai/react v4.0.3

Weekly downloads
80
License
MIT
Repository
github
Last release
2 months ago

Charisma for React

Charisma.ai chat component for React.

pnpm i @charisma-ai/react

Setup in Charisma

After you have signed up at Charisma.ai, and logged in, make sure you have a valid licence (a free trial licence is available).

Then, on your My Stories page, click to Create a new game story.

In your story add a subplot, and a few character nodes, and player nodes.

From the story editor left navigation bar, click ... next to your subplot name, and select Edit details. Take note of the reference ID which is a uuid.

On the story overview page scroll down to Play API Access and generate and/or copy the API key. This will enable access to start playthroughs of your story.

At the top of the navbar on the left, underneath the title, your version number, or 'draft' will be displayed. You can use -1 for your most recent draft, or the version number to select a particular version of your story.

Finally the story ID can be found in the url, eg. https://charisma.ai/stories/12345 gives you ID 12345.

Try the Playground App

From the root of this project, run pnpm install and pnpm build to install dependencies in node_modules, and create the dist directory with the compiled package respectively.

From the root of this project, navigate to test/test-app/. Install dependencies here with pnpm install and paste your apiKey into the parameter defined in test/test-app/src/App.tsx. You can now start the playground app which has a form to input your story parameters. You can launch the playground app from the root of this project using pnpm run playground.

Once the page loads, enter your conversation parameters, and the Confirm button will appear. Click it. This opens the chat, where you can click start, and would expect to see the first character nodes from your story start to appear on the page. Type your player responses in the input box.

Basic Code Example

import { Playthrough, Conversation } from "@charisma-ai/react";
import { createPlaythroughToken, createConversation } from "@charisma-ai/sdk";

const MyChat = () => {
  // If you need to get a playthrough token or conversation id, you may consider
  // doing this as a `useEffect` hook, otherwise skip this:

  const [playthroughToken, setPlaythroughToken] = useState<string>();
  const [conversationUuid, setConversationUuid] = useState<string>();
  useEffect(() => {
    async function run() {
      const tokenResult = await createPlaythroughToken({
        storyId,
        version,
        userToken,
      });
      const conversationResult = await createConversation(newToken);

      setPlaythroughToken(tokenResult.token);
      setConversationUuid(conversationResult.conversationUuid);
    }
    run();
  }, [storyId, version, userToken]);

  return (
    <Playthrough playthroughToken={playthroughToken}>
      <Conversation conversationUuid={conversationUuid}>
        {({ messages, inputValue, start, reply, type }) => (
          <>
            <button onClick={() => start()}>Start</button>
            {messages.map(({ message: { text } }) => (
              <div>{text}</div>
            ))}
            <input
              onChange={({ currentTarget: { value } }) => type(value)}
              value={inputValue}
              onKeyPress={({ key }) => {
                if (key === "Enter") {
                  reply({ text: inputValue });
                }
              }}
            />
          </>
        )}
      </Conversation>
    </Playthrough>
  );
}

For a full list of prop types, see the TypeScript definition file.

4.0.3

2 months ago

4.0.3-alpha.2

2 months ago

4.0.3-alpha

3 months ago

4.0.2-alpha

3 months ago

4.0.1

3 months ago

4.0.0-alpha.5

9 months ago

4.0.0-alpha.4

9 months ago

4.0.0

8 months ago

4.0.0-alpha.3

12 months ago

4.0.0-alpha.2

12 months ago

4.0.0-alpha.1

1 year ago

3.5.0

1 year ago

3.4.0

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.3.0

2 years ago

3.3.0-alpha.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.1.0-alpha.1

3 years ago

3.0.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-alpha.10

3 years ago

2.0.0-alpha.8

3 years ago

2.0.0-alpha.9

3 years ago

2.0.0-alpha.7

4 years ago

2.0.0-alpha.6

4 years ago

2.0.0-alpha.5

4 years ago

2.0.0-alpha.3

4 years ago

2.0.0-alpha.4

4 years ago

2.0.0-alpha.2

4 years ago

2.0.0-alpha.1

4 years ago

1.10.0-alpha.1

4 years ago

1.10.0-alpha.2

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.8.0-alpha.1

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.6.0-alpha.1

4 years ago

1.5.0

4 years ago

1.5.0-alpha.3

4 years ago

1.5.0-alpha.2

5 years ago

1.5.0-alpha.1

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.3.0-alpha.1

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.2.0-alpha.4

5 years ago

1.2.0-alpha.3

5 years ago

1.2.0-alpha.2

5 years ago

1.2.0-alpha.1

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-alpha.16

5 years ago

1.0.0-alpha.15

5 years ago

1.0.0-alpha.14

5 years ago

1.0.0-alpha.13

5 years ago

1.0.0-alpha.12

5 years ago

1.0.0-alpha.11

5 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.5.0-next.6

5 years ago

0.5.0-next.5

5 years ago

0.5.0-next.4

5 years ago

0.5.0-next.3

5 years ago

0.5.0-next.2

5 years ago

0.5.0-next.1

5 years ago

0.5.0-next.0

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago