Class: XiangxinClient
示例
import { XiangxinClient, noul } from '@xiangxinai/sdk'
const client = new XiangxinClient() // 读取 XIANGXIN_API_KEY
const { answers } = await client.systemOne({
state: '我被重复扣费了两次,请尽快处理!',
questions: { billing: noul('这是否与扣费相关?') },
})
console.log(answers.billing.noul)构造函数
构造函数
new XiangxinClient(config?): XiangxinClient;参数
config?
XiangxinClientConfig = {}
返回
XiangxinClient
抛出
缺少或非法的 API 密钥、非法配置,或在浏览器中未显式允许。 / Missing or invalid API key, invalid options, or browser use without opt-in.
属性
baseURL
readonly baseURL: string;API 根地址(已去掉末尾斜杠)。 / API root without trailing slashes.
defaultHeaders
readonly defaultHeaders: Readonly<Record<string, string>>;附加到每个请求的请求头。 / Extra headers sent with each request.
defaultModel
readonly defaultModel: string;请求省略 model 时使用的模型。 / Model used when a request omits model.
fetch
readonly fetch: Fetch;使用的 fetch 实现。 / The fetch implementation.
logger
readonly logger: Logger;按 logLevel 过滤后的日志器。 / The logger, filtered to logLevel.
logLevel
readonly logLevel: LogLevel;日志级别。 / Log level.
models
readonly models: Models;模型资源。 / The models resource.
retry
readonly retry: RetryPolicy;合并后的客户端重试策略。 / Client retry policy with overrides applied.
timeout
readonly timeout: number;每次尝试的超时(毫秒)。 / Timeout per attempt in ms.
方法
systemOne()
systemOne<Q>(request, options?): APIPromise<SystemOneResult<Q>>;对 state 提出一组带名字的问题,一次前向返回全部答案。答案类型由问题推断: Choice 的 choice 是选项名的字面量联合,Score 的 legend 以档位为键。
Ask named questions about state and get every answer in one forward pass. Answer types are inferred from the questions.
类型参数
Q
Q extends Questions
参数
request
state、questions 与可选的 model;其余字段原样转发。 / State, questions and optional model.
options?
RequestOptions = {}
单次调用的超时、重试、请求头与取消信号。 / Per-call options.
返回
APIPromise<SystemOneResult<Q>>
可 await 的 APIPromise;.withResponse() 额外返回 HTTP 响应。
以下情况会以错误拒绝 / Rejects with:
XiangxinError:请求参数不合法(问题为空、Score 少于两档等)。APIError子类:重试后服务端仍返回非 2xx。APIConnectionError/APITimeoutError:重试后仍无法连接或超时。APIUserAbortError:调用方取消。
toString()
toString(): string;不包含 API 密钥的可读表示。 / A readable representation that never includes the API key.
返回
string

