@memberjunction/ai-prompts 2.103.0 → 2.105.0
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 +51 -1
- package/dist/AIPromptRunner.d.ts +9 -1
- package/dist/AIPromptRunner.d.ts.map +1 -1
- package/dist/AIPromptRunner.js +284 -104
- package/dist/AIPromptRunner.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -768,7 +768,57 @@ GROUP BY OriginalModelID, ModelID
|
|
|
768
768
|
ORDER BY FailoverCount DESC;
|
|
769
769
|
```
|
|
770
770
|
|
|
771
|
-
|
|
771
|
+
#### Configuration-Aware Failover
|
|
772
|
+
|
|
773
|
+
The failover system respects `AIConfiguration` boundaries to ensure environment-specific models stay isolated:
|
|
774
|
+
|
|
775
|
+
**How It Works:**
|
|
776
|
+
- When you specify a `configurationId`, the system builds a candidate list with two priority tiers:
|
|
777
|
+
1. **Configuration-specific models** (priority 5000+): Models assigned to your configuration
|
|
778
|
+
2. **NULL configuration models** (priority 2000+): Universal fallback models available to all configurations
|
|
779
|
+
|
|
780
|
+
**Example Setup:**
|
|
781
|
+
```sql
|
|
782
|
+
-- Production Configuration: Only approved production models
|
|
783
|
+
INSERT INTO AIPromptModel (PromptID, ModelID, ConfigurationID, Priority)
|
|
784
|
+
VALUES
|
|
785
|
+
(@PromptID, @Claude35SonnetID, @ProductionConfigID, 100),
|
|
786
|
+
(@PromptID, @GPT4ID, @ProductionConfigID, 90);
|
|
787
|
+
|
|
788
|
+
-- Development Configuration: Include experimental models
|
|
789
|
+
INSERT INTO AIPromptModel (PromptID, ModelID, ConfigurationID, Priority)
|
|
790
|
+
VALUES
|
|
791
|
+
(@PromptID, @LlamaExperimentalID, @DevelopmentConfigID, 100);
|
|
792
|
+
|
|
793
|
+
-- NULL Configuration: Universal fallbacks for all environments
|
|
794
|
+
INSERT INTO AIPromptModel (PromptID, ModelID, ConfigurationID, Priority)
|
|
795
|
+
VALUES
|
|
796
|
+
(@PromptID, @Claude3HaikuID, NULL, 100),
|
|
797
|
+
(@PromptID, @GPT35TurboID, NULL, 90);
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
**Failover Behavior:**
|
|
801
|
+
```typescript
|
|
802
|
+
// Execute with Production configuration
|
|
803
|
+
const result = await runner.ExecutePrompt({
|
|
804
|
+
prompt: myPrompt,
|
|
805
|
+
configurationId: productionConfigID,
|
|
806
|
+
data: { query: 'Analyze this' }
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// Failover order:
|
|
810
|
+
// 1. Try Claude 3.5 Sonnet (Production config, priority 5100)
|
|
811
|
+
// 2. Try GPT-4 (Production config, priority 5090)
|
|
812
|
+
// 3. Try Claude 3 Haiku (NULL config fallback, priority 2100)
|
|
813
|
+
// 4. Try GPT-3.5 Turbo (NULL config fallback, priority 2090)
|
|
814
|
+
// ✅ Never crosses to Development config models
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
**Key Benefits:**
|
|
818
|
+
- **Environment Isolation**: Production models never failover to development/experimental models
|
|
819
|
+
- **Controlled Fallback**: Explicit hierarchy from config-specific to universal fallbacks
|
|
820
|
+
- **Performance**: Candidate list built once and cached, no rebuilding during failover
|
|
821
|
+
- **Consistency**: Same candidate list used for initial selection and all failover attempts
|
|
772
822
|
|
|
773
823
|
### Intelligent Caching
|
|
774
824
|
|
package/dist/AIPromptRunner.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface ModelVendorCandidate {
|
|
|
9
9
|
vendorName?: string;
|
|
10
10
|
driverClass: string;
|
|
11
11
|
apiName?: string;
|
|
12
|
+
supportsEffortLevel?: boolean;
|
|
12
13
|
isPreferredVendor: boolean;
|
|
13
14
|
priority: number;
|
|
14
15
|
source: 'explicit' | 'prompt-model' | 'model-type' | 'power-rank';
|
|
@@ -44,6 +45,7 @@ export declare class AIPromptRunner {
|
|
|
44
45
|
prompt?: AIPromptEntityExtended;
|
|
45
46
|
model?: AIModelEntityExtended;
|
|
46
47
|
severity?: 'warning' | 'error' | 'critical';
|
|
48
|
+
maxErrorLength?: number;
|
|
47
49
|
}): void;
|
|
48
50
|
private isInferenceProvider;
|
|
49
51
|
ExecutePrompt<T = unknown>(params: AIPromptParams): Promise<AIPromptRunResult<T>>;
|
|
@@ -54,10 +56,12 @@ export declare class AIPromptRunner {
|
|
|
54
56
|
private renderPromptWithChildTemplates;
|
|
55
57
|
private selectModel;
|
|
56
58
|
private buildModelVendorCandidates;
|
|
59
|
+
private createSelectionInfo;
|
|
60
|
+
private buildCandidatesFromSelectionInfo;
|
|
57
61
|
private selectModelWithAPIKeyTracked;
|
|
58
62
|
private createPromptRun;
|
|
59
63
|
private renderPromptTemplate;
|
|
60
|
-
protected executeModelWithFailover(model: AIModelEntityExtended, renderedPrompt: string, prompt: AIPromptEntityExtended, params: AIPromptParams, vendorId: string | null, conversationMessages?: ChatMessage[], templateMessageRole?: TemplateMessageRole, cancellationToken?: AbortSignal, allCandidates?: ModelVendorCandidate[], promptRun?: AIPromptRunEntityExtended, vendorDriverClass?: string, vendorApiName?: string): Promise<ChatResult>;
|
|
64
|
+
protected executeModelWithFailover(model: AIModelEntityExtended, renderedPrompt: string, prompt: AIPromptEntityExtended, params: AIPromptParams, vendorId: string | null, conversationMessages?: ChatMessage[], templateMessageRole?: TemplateMessageRole, cancellationToken?: AbortSignal, allCandidates?: ModelVendorCandidate[], promptRun?: AIPromptRunEntityExtended, vendorDriverClass?: string, vendorApiName?: string, vendorSupportsEffortLevel?: boolean): Promise<ChatResult>;
|
|
61
65
|
protected buildFailoverCandidates(prompt: AIPromptEntityExtended): Promise<ModelVendorCandidate[]>;
|
|
62
66
|
protected createCandidatesFromModels(models: AIModelEntityExtended[]): ModelVendorCandidate[];
|
|
63
67
|
protected updatePromptRunWithFailoverSuccess(promptRun: AIPromptRunEntityExtended, failoverAttempts: FailoverAttempt[], currentModel: AIModelEntityExtended, currentVendorId: string | null): void;
|
|
@@ -66,7 +70,11 @@ export declare class AIPromptRunner {
|
|
|
66
70
|
private executeModel;
|
|
67
71
|
private buildMessageArray;
|
|
68
72
|
private executeWithValidationRetries;
|
|
73
|
+
private calculateRetryDelay;
|
|
69
74
|
private applyRetryDelay;
|
|
75
|
+
private filterAuthenticationFailedVendor;
|
|
76
|
+
private handleRateLimitRetry;
|
|
77
|
+
private transitionToNextCandidate;
|
|
70
78
|
private getValidationDecisionDescription;
|
|
71
79
|
private generateSchemaFromExample;
|
|
72
80
|
private isLikelyPlaceholder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIPromptRunner.d.ts","sourceRoot":"","sources":["../src/AIPromptRunner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,UAAU,EAAmB,WAAW,EAA8B,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAqB,iBAAiB,EAAwB,MAAM,8BAA8B,CAAC;AAG1G,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"AIPromptRunner.d.ts","sourceRoot":"","sources":["../src/AIPromptRunner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,UAAU,EAAmB,WAAW,EAA8B,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAqB,iBAAiB,EAAwB,MAAM,8BAA8B,CAAC;AAG1G,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,yBAAyB,EAA2G,MAAM,+BAA+B,CAAC;AAQlO,OAAO,EACH,mBAAmB,EAEnB,cAAc,EACjB,MAAM,8BAA8B,CAAC;AAkEtC,UAAU,oBAAoB;IAC5B,KAAK,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;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