Skip to content

@codesoul-co/hypha-serving-cache / middleware/llm-cache-middleware

Using this module

Use the Llm cache middleware module for reading, writing, or coordinating cache state. It exports 1 class, 2 functions.

Import from the package entrypoint

ts
import {
  CachedLLMProvider,
  requestHashForModelRequest,
  servingCacheResponseMetadata,
} from '@codesoul-co/hypha-serving-cache';

Usage patterns

  • The module exposes 1 class as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 2 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
CachedLLMProviderclassnew CachedLLMProvider(inner: ModelProvider<ModelRequest, ModelResponse>, cache: ServingCacheManager, options?: CachedLLMProviderOptions): CachedLLMProviderCached LLM Provider class with 6 public constructor or member entries; its exact declarations are listed below.
requestHashForModelRequestfunctionrequestHashForModelRequest(request: ModelRequest): stringRequest Hash For Model Request function with 1 public call signature; parameters and return types are listed below.
servingCacheResponseMetadatafunctionservingCacheResponseMetadata(response: ModelResponse): Record<string, unknown> | undefinedServing Cache Response Metadata function with 1 public call signature; parameters and return types are listed below.

CachedLLMProvider

Cached LLM Provider class with 6 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class CachedLLMProvider implements ModelProvider<ModelRequest, ModelResponse> {
    readonly id: string;
    constructor(inner: ModelProvider<ModelRequest, ModelResponse>, cache: ServingCacheManager, options?: CachedLLMProviderOptions);
    capabilities(): ReturnType<ModelProvider['capabilities']>;
    generate(request: ModelRequest): Promise<ModelResponse>;
    stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
    countTokens(input: unknown): Promise<ModelUsage>;
}

Public members

MemberKindSignatureDescription
capabilitiesmethodcapabilities(): ReturnType<ModelProvider["capabilities"]>Public method; parameters and return type are shown in the signature.
constructorconstructor(inner: ModelProvider<ModelRequest, ModelResponse>, cache: ServingCacheManager, options?: CachedLLMProviderOptions): CachedLLMProviderCreates an instance of this class.
countTokensmethodcountTokens(input: unknown): Promise<ModelUsage>Public method; parameters and return type are shown in the signature.
generatemethodgenerate(request: ModelRequest): Promise<ModelResponse>Public method; parameters and return type are shown in the signature.
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
streammethodstream(request: ModelRequest): AsyncIterable<ModelStreamEvent>Public method; parameters and return type are shown in the signature.

requestHashForModelRequest

Request Hash For Model Request function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function requestHashForModelRequest(request: ModelRequest): string;

Call signature

text
requestHashForModelRequest(request: ModelRequest): string

Parameters

ParameterTypeRequiredDescription
requestModelRequest<unknown>YesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: string
  • Description: The return contract is defined by the type shown above.

servingCacheResponseMetadata

Serving Cache Response Metadata function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function servingCacheResponseMetadata(response: ModelResponse): Record<string, unknown> | undefined;

Call signature

text
servingCacheResponseMetadata(response: ModelResponse): Record<string, unknown> | undefined

Parameters

ParameterTypeRequiredDescription
responseModelResponse<string>YesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: Record<string, unknown>
  • Description: The return contract is defined by the type shown above.