XRequest

When To Use

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

Examples

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.

expand code expand code

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

expand code expand code

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

expand code expand code

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

expand code expand code

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

expand code expand code

API#

XRequestOptions

Property Description Type Default Version
baseURL Base URL for the API request string - -
model Model name, e.g., 'gpt-3.5-turbo' string - -
dangerouslyApiKey 🔥 dangerouslyApiKey presents security risks. Detailed documentation on this can be found in Explanation string - -
fetch Optional custom fetch function for making requests fetch - -

XRequestFunction

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

XRequestParams

Property Description Type Default Version
model The model to be used for generating responses. string - -
messages An array of message objects, each containing a role and content. Record<PropertyKey, any>[] - -
stream Indicates whether to use streaming for the response. boolean false -

XRequestCallbacks

Property Description Type Default Version
onSuccess Callback for successful (chunks: Output[]) => void - -
onError Callback for error handling (error: Error) => void - -
onUpdate Callback for message updates (chunk: Output) => void - -
onStream Callback for stream controller (abortController: AbortController) => void - -
transformStream Optional transform function for processing stream data XStreamOptions<Output>['transformStream'] - -
XStream