ai-jsx-test
v0.5.17
Published
[](https://docs.ai-jsx.com) [](https://discord.gg/MsKAeKF8kU) [.
Here is a simple example using AI.JSX to generate an AI response to a prompt:
import * as AI from 'ai-jsx';
import { ChatCompletion, UserMessage } from 'ai-jsx/core/completion';
const app = (
<ChatCompletion>
<UserMessage>Write a Shakespearean sonnet about AI models.</UserMessage>
</ChatCompletion>
);
const renderContext = AI.createRenderContext();
const response = await renderContext.render(app);
console.log(response);
Here's a more complex example that uses the built-in <Inline>
component to progressively generate multiple fields in a JSON object:
function CharacterGenerator() {
const inlineCompletion = (prompt: Node) => (
<Completion stop={['"']} temperature={1.0}>
{prompt}
</Completion>
);
return (
<Inline>
Generate a character profile for a fantasy role-playing game in JSON format.{'\n'}
{'{'}
{'\n '}"name": "{inlineCompletion}",
{'\n '}"class": "{inlineCompletion}",
{'\n '}"race": "{inlineCompletion}",
{'\n '}"alignment": "{inlineCompletion}",
{'\n '}"weapons": "{inlineCompletion}",
{'\n '}"spells": "{inlineCompletion}",
{'\n}'}
</Inline>
);
}
For a full set of examples, see the examples package.
Features
- Prompt engineering through modular, reusable components
- The ability to easily switch between model providers and LLM configurations (e.g., temperature)
- Built in support for Tools (ReAct pattern), Document Question and Answering, Chain of Thought, and more
- Ability to directly interweave LLM calls with standard UI components, including the ability for the LLM to render the UI from a set of provided components
- Built-in streaming support
- First-class support for NextJS and Create React App (more coming soon)
- Full support for LangChainJS
Contributing
We welcome contributions! See Contributing for how to get started.