@jaex/dstsx 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.cjs +265 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -10
- package/dist/index.d.ts +42 -10
- package/dist/index.js +264 -166
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -231,6 +231,8 @@ interface LMCallConfig {
|
|
|
231
231
|
stop?: string[];
|
|
232
232
|
/** Number of completions to generate (default 1). */
|
|
233
233
|
n?: number;
|
|
234
|
+
/** Opt-in to prompt caching API if the provider supports it (e.g. Anthropic `cache_control`). */
|
|
235
|
+
promptCaching?: boolean;
|
|
234
236
|
/**
|
|
235
237
|
* Optional cache key override. When provided the cache uses this key
|
|
236
238
|
* instead of hashing the prompt.
|
|
@@ -250,6 +252,8 @@ interface LMResponse {
|
|
|
250
252
|
promptTokens: number;
|
|
251
253
|
completionTokens: number;
|
|
252
254
|
totalTokens: number;
|
|
255
|
+
/** Cached input tokens read by the provider (e.g. OpenAI cached_tokens, Anthropic cache_read_input_tokens). */
|
|
256
|
+
cachedPromptTokens?: number;
|
|
253
257
|
} | null;
|
|
254
258
|
/** Raw provider response (opaque). */
|
|
255
259
|
raw: unknown;
|
|
@@ -296,6 +300,7 @@ declare abstract class LM {
|
|
|
296
300
|
promptTokens: number;
|
|
297
301
|
completionTokens: number;
|
|
298
302
|
totalTokens: number;
|
|
303
|
+
cachedPromptTokens: number;
|
|
299
304
|
}>;
|
|
300
305
|
/** Clear the in-memory response cache. */
|
|
301
306
|
clearCache(): void;
|
|
@@ -374,6 +379,8 @@ interface AnthropicOptions {
|
|
|
374
379
|
apiKey?: string;
|
|
375
380
|
model?: string;
|
|
376
381
|
maxRetries?: number;
|
|
382
|
+
/** Whether to enable prompt caching up-front. */
|
|
383
|
+
promptCaching?: boolean;
|
|
377
384
|
}
|
|
378
385
|
/**
|
|
379
386
|
* LM adapter for Anthropic Claude models.
|
|
@@ -500,11 +507,24 @@ declare class MockLM extends LM {
|
|
|
500
507
|
addResponse(prompt: string, response: string): void;
|
|
501
508
|
}
|
|
502
509
|
|
|
510
|
+
/**
|
|
511
|
+
* The return type of {@link Module.forward} — either a single prediction or
|
|
512
|
+
* an array of predictions for modules that produce multiple outputs (e.g.
|
|
513
|
+
* {@link Parallel}).
|
|
514
|
+
*/
|
|
515
|
+
type ModuleOutput = Prediction | Prediction[];
|
|
516
|
+
/**
|
|
517
|
+
* Extracts the first {@link Prediction} from a {@link ModuleOutput}.
|
|
518
|
+
*
|
|
519
|
+
* Useful when consuming an unknown module whose `forward()` may return either
|
|
520
|
+
* a single prediction or an array.
|
|
521
|
+
*/
|
|
522
|
+
declare function firstPrediction(result: ModuleOutput): Prediction;
|
|
503
523
|
/**
|
|
504
524
|
* Abstract base class for all DSTsx modules.
|
|
505
525
|
*
|
|
506
526
|
* A Module is a composable, serializable unit that encapsulates one or more
|
|
507
|
-
* language model calls. Subclasses implement {@link Module
|
|
527
|
+
* language model calls. Subclasses implement {@link Module["forward"]} to define
|
|
508
528
|
* their behaviour.
|
|
509
529
|
*
|
|
510
530
|
* Mirrors `dspy.Module` in Python.
|
|
@@ -528,8 +548,13 @@ declare abstract class Module {
|
|
|
528
548
|
*
|
|
529
549
|
* Subclasses define their own parameter signatures; the base type uses
|
|
530
550
|
* `unknown` so that TypeScript accepts any subclass override.
|
|
551
|
+
*
|
|
552
|
+
* The return value is {@link ModuleOutput} — a single {@link Prediction} for
|
|
553
|
+
* most modules, or a `Prediction[]` for multi-output modules such as
|
|
554
|
+
* {@link Parallel}. Use {@link firstPrediction} to safely extract the first
|
|
555
|
+
* result when consuming an unknown module.
|
|
531
556
|
*/
|
|
532
|
-
abstract forward(...args: unknown[]): Promise<
|
|
557
|
+
abstract forward(...args: unknown[]): Promise<ModuleOutput>;
|
|
533
558
|
/**
|
|
534
559
|
* Recursively discover all {@link Predict} sub-modules by walking the own
|
|
535
560
|
* enumerable properties of this instance.
|
|
@@ -628,7 +653,6 @@ declare class ChainOfThoughtWithHint extends ChainOfThought {
|
|
|
628
653
|
constructor(signature: string | Signature, options?: {
|
|
629
654
|
rationaleDescription?: string;
|
|
630
655
|
});
|
|
631
|
-
forward(inputs: Record<string, unknown>): Promise<Prediction>;
|
|
632
656
|
}
|
|
633
657
|
|
|
634
658
|
/**
|
|
@@ -787,20 +811,28 @@ declare class TypedChainOfThought<T = unknown> extends TypedPredictor<T> {
|
|
|
787
811
|
}
|
|
788
812
|
|
|
789
813
|
/**
|
|
790
|
-
* Runs multiple modules in parallel and returns all their results
|
|
814
|
+
* Runs multiple modules in parallel and returns all their results as a
|
|
815
|
+
* `Prediction[]`.
|
|
791
816
|
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
817
|
+
* Because `forward()` now returns `Prediction[]`, consumers can use the
|
|
818
|
+
* results directly without needing the separate `run()` method. `run()` is
|
|
819
|
+
* retained as a more explicit, named alternative.
|
|
794
820
|
*/
|
|
795
821
|
declare class Parallel extends Module {
|
|
796
822
|
#private;
|
|
797
823
|
constructor(modules: Module[], options?: {
|
|
798
824
|
timeoutMs?: number;
|
|
799
825
|
});
|
|
800
|
-
/**
|
|
826
|
+
/**
|
|
827
|
+
* Run all modules in parallel and return one {@link Prediction} per module.
|
|
828
|
+
* If a module's `forward()` returns multiple predictions, the first is used.
|
|
829
|
+
*/
|
|
801
830
|
run(...args: unknown[]): Promise<Prediction[]>;
|
|
802
|
-
/**
|
|
803
|
-
|
|
831
|
+
/**
|
|
832
|
+
* Execute all modules in parallel and return all predictions as an array
|
|
833
|
+
* (one entry per module).
|
|
834
|
+
*/
|
|
835
|
+
forward(...args: unknown[]): Promise<Prediction[]>;
|
|
804
836
|
}
|
|
805
837
|
|
|
806
838
|
interface RefineOptions {
|
|
@@ -1594,4 +1626,4 @@ declare class JsonFileTracker extends Tracker {
|
|
|
1594
1626
|
flush(): Promise<void>;
|
|
1595
1627
|
}
|
|
1596
1628
|
|
|
1597
|
-
export { Anthropic, type AnthropicOptions, Assert, AssertionError, AvatarOptimizer, type AvatarOptimizerOptions, BestOfN, BootstrapFewShot, type BootstrapFewShotOptions, BootstrapFewShotWithOptuna, type BootstrapFewShotWithOptunaOptions, BootstrapFewShotWithRandomSearch, type BootstrapFewShotWithRandomSearchOptions, BootstrapFinetune, type BootstrapFinetuneOptions, COPRO, type COPROOptions, ChainOfThought, ChainOfThoughtWithHint, ChromadbRM, type ChromadbRMOptions, Cohere, type CohereOptions, ColBERTv2, type ColBERTv2Options, ConsoleTracker, DSTsxMCPServer, DiskCache, Ensemble, EnsembleOptimizer, type EnsembleOptimizerOptions, type EvaluateOptions, type EvaluationResult, Example, type ExampleResult, FaissRM, type FaissRMOptions, type FieldMeta, type FinetuneFormat, GRPO, type GRPOOptions, GoogleAI, type GoogleAIOptions, HuggingFace, type HuggingFaceOptions, Image, type ImageMimeType, InputField, JsonFileTracker, KNNFewShot, type KNNFewShotOptions, LM, type LMCallConfig, type LMResponse, LMStudio, type LMStudioOptions, LRUCache, LabeledFewShot, type MCPAdapterOptions, type MCPTool, MCPToolAdapter, MIPRO, type MIPROOptions, type Message, type Metric, MockLM, MockRetriever, Module, MultiChainComparison, NativeReAct, Ollama, type OllamaOptions, OpenAI, type OpenAIOptions, Optimizer, OutputField, Parallel, PineconeRM, type PineconeRMOptions, Predict, Prediction, ProgramOfThought, QdrantRM, type QdrantRMOptions, ReAct, Refine, type RefineOptions, Retrieve, Retriever, Retry, SIMBA, type SIMBAOptions, Settings, type SettingsOptions, Signature, type SignatureMeta, type StreamChunk, Suggest, type TokenUsage, type Tool, type Trace, Tracker, type TrackerEvent, TypedChainOfThought, TypedPrediction, TypedPredictor, WeaviateRM, type WeaviateRMOptions, YouRM, type YouRMOptions, bleu, evaluate, exactMatch, f1, majority, passAtK, rouge, settings };
|
|
1629
|
+
export { Anthropic, type AnthropicOptions, Assert, AssertionError, AvatarOptimizer, type AvatarOptimizerOptions, BestOfN, BootstrapFewShot, type BootstrapFewShotOptions, BootstrapFewShotWithOptuna, type BootstrapFewShotWithOptunaOptions, BootstrapFewShotWithRandomSearch, type BootstrapFewShotWithRandomSearchOptions, BootstrapFinetune, type BootstrapFinetuneOptions, COPRO, type COPROOptions, ChainOfThought, ChainOfThoughtWithHint, ChromadbRM, type ChromadbRMOptions, Cohere, type CohereOptions, ColBERTv2, type ColBERTv2Options, ConsoleTracker, DSTsxMCPServer, DiskCache, Ensemble, EnsembleOptimizer, type EnsembleOptimizerOptions, type EvaluateOptions, type EvaluationResult, Example, type ExampleResult, FaissRM, type FaissRMOptions, type FieldMeta, type FinetuneFormat, GRPO, type GRPOOptions, GoogleAI, type GoogleAIOptions, HuggingFace, type HuggingFaceOptions, Image, type ImageMimeType, InputField, JsonFileTracker, KNNFewShot, type KNNFewShotOptions, LM, type LMCallConfig, type LMResponse, LMStudio, type LMStudioOptions, LRUCache, LabeledFewShot, type MCPAdapterOptions, type MCPTool, MCPToolAdapter, MIPRO, type MIPROOptions, type Message, type Metric, MockLM, MockRetriever, Module, type ModuleOutput, MultiChainComparison, NativeReAct, Ollama, type OllamaOptions, OpenAI, type OpenAIOptions, Optimizer, OutputField, Parallel, PineconeRM, type PineconeRMOptions, Predict, Prediction, ProgramOfThought, QdrantRM, type QdrantRMOptions, ReAct, Refine, type RefineOptions, Retrieve, Retriever, Retry, SIMBA, type SIMBAOptions, Settings, type SettingsOptions, Signature, type SignatureMeta, type StreamChunk, Suggest, type TokenUsage, type Tool, type Trace, Tracker, type TrackerEvent, TypedChainOfThought, TypedPrediction, TypedPredictor, WeaviateRM, type WeaviateRMOptions, YouRM, type YouRMOptions, bleu, evaluate, exactMatch, f1, firstPrediction, majority, passAtK, rouge, settings };
|
package/dist/index.d.ts
CHANGED
|
@@ -231,6 +231,8 @@ interface LMCallConfig {
|
|
|
231
231
|
stop?: string[];
|
|
232
232
|
/** Number of completions to generate (default 1). */
|
|
233
233
|
n?: number;
|
|
234
|
+
/** Opt-in to prompt caching API if the provider supports it (e.g. Anthropic `cache_control`). */
|
|
235
|
+
promptCaching?: boolean;
|
|
234
236
|
/**
|
|
235
237
|
* Optional cache key override. When provided the cache uses this key
|
|
236
238
|
* instead of hashing the prompt.
|
|
@@ -250,6 +252,8 @@ interface LMResponse {
|
|
|
250
252
|
promptTokens: number;
|
|
251
253
|
completionTokens: number;
|
|
252
254
|
totalTokens: number;
|
|
255
|
+
/** Cached input tokens read by the provider (e.g. OpenAI cached_tokens, Anthropic cache_read_input_tokens). */
|
|
256
|
+
cachedPromptTokens?: number;
|
|
253
257
|
} | null;
|
|
254
258
|
/** Raw provider response (opaque). */
|
|
255
259
|
raw: unknown;
|
|
@@ -296,6 +300,7 @@ declare abstract class LM {
|
|
|
296
300
|
promptTokens: number;
|
|
297
301
|
completionTokens: number;
|
|
298
302
|
totalTokens: number;
|
|
303
|
+
cachedPromptTokens: number;
|
|
299
304
|
}>;
|
|
300
305
|
/** Clear the in-memory response cache. */
|
|
301
306
|
clearCache(): void;
|
|
@@ -374,6 +379,8 @@ interface AnthropicOptions {
|
|
|
374
379
|
apiKey?: string;
|
|
375
380
|
model?: string;
|
|
376
381
|
maxRetries?: number;
|
|
382
|
+
/** Whether to enable prompt caching up-front. */
|
|
383
|
+
promptCaching?: boolean;
|
|
377
384
|
}
|
|
378
385
|
/**
|
|
379
386
|
* LM adapter for Anthropic Claude models.
|
|
@@ -500,11 +507,24 @@ declare class MockLM extends LM {
|
|
|
500
507
|
addResponse(prompt: string, response: string): void;
|
|
501
508
|
}
|
|
502
509
|
|
|
510
|
+
/**
|
|
511
|
+
* The return type of {@link Module.forward} — either a single prediction or
|
|
512
|
+
* an array of predictions for modules that produce multiple outputs (e.g.
|
|
513
|
+
* {@link Parallel}).
|
|
514
|
+
*/
|
|
515
|
+
type ModuleOutput = Prediction | Prediction[];
|
|
516
|
+
/**
|
|
517
|
+
* Extracts the first {@link Prediction} from a {@link ModuleOutput}.
|
|
518
|
+
*
|
|
519
|
+
* Useful when consuming an unknown module whose `forward()` may return either
|
|
520
|
+
* a single prediction or an array.
|
|
521
|
+
*/
|
|
522
|
+
declare function firstPrediction(result: ModuleOutput): Prediction;
|
|
503
523
|
/**
|
|
504
524
|
* Abstract base class for all DSTsx modules.
|
|
505
525
|
*
|
|
506
526
|
* A Module is a composable, serializable unit that encapsulates one or more
|
|
507
|
-
* language model calls. Subclasses implement {@link Module
|
|
527
|
+
* language model calls. Subclasses implement {@link Module["forward"]} to define
|
|
508
528
|
* their behaviour.
|
|
509
529
|
*
|
|
510
530
|
* Mirrors `dspy.Module` in Python.
|
|
@@ -528,8 +548,13 @@ declare abstract class Module {
|
|
|
528
548
|
*
|
|
529
549
|
* Subclasses define their own parameter signatures; the base type uses
|
|
530
550
|
* `unknown` so that TypeScript accepts any subclass override.
|
|
551
|
+
*
|
|
552
|
+
* The return value is {@link ModuleOutput} — a single {@link Prediction} for
|
|
553
|
+
* most modules, or a `Prediction[]` for multi-output modules such as
|
|
554
|
+
* {@link Parallel}. Use {@link firstPrediction} to safely extract the first
|
|
555
|
+
* result when consuming an unknown module.
|
|
531
556
|
*/
|
|
532
|
-
abstract forward(...args: unknown[]): Promise<
|
|
557
|
+
abstract forward(...args: unknown[]): Promise<ModuleOutput>;
|
|
533
558
|
/**
|
|
534
559
|
* Recursively discover all {@link Predict} sub-modules by walking the own
|
|
535
560
|
* enumerable properties of this instance.
|
|
@@ -628,7 +653,6 @@ declare class ChainOfThoughtWithHint extends ChainOfThought {
|
|
|
628
653
|
constructor(signature: string | Signature, options?: {
|
|
629
654
|
rationaleDescription?: string;
|
|
630
655
|
});
|
|
631
|
-
forward(inputs: Record<string, unknown>): Promise<Prediction>;
|
|
632
656
|
}
|
|
633
657
|
|
|
634
658
|
/**
|
|
@@ -787,20 +811,28 @@ declare class TypedChainOfThought<T = unknown> extends TypedPredictor<T> {
|
|
|
787
811
|
}
|
|
788
812
|
|
|
789
813
|
/**
|
|
790
|
-
* Runs multiple modules in parallel and returns all their results
|
|
814
|
+
* Runs multiple modules in parallel and returns all their results as a
|
|
815
|
+
* `Prediction[]`.
|
|
791
816
|
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
817
|
+
* Because `forward()` now returns `Prediction[]`, consumers can use the
|
|
818
|
+
* results directly without needing the separate `run()` method. `run()` is
|
|
819
|
+
* retained as a more explicit, named alternative.
|
|
794
820
|
*/
|
|
795
821
|
declare class Parallel extends Module {
|
|
796
822
|
#private;
|
|
797
823
|
constructor(modules: Module[], options?: {
|
|
798
824
|
timeoutMs?: number;
|
|
799
825
|
});
|
|
800
|
-
/**
|
|
826
|
+
/**
|
|
827
|
+
* Run all modules in parallel and return one {@link Prediction} per module.
|
|
828
|
+
* If a module's `forward()` returns multiple predictions, the first is used.
|
|
829
|
+
*/
|
|
801
830
|
run(...args: unknown[]): Promise<Prediction[]>;
|
|
802
|
-
/**
|
|
803
|
-
|
|
831
|
+
/**
|
|
832
|
+
* Execute all modules in parallel and return all predictions as an array
|
|
833
|
+
* (one entry per module).
|
|
834
|
+
*/
|
|
835
|
+
forward(...args: unknown[]): Promise<Prediction[]>;
|
|
804
836
|
}
|
|
805
837
|
|
|
806
838
|
interface RefineOptions {
|
|
@@ -1594,4 +1626,4 @@ declare class JsonFileTracker extends Tracker {
|
|
|
1594
1626
|
flush(): Promise<void>;
|
|
1595
1627
|
}
|
|
1596
1628
|
|
|
1597
|
-
export { Anthropic, type AnthropicOptions, Assert, AssertionError, AvatarOptimizer, type AvatarOptimizerOptions, BestOfN, BootstrapFewShot, type BootstrapFewShotOptions, BootstrapFewShotWithOptuna, type BootstrapFewShotWithOptunaOptions, BootstrapFewShotWithRandomSearch, type BootstrapFewShotWithRandomSearchOptions, BootstrapFinetune, type BootstrapFinetuneOptions, COPRO, type COPROOptions, ChainOfThought, ChainOfThoughtWithHint, ChromadbRM, type ChromadbRMOptions, Cohere, type CohereOptions, ColBERTv2, type ColBERTv2Options, ConsoleTracker, DSTsxMCPServer, DiskCache, Ensemble, EnsembleOptimizer, type EnsembleOptimizerOptions, type EvaluateOptions, type EvaluationResult, Example, type ExampleResult, FaissRM, type FaissRMOptions, type FieldMeta, type FinetuneFormat, GRPO, type GRPOOptions, GoogleAI, type GoogleAIOptions, HuggingFace, type HuggingFaceOptions, Image, type ImageMimeType, InputField, JsonFileTracker, KNNFewShot, type KNNFewShotOptions, LM, type LMCallConfig, type LMResponse, LMStudio, type LMStudioOptions, LRUCache, LabeledFewShot, type MCPAdapterOptions, type MCPTool, MCPToolAdapter, MIPRO, type MIPROOptions, type Message, type Metric, MockLM, MockRetriever, Module, MultiChainComparison, NativeReAct, Ollama, type OllamaOptions, OpenAI, type OpenAIOptions, Optimizer, OutputField, Parallel, PineconeRM, type PineconeRMOptions, Predict, Prediction, ProgramOfThought, QdrantRM, type QdrantRMOptions, ReAct, Refine, type RefineOptions, Retrieve, Retriever, Retry, SIMBA, type SIMBAOptions, Settings, type SettingsOptions, Signature, type SignatureMeta, type StreamChunk, Suggest, type TokenUsage, type Tool, type Trace, Tracker, type TrackerEvent, TypedChainOfThought, TypedPrediction, TypedPredictor, WeaviateRM, type WeaviateRMOptions, YouRM, type YouRMOptions, bleu, evaluate, exactMatch, f1, majority, passAtK, rouge, settings };
|
|
1629
|
+
export { Anthropic, type AnthropicOptions, Assert, AssertionError, AvatarOptimizer, type AvatarOptimizerOptions, BestOfN, BootstrapFewShot, type BootstrapFewShotOptions, BootstrapFewShotWithOptuna, type BootstrapFewShotWithOptunaOptions, BootstrapFewShotWithRandomSearch, type BootstrapFewShotWithRandomSearchOptions, BootstrapFinetune, type BootstrapFinetuneOptions, COPRO, type COPROOptions, ChainOfThought, ChainOfThoughtWithHint, ChromadbRM, type ChromadbRMOptions, Cohere, type CohereOptions, ColBERTv2, type ColBERTv2Options, ConsoleTracker, DSTsxMCPServer, DiskCache, Ensemble, EnsembleOptimizer, type EnsembleOptimizerOptions, type EvaluateOptions, type EvaluationResult, Example, type ExampleResult, FaissRM, type FaissRMOptions, type FieldMeta, type FinetuneFormat, GRPO, type GRPOOptions, GoogleAI, type GoogleAIOptions, HuggingFace, type HuggingFaceOptions, Image, type ImageMimeType, InputField, JsonFileTracker, KNNFewShot, type KNNFewShotOptions, LM, type LMCallConfig, type LMResponse, LMStudio, type LMStudioOptions, LRUCache, LabeledFewShot, type MCPAdapterOptions, type MCPTool, MCPToolAdapter, MIPRO, type MIPROOptions, type Message, type Metric, MockLM, MockRetriever, Module, type ModuleOutput, MultiChainComparison, NativeReAct, Ollama, type OllamaOptions, OpenAI, type OpenAIOptions, Optimizer, OutputField, Parallel, PineconeRM, type PineconeRMOptions, Predict, Prediction, ProgramOfThought, QdrantRM, type QdrantRMOptions, ReAct, Refine, type RefineOptions, Retrieve, Retriever, Retry, SIMBA, type SIMBAOptions, Settings, type SettingsOptions, Signature, type SignatureMeta, type StreamChunk, Suggest, type TokenUsage, type Tool, type Trace, Tracker, type TrackerEvent, TypedChainOfThought, TypedPrediction, TypedPredictor, WeaviateRM, type WeaviateRMOptions, YouRM, type YouRMOptions, bleu, evaluate, exactMatch, f1, firstPrediction, majority, passAtK, rouge, settings };
|