curl --request POST \
--url https://api-dsc.mintlify.com/v1/assistant/{domain}/message \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"fp": "<string>",
"messages": [
{
"id": "foobar",
"role": "user",
"content": "how do i get started",
"parts": [
{
"type": "text",
"text": "How do I get started"
}
]
}
],
"threadId": null,
"retrievalPageSize": 5,
"filter": null
}
'{}Generates a response message from the assistant for the specified domain.
curl --request POST \
--url https://api-dsc.mintlify.com/v1/assistant/{domain}/message \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"fp": "<string>",
"messages": [
{
"id": "foobar",
"role": "user",
"content": "how do i get started",
"parts": [
{
"type": "text",
"text": "How do I get started"
}
]
}
],
"threadId": null,
"retrievalPageSize": 5,
"filter": null
}
'{}useChat 集成useChat 钩子。
安装 AI SDK
npm i ai
使用该钩子
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 (
<div>
{messages.map((message) => (
<div key={message.id}>
{message.role === 'user' ? 'User: ' : 'Assistant: '}
{message.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button type="submit">Send</button>
</form>
</div>
);
}
The Authorization header expects a Bearer token. See the Assistant API Key documentation for details on how to get your API key.
The domain identifier from your domain.mintlify.app URL. Can be found at the end of your dashboard URL. For example, dashboard.mintlify.com/organization/domain has a domain identifier of domain.
Fingerprint identifier for tracking conversation sessions. Use 'anonymous' for anonymous users or provide a unique user identifier.
Array of messages in the conversation. On the frontend, you will likely want to use the handleSubmit function from the @ai-sdk package's useChat hook to append user messages and handle streaming responses, rather than manually defining the objects in this array as they have so many parameters.
显示 子属性
Unique identifier for the message
The role of the message sender
system, assistant, data, user The content of the message
Timestamp when the message was created
Optional array of annotations for the message
An optional identifier used to maintain conversation continuity across multiple messages. When provided, it allows the system to associate follow-up messages with the same conversation thread. The threadId is returned in the response as event.threadId when event.type === 'finish'.
Number of documentation search results to use for generating the response. Higher values provide more context but may increase response time. Recommended: 5.
Message generated successfully
Response object that streams formatted data stream parts with the specified status, headers, and content. This matches what is expected from the AI SDK as documented at ai-sdk.dev/docs/ai-sdk-ui/streaming-data. Instead of writing your own parser, it is recommended to use the useChat hook from ai-sdk as documented here.
此页面对您有帮助吗?