diff --git a/api/assistant/create-assistant-message.mdx b/api/assistant/create-assistant-message.mdx index b2dd38479..35b80afe9 100644 --- a/api/assistant/create-assistant-message.mdx +++ b/api/assistant/create-assistant-message.mdx @@ -2,16 +2,65 @@ openapi: POST /assistant/{domain}/message --- +## Integration with `useChat` + +The recommended way to integrate the assistant API into your application is with the `useChat` hook from [Vercel's AI SDK](https://sdk.vercel.ai/docs). + + + + +```bash +npm i ai +``` + + + + +```tsx +import { useChat } from 'ai/react'; + +function MyComponent({ domain }) { + const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({ + api: `https://api-dsc.mintlify.com/v1/assistant/${domain}/message`, + headers: { + 'Authorization': `Bearer ${process.env.MINTLIFY_TOKEN}`, + }, + body: { + fp: 'anonymous', + messages: [ + { role: 'user', content: 'What is this documentation about?' } + ] + }, + streamProtocol: 'data', + sendExtraMessageFields: true, + }); + + return ( +
+ {messages.map((message) => ( +
+ {message.role === 'user' ? 'User: ' : 'Assistant: '} + {message.content} +
+ ))} +
+ + +
+
+ ); +} +``` + +
+
+ +See [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) in the AI SDK documentation for more details. + ## Rate limits The assistant API has the following limits: - 10,000 uses per key per month - 10,000 requests per Mintlify organization per hour -- 10,000 requests per IP per day - -## Suggested usage - -For best results, use the [useChat hook from ai-sdk](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) to send requests and handle responses. - -You can set `fp`, `threadId`, and `filter` in the `body` field of the options parameter passed to the hook. \ No newline at end of file +- 10,000 requests per IP per day \ No newline at end of file diff --git a/docs.json b/docs.json index 8f0c64cd4..6af410718 100644 --- a/docs.json +++ b/docs.json @@ -275,7 +275,7 @@ ] }, { - "tab": "API Reference", + "tab": "API reference", "groups": [ { "group": "API reference",