XRequest
When To Use
- Initiate a fetch request to LLMs that comply with OpenAI standards.
Examples
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'] |
- | - |