Ask me

logoAnt Design X

DesignDevelopmentComponentsPlayground
  • Overview
  • Common
    • Bubble
    • Conversations
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Confirm
    • ThoughtChain
  • Tools
    • useXAgent
    • useXChat
    • XStream
    • XRequest
    • XProvider

XRequest

Import
import{ XRequest }from"@ant-design/x";
Sourcecomponents/x-request
Docs
Edit this pageChangelog

Resources

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
ahooks-React Hooks Library
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

  • Initiate a fetch request to LLMs that comply with OpenAI standards.

Examples

API

XRequestOptions

PropertyDescriptionTypeDefaultVersion
baseURLBase URL for the API requeststring--
modelModel name, e.g., 'gpt-3.5-turbo'string--
dangerouslyApiKey🔥 dangerouslyApiKey presents security risks. Detailed documentation on this can be found in Explanationstring--
fetchOptional custom fetch function for making requestsfetch--

XRequestFunction

type XRequestFunction<Input = Record<PropertyKey, any>, Output = Record<string, string>> = (
params: XRequestParams & Input,
callbacks: XRequestCallbacks<Output>,
transformStream?: XStreamOptions<Output>['transformStream'],
) => Promise<void>;

XRequestParams

PropertyDescriptionTypeDefaultVersion
modelThe model to be used for generating responses.string--
messagesAn array of message objects, each containing a role and content.Record<PropertyKey, any>[]--
streamIndicates whether to use streaming for the response.booleanfalse-

XRequestCallbacks

PropertyDescriptionTypeDefaultVersion
onSuccessCallback for successful.(messages: Output[]) => void--
onErrorCallback for error handling.(error: Error) => void--
onUpdateCallback for message updates.(message: Output) => void--
transformStreamOptional transform function for processing stream dataXStreamOptions<Output>['transformStream']--
Basic

This example illustrates how to use XRequest to initiate a fetch request to LLMs that comply with OpenAI standards. Please copy the code and replace BASE_URL, PATH, MODEL, and API_KEY with actual values in the DEV environment to use it.

codepen icon
External Link Icon
expand codeexpand code
Custom Transformer

Configure a custom transformStream for XRequest. The following example demonstrates how to handle application/x-ndjson data format.

codepen icon
External Link Icon
expand codeexpand code
Request Log
Status-
Update Times0
Mock Custom Protocol - Log