@codesoul-co/hypha-inference / manager
模块用法
用于使用该功能边界的公共契约与操作。Manager 模块公开 4 类、2 接口。
从包入口导入
ts
import {
InferenceCacheCapacityError,
InferenceManager,
InMemoryKvCacheProvider,
InMemoryPrefixCacheProvider,
} from '@codesoul-co/hypha-inference';
import type {
InMemoryKvCacheProviderOptions,
InMemoryPrefixCacheProviderOptions,
} from '@codesoul-co/hypha-inference';使用要点
- 2 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用
import type,运行时不应依赖它们。 - 4 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
公共导出
| Symbol | 种类 | 签名 | 说明 |
|---|---|---|---|
InferenceCacheCapacityError | 类 | new InferenceCacheCapacityError(message: string): InferenceCacheCapacityError | Inference Cache Capacity Error 类,共公开 9 个构造函数或成员;精确签名见本条目的声明与成员表。 |
InferenceManager | 类 | new InferenceManager(options?: InferenceManagerOptions): InferenceManager | Inference Manager 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。 |
InMemoryKvCacheProvider | 类 | new InMemoryKvCacheProvider(options?: InMemoryKvCacheProviderOptions): InMemoryKvCacheProvider | In Memory Kv Cache Provider 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。 |
InMemoryPrefixCacheProvider | 类 | new InMemoryPrefixCacheProvider(options?: InMemoryPrefixCacheProviderOptions): InMemoryPrefixCacheProvider | In Memory Prefix Cache Provider 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。 |
InMemoryKvCacheProviderOptions | 接口 | interface InMemoryKvCacheProviderOptions | In Memory Kv Cache Provider Options 接口,共包含 3 个公开字段或方法。 |
InMemoryPrefixCacheProviderOptions | 接口 | interface InMemoryPrefixCacheProviderOptions | In Memory Prefix Cache Provider Options 接口,共包含 3 个公开字段或方法。 |
InferenceCacheCapacityError
Inference Cache Capacity Error 类,共公开 9 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InferenceCacheCapacityError } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export declare class InferenceCacheCapacityError extends Error {
readonly code = "INFERENCE_CACHE_CAPACITY_EXCEEDED";
constructor(message: string);
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
cause | 属性 | cause?: unknown | 公开属性;类型、只读和可选状态以签名列为准。 |
code | 属性 | readonly code: "INFERENCE_CACHE_CAPACITY_EXCEEDED" | 公开属性;类型、只读和可选状态以签名列为准。 |
constructor | 构造函数 | (message: string): InferenceCacheCapacityError | 创建该类的实例。 |
message | 属性 | message: string | 公开属性;类型、只读和可选状态以签名列为准。 |
name | 属性 | name: string | 公开属性;类型、只读和可选状态以签名列为准。 |
stack | 属性 | stack?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
static captureStackTrace | 方法 | static captureStackTrace(targetObject: object, constructorOpt?: Function): void | Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called. js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}. The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace. The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance: js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); |
static prepareStackTrace | 方法 | static prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any | 公开方法;参数与返回类型以签名列为准。 |
static stackTraceLimit | 属性 | static stackTraceLimit: number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. |
InferenceManager
Inference Manager 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InferenceManager } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export declare class InferenceManager {
constructor(options?: InferenceManagerOptions);
register(provider: InferenceProvider): void;
get(providerId: string): InferenceProvider | null;
infer(providerId: string, request: InferenceRequest): Promise<InferenceResponse>;
stream(providerId: string, request: InferenceRequest): AsyncIterable<InferenceResponse>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
constructor | 构造函数 | (options?: InferenceManagerOptions): InferenceManager | 创建该类的实例。 |
get | 方法 | get(providerId: string): InferenceProvider | null | 公开方法;参数与返回类型以签名列为准。 |
infer | 方法 | infer(providerId: string, request: InferenceRequest): Promise<InferenceResponse> | 公开方法;参数与返回类型以签名列为准。 |
register | 方法 | register(provider: InferenceProvider): void | 公开方法;参数与返回类型以签名列为准。 |
stream | 方法 | stream(providerId: string, request: InferenceRequest): AsyncIterable<InferenceResponse> | 公开方法;参数与返回类型以签名列为准。 |
InMemoryKvCacheProvider
In Memory Kv Cache Provider 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InMemoryKvCacheProvider } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export declare class InMemoryKvCacheProvider implements KvCacheProvider {
constructor(options?: InMemoryKvCacheProviderOptions);
get(ref: KvCacheRef): Promise<unknown | null>;
put(ref: KvCacheRef, value: unknown): Promise<void>;
invalidate(ref: KvCacheRef): Promise<void>;
size(): number;
stats(): {
entries: number;
totalBytes: number;
};
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
constructor | 构造函数 | (options?: InMemoryKvCacheProviderOptions): InMemoryKvCacheProvider | 创建该类的实例。 |
get | 方法 | get(ref: KvCacheRef): Promise<unknown | null> | 公开方法;参数与返回类型以签名列为准。 |
invalidate | 方法 | invalidate(ref: KvCacheRef): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
put | 方法 | put(ref: KvCacheRef, value: unknown): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
size | 方法 | size(): number | 公开方法;参数与返回类型以签名列为准。 |
stats | 方法 | stats(): { entries: number; totalBytes: number; } | 公开方法;参数与返回类型以签名列为准。 |
InMemoryPrefixCacheProvider
In Memory Prefix Cache Provider 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InMemoryPrefixCacheProvider } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export declare class InMemoryPrefixCacheProvider implements PrefixCacheProvider {
constructor(options?: InMemoryPrefixCacheProviderOptions);
get(ref: PrefixCacheRef): Promise<string | null>;
put(ref: PrefixCacheRef, content: string): Promise<void>;
invalidate(ref: PrefixCacheRef): Promise<void>;
stats(): {
entries: number;
totalBytes: number;
};
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
constructor | 构造函数 | (options?: InMemoryPrefixCacheProviderOptions): InMemoryPrefixCacheProvider | 创建该类的实例。 |
get | 方法 | get(ref: PrefixCacheRef): Promise<string | null> | 公开方法;参数与返回类型以签名列为准。 |
invalidate | 方法 | invalidate(ref: PrefixCacheRef): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
put | 方法 | put(ref: PrefixCacheRef, content: string): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
stats | 方法 | stats(): { entries: number; totalBytes: number; } | 公开方法;参数与返回类型以签名列为准。 |
InMemoryKvCacheProviderOptions
In Memory Kv Cache Provider Options 接口,共包含 3 个公开字段或方法。
- 种类: 接口
- 导入:
import type { InMemoryKvCacheProviderOptions } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export interface InMemoryKvCacheProviderOptions {
maxEntries?: number;
maxEntryBytes?: number;
maxTotalBytes?: number;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
maxEntries | 属性 | maxEntries?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
maxEntryBytes | 属性 | maxEntryBytes?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
maxTotalBytes | 属性 | maxTotalBytes?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
InMemoryPrefixCacheProviderOptions
In Memory Prefix Cache Provider Options 接口,共包含 3 个公开字段或方法。
- 种类: 接口
- 导入:
import type { InMemoryPrefixCacheProviderOptions } from '@codesoul-co/hypha-inference'; - 源码模块:
manager
声明
text
export interface InMemoryPrefixCacheProviderOptions {
maxEntries?: number;
maxEntryBytes?: number;
maxTotalBytes?: number;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
maxEntries | 属性 | maxEntries?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
maxEntryBytes | 属性 | maxEntryBytes?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
maxTotalBytes | 属性 | maxTotalBytes?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
