Skip to content

ArtRequest 请求

何时使用

  • 向符合 OpenAI 标准的 LLM 发起请求。

代码演示

基础

该示例说明如何使用 ArtRequest 对符合 OpenAI 标准的 LLM 发起 fetch 请求 ,请拷贝代码且在 DEV 环境用实际的值替换 BASE_URL, PATH, MODEL, API_KEY 来使用

Request Log
Status:-
Update Times:0
查看源代码

自定义转换器

ArtRequest 配置自定义的 transformStream

Mock Custom Protocol - Log
          
        
查看源代码

API

ArtRequestOptions

属性描述类型默认值版本
baseURLAPI 请求的基础 URLstring--
model模型名称,例如 'gpt-3.5-turbo'string--
dangerouslyApiKey注意: 🔥 dangerouslyApiKey 存在安全风险,对此有详细的说明string--
fetch可选的自定义 fetch 函数,用于发起请求fetch--

ArtRequestFunction

ts
type ArtRequestFunction<Input = Record<PropertyKey, any>, Output = Record<string, string>> = (
  params: ArtRequestParams & Input,
  callbacks: ArtRequestCallbacks<Output>,
  transformStream?: ArtStreamOptions<Output>['transformStream']
) => Promise<void>

ArtRequestParams

属性描述类型默认值版本
model生成响应时使用的模型。string--
messages消息对象数组,每个对象包含角色和内容。Record<PropertyKey, any>[]--
stream指示是否使用流式响应。booleanfalse-

ArtRequestCallbacks

属性描述类型默认值版本
onSuccess成功时的回调。(messages: Output[]) => void--
onError错误处理的回调。(error: Error) => void--
onUpdate消息更新的回调。(message: Output) => void--
transformStream可选的转换函数,用于处理流数据ArtStreamOptions<Output>['transformStream']--