Skip to content

Commit

Permalink
update basics
Browse files Browse the repository at this point in the history
  • Loading branch information
Raunak Chowdhuri committed Aug 29, 2023
1 parent 4a5dbf3 commit d60cc4e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
56 changes: 55 additions & 1 deletion docs/pages/basics.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Code, {Python, Typescript} from "components/Code";
import { Callout } from 'nextra/components'

## Generate XML Prompt

Expand All @@ -10,11 +11,64 @@ A basic utility of the library is converting from a dictionary format to a XML f
from xmlai import generate_xml_prompt

generate_xml_prompt({
"cheese": "gouda",
"title": "Hello",
"content": "Blah"
})
```
</Python>
<Typescript>
```ts
import {generateXmlPrompt} from "xmlai"

generate_xml_prompt({
cheese: "gouda",
title: "Hello",
content: "Blah"
})
```
</Typescript>
</Code>

Both of these will generate the following output:
```xml
<cheese>gouda</cheese><title>Hello</title><content>Blah</content>
```

## Streaming Results

<Callout type="warning">
There is not currently support for arrays of objects or multiple child keys at the same level that have the same key string. PRs are welcome for this!
</Callout>

A core feature of the library is being able to stream out structured JSON from a partial LLM completion. We use the `parseXmlPrefix` function to handle this.


<Code>
<Python>
```python
from xmlai import parse_xml_prefix

parse_xml_prefix("<foo><cheese>gouda</cheese><title>Hel")
```
</Python>
<Typescript>
```ts
import {parseXmlPrefix} from "xmlai"

parse_xml_prefix("<foo><cheese>gouda</cheese><title>Hel")
```
</Typescript>
</Code>
</Code>

This results in the following parsed JSON:
```json
{
"foo": {
"cheese": "gouda",
"title": "Hel"
}
}
```

This form of streaming is useful when populating values in different parts of a user interface dynamically.
3 changes: 1 addition & 2 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import Code, {Python, Typescript} from "components/Code";

XML AI is the fastest and most ergonomic way to get structured input and output out of your large language model.

Just write your prompt in JSON and we'll autoconvert it to XML that the model can work with. The best part? You can [stream the response](/streaming) back as a JSON object in real time. No more sacrificing streaming for function calling or schema following capabilities. Built and optimized for Anthropic's Claude models, but also including OpenAI support.

Just write your prompt in JSON and we'll autoconvert it to XML that the model can work with. The best part? You can [stream the response](/basics#streaming-results) back as a JSON object in real time. No more sacrificing streaming for function calling or schema following capabilities. Built and optimized for Anthropic's Claude models, but also including OpenAI support.

The library is designed to be as lightweight as possible, and with nearly identical APIs whether you are operating in Python or Javascript/Typescript.

Expand Down

0 comments on commit d60cc4e

Please sign in to comment.