XRequest

Fetch request for LLMs
Import

When To Use#

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

Examples#

Request Log
Status -
Update Times 0

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.

      Loading...
    
Request Log
Status -
Update Times 0

Customize the menu RequestParams, can send request to intelligent agents, etc.

      Loading...
    
Mock Custom Protocol Log
        
      

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

      Loading...
    

baseURL: https://api.example.com/chat

model: gpt-3.5-turbo

dangerouslyApiKey: Bearer sk-your-dangerouslyApiKey

Request Log
Status -
Update Times 0

Control change XRequestOptions,dynamically modify configuration items such as baseURL, model, and API key.

      Loading...
    
Request Log request null
Status -
Update Times 0

Access to cloud service platform, send messages, process data, abort stream.

      Loading...
    

API#

XRequestOptions#

PropertyDescriptionTypeDefault
baseURLBase URL for the API requeststring-
modelModel name, e.g., 'gpt-3.5-turbo'string-
dangerouslyApiKeyNote: dangerouslyApiKey presents security risksstring-
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#

PropertyDescriptionTypeDefault
modelThe model to be used for generating responsesstring-
messagesAn array of message objects, each containing a role and contentRecord<PropertyKey, any>[]-
streamIndicates whether to use streaming for the responsebooleanfalse

XRequestCallbacks#

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