@loonylabs/llm-middleware 2.2.0 → 2.3.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 +88 -5
- package/dist/examples/custom-config/custom-config.messages.d.ts +16 -0
- package/dist/examples/custom-config/custom-config.messages.d.ts.map +1 -0
- package/dist/examples/custom-config/custom-config.messages.js +32 -0
- package/dist/examples/custom-config/custom-config.messages.js.map +1 -0
- package/dist/examples/custom-config/custom-config.usecase.d.ts +81 -0
- package/dist/examples/custom-config/custom-config.usecase.d.ts.map +1 -0
- package/dist/examples/custom-config/custom-config.usecase.js +137 -0
- package/dist/examples/custom-config/custom-config.usecase.js.map +1 -0
- package/dist/examples/simple-chat/anthropic-chat.usecase.d.ts +25 -0
- package/dist/examples/simple-chat/anthropic-chat.usecase.d.ts.map +1 -0
- package/dist/examples/simple-chat/anthropic-chat.usecase.js +31 -0
- package/dist/examples/simple-chat/anthropic-chat.usecase.js.map +1 -0
- package/dist/examples/simple-chat/index.d.ts +2 -0
- package/dist/examples/simple-chat/index.d.ts.map +1 -1
- package/dist/examples/simple-chat/index.js +6 -0
- package/dist/examples/simple-chat/index.js.map +1 -1
- package/dist/middleware/usecases/base/base-ai.usecase.d.ts +16 -0
- package/dist/middleware/usecases/base/base-ai.usecase.d.ts.map +1 -1
- package/dist/middleware/usecases/base/base-ai.usecase.js +19 -1
- package/dist/middleware/usecases/base/base-ai.usecase.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ npm install github:loonylabs-dev/llm-middleware#v1.3.0
|
|
|
77
77
|
### Basic Usage
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
import { BaseAIUseCase, BaseAIRequest, BaseAIResult } from '@loonylabs/llm-middleware';
|
|
80
|
+
import { BaseAIUseCase, BaseAIRequest, BaseAIResult, LLMProvider } from '@loonylabs/llm-middleware';
|
|
81
81
|
|
|
82
82
|
// Define your request/response interfaces
|
|
83
83
|
interface MyRequest extends BaseAIRequest<string> {
|
|
@@ -88,19 +88,19 @@ interface MyResult extends BaseAIResult {
|
|
|
88
88
|
response: string;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
// Create your use case
|
|
91
|
+
// Create your use case (uses Ollama by default)
|
|
92
92
|
class MyChatUseCase extends BaseAIUseCase<string, MyRequest, MyResult> {
|
|
93
93
|
protected readonly systemMessage = "You are a helpful assistant.";
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
// Required: return user message template function
|
|
96
96
|
protected getUserTemplate(): (formattedPrompt: string) => string {
|
|
97
97
|
return (message) => message;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
protected formatUserMessage(prompt: any): string {
|
|
101
101
|
return typeof prompt === 'string' ? prompt : prompt.message;
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
protected createResult(content: string, usedPrompt: string, thinking?: string): MyResult {
|
|
105
105
|
return {
|
|
106
106
|
generatedContent: content,
|
|
@@ -111,6 +111,13 @@ class MyChatUseCase extends BaseAIUseCase<string, MyRequest, MyResult> {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
// Switch to different provider (optional)
|
|
116
|
+
class MyAnthropicChatUseCase extends MyChatUseCase {
|
|
117
|
+
protected getProvider(): LLMProvider {
|
|
118
|
+
return LLMProvider.ANTHROPIC; // Use Claude instead of Ollama
|
|
119
|
+
}
|
|
120
|
+
}
|
|
114
121
|
```
|
|
115
122
|
|
|
116
123
|
<details>
|
|
@@ -564,6 +571,82 @@ console.log(config.baseUrl); // Value from MODEL1_URL or default localhost
|
|
|
564
571
|
|
|
565
572
|
</details>
|
|
566
573
|
|
|
574
|
+
<details>
|
|
575
|
+
<summary><strong>🔧 Customizing Model Configuration (New in v2.3.0)</strong></summary>
|
|
576
|
+
|
|
577
|
+
Override the model configuration provider to use your own custom model configurations:
|
|
578
|
+
|
|
579
|
+
**Use Cases:**
|
|
580
|
+
- Multi-environment deployments (dev, staging, production)
|
|
581
|
+
- Dynamic model selection based on runtime conditions
|
|
582
|
+
- Loading model configs from external sources (database, API)
|
|
583
|
+
- Testing with different model configurations
|
|
584
|
+
|
|
585
|
+
**New Pattern (Recommended):**
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
import { BaseAIUseCase, ModelConfigKey, ValidatedLLMModelConfig } from '@loonylabs/llm-middleware';
|
|
589
|
+
|
|
590
|
+
// Define your custom model configurations
|
|
591
|
+
const MY_CUSTOM_MODELS: Record<string, ValidatedLLMModelConfig> = {
|
|
592
|
+
'PRODUCTION_MODEL': {
|
|
593
|
+
name: 'llama3.2:latest',
|
|
594
|
+
baseUrl: 'http://production-server.com:11434',
|
|
595
|
+
temperature: 0.7
|
|
596
|
+
},
|
|
597
|
+
'DEVELOPMENT_MODEL': {
|
|
598
|
+
name: 'llama3.2:latest',
|
|
599
|
+
baseUrl: 'http://localhost:11434',
|
|
600
|
+
temperature: 0.9
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
class MyCustomUseCase extends BaseAIUseCase<string, MyRequest, MyResult> {
|
|
605
|
+
// Override this method to provide custom model configurations
|
|
606
|
+
protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig {
|
|
607
|
+
const config = MY_CUSTOM_MODELS[key];
|
|
608
|
+
if (!config?.name) {
|
|
609
|
+
throw new Error(`Model ${key} not found`);
|
|
610
|
+
}
|
|
611
|
+
return config;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// ... rest of your use case implementation
|
|
615
|
+
}
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
**Environment-Aware Example:**
|
|
619
|
+
|
|
620
|
+
```typescript
|
|
621
|
+
class EnvironmentAwareUseCase extends BaseAIUseCase<string, MyRequest, MyResult> {
|
|
622
|
+
protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig {
|
|
623
|
+
const env = process.env.NODE_ENV || 'development';
|
|
624
|
+
|
|
625
|
+
// Automatically select model based on environment
|
|
626
|
+
const modelKey = env === 'production' ? 'PRODUCTION_MODEL' :
|
|
627
|
+
env === 'staging' ? 'STAGING_MODEL' :
|
|
628
|
+
'DEVELOPMENT_MODEL';
|
|
629
|
+
|
|
630
|
+
return MY_CUSTOM_MODELS[modelKey];
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
**Old Pattern (Still Supported):**
|
|
636
|
+
|
|
637
|
+
```typescript
|
|
638
|
+
// Legacy approach - still works but not recommended
|
|
639
|
+
class LegacyUseCase extends BaseAIUseCase<string, MyRequest, MyResult> {
|
|
640
|
+
protected get modelConfig(): ValidatedLLMModelConfig {
|
|
641
|
+
return myCustomGetModelConfig(this.modelConfigKey);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
**See the [Custom Config Example](src/examples/custom-config/README.md) for a complete working implementation.**
|
|
647
|
+
|
|
648
|
+
</details>
|
|
649
|
+
|
|
567
650
|
<details>
|
|
568
651
|
<summary><strong>🎛️ Parameter Configuration</strong></summary>
|
|
569
652
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Config Example - Message Templates
|
|
3
|
+
*
|
|
4
|
+
* Simple message templates for demonstrating custom model configuration provider
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* System message for the custom config example
|
|
8
|
+
* Defines the AI's role and behavior
|
|
9
|
+
*/
|
|
10
|
+
export declare const CUSTOM_CONFIG_SYSTEM_MESSAGE = "You are a helpful AI assistant that responds to user queries in a clear and concise manner.\n\nYour responses should be:\n- Direct and to the point\n- Accurate and factual\n- Well-formatted in JSON when appropriate\n\nReturn your response in the following JSON format:\n{\n \"response\": \"Your response text here\"\n}";
|
|
11
|
+
/**
|
|
12
|
+
* User message template
|
|
13
|
+
* Takes the formatted prompt and returns the user message
|
|
14
|
+
*/
|
|
15
|
+
export declare const CUSTOM_CONFIG_USER_TEMPLATE: (formattedPrompt: string) => string;
|
|
16
|
+
//# sourceMappingURL=custom-config.messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-config.messages.d.ts","sourceRoot":"","sources":["../../../src/examples/custom-config/custom-config.messages.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,eAAO,MAAM,4BAA4B,oUAUvC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,iBAAiB,MAAM,KAAG,MAErE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom Config Example - Message Templates
|
|
4
|
+
*
|
|
5
|
+
* Simple message templates for demonstrating custom model configuration provider
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CUSTOM_CONFIG_USER_TEMPLATE = exports.CUSTOM_CONFIG_SYSTEM_MESSAGE = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* System message for the custom config example
|
|
11
|
+
* Defines the AI's role and behavior
|
|
12
|
+
*/
|
|
13
|
+
exports.CUSTOM_CONFIG_SYSTEM_MESSAGE = `You are a helpful AI assistant that responds to user queries in a clear and concise manner.
|
|
14
|
+
|
|
15
|
+
Your responses should be:
|
|
16
|
+
- Direct and to the point
|
|
17
|
+
- Accurate and factual
|
|
18
|
+
- Well-formatted in JSON when appropriate
|
|
19
|
+
|
|
20
|
+
Return your response in the following JSON format:
|
|
21
|
+
{
|
|
22
|
+
"response": "Your response text here"
|
|
23
|
+
}`;
|
|
24
|
+
/**
|
|
25
|
+
* User message template
|
|
26
|
+
* Takes the formatted prompt and returns the user message
|
|
27
|
+
*/
|
|
28
|
+
const CUSTOM_CONFIG_USER_TEMPLATE = (formattedPrompt) => {
|
|
29
|
+
return formattedPrompt;
|
|
30
|
+
};
|
|
31
|
+
exports.CUSTOM_CONFIG_USER_TEMPLATE = CUSTOM_CONFIG_USER_TEMPLATE;
|
|
32
|
+
//# sourceMappingURL=custom-config.messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-config.messages.js","sourceRoot":"","sources":["../../../src/examples/custom-config/custom-config.messages.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;GAGG;AACU,QAAA,4BAA4B,GAAG;;;;;;;;;;EAU1C,CAAC;AAEH;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAAC,eAAuB,EAAU,EAAE;IAC7E,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAFW,QAAA,2BAA2B,+BAEtC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { BaseAIUseCase } from '../../middleware/usecases/base/base-ai.usecase';
|
|
2
|
+
import { BaseAIRequest, BaseAIResult } from '../../middleware/shared/types/base-request.types';
|
|
3
|
+
import { ModelConfigKey, ValidatedLLMModelConfig } from '../../middleware/shared/config/models.config';
|
|
4
|
+
/**
|
|
5
|
+
* Simple request interface for the custom config example
|
|
6
|
+
*/
|
|
7
|
+
export interface CustomConfigRequest extends BaseAIRequest<string> {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Simple response structure
|
|
11
|
+
*/
|
|
12
|
+
export interface CustomConfigResponse {
|
|
13
|
+
response: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result interface for the custom config example
|
|
17
|
+
*/
|
|
18
|
+
export interface CustomConfigResult extends BaseAIResult {
|
|
19
|
+
parsedResponse: CustomConfigResponse;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Custom Config Use Case Example
|
|
23
|
+
*
|
|
24
|
+
* This example demonstrates how to override the model configuration provider
|
|
25
|
+
* to use your own custom model configurations instead of the library's default MODELS config.
|
|
26
|
+
*
|
|
27
|
+
* Key Pattern: Override `getModelConfigProvider()` method
|
|
28
|
+
*
|
|
29
|
+
* Use Cases:
|
|
30
|
+
* - Multi-environment deployments (dev, staging, production)
|
|
31
|
+
* - Dynamic model selection based on runtime conditions
|
|
32
|
+
* - Using model configs from external sources (database, API, etc.)
|
|
33
|
+
* - Testing with different model configurations
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const useCase = new CustomConfigUseCase();
|
|
38
|
+
* const result = await useCase.execute({
|
|
39
|
+
* prompt: 'What is the capital of France?'
|
|
40
|
+
* });
|
|
41
|
+
* console.log(result.parsedResponse.response);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class CustomConfigUseCase extends BaseAIUseCase<string, CustomConfigRequest, CustomConfigResult> {
|
|
45
|
+
protected readonly systemMessage = "You are a helpful AI assistant that responds to user queries in a clear and concise manner.\n\nYour responses should be:\n- Direct and to the point\n- Accurate and factual\n- Well-formatted in JSON when appropriate\n\nReturn your response in the following JSON format:\n{\n \"response\": \"Your response text here\"\n}";
|
|
46
|
+
/**
|
|
47
|
+
* Default model to use - references our custom config
|
|
48
|
+
*/
|
|
49
|
+
protected static readonly DEFAULT_MODEL_CONFIG_KEY = "DEVELOPMENT_MODEL";
|
|
50
|
+
/**
|
|
51
|
+
* Override to use custom model configuration source
|
|
52
|
+
*
|
|
53
|
+
* This is the key method that allows you to provide your own model configurations.
|
|
54
|
+
* Instead of calling the library's getModelConfig(), we use our own MY_CUSTOM_MODELS.
|
|
55
|
+
*
|
|
56
|
+
* @param key - The model configuration key
|
|
57
|
+
* @returns Validated model configuration from our custom source
|
|
58
|
+
*/
|
|
59
|
+
protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig;
|
|
60
|
+
/**
|
|
61
|
+
* Get user template for formatting the prompt
|
|
62
|
+
*/
|
|
63
|
+
protected getUserTemplate(): (formattedPrompt: string) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Create the result object from the AI response
|
|
66
|
+
*/
|
|
67
|
+
protected createResult(content: string, usedPrompt: string, thinking?: string): CustomConfigResult;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Environment-Aware Use Case Example
|
|
71
|
+
*
|
|
72
|
+
* This example shows how to dynamically select model configurations
|
|
73
|
+
* based on the runtime environment (NODE_ENV).
|
|
74
|
+
*/
|
|
75
|
+
export declare class EnvironmentAwareUseCase extends CustomConfigUseCase {
|
|
76
|
+
/**
|
|
77
|
+
* Override to select model based on environment
|
|
78
|
+
*/
|
|
79
|
+
protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=custom-config.usecase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-config.usecase.d.ts","sourceRoot":"","sources":["../../../src/examples/custom-config/custom-config.usecase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AA4BvG;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa,CAAC,MAAM,CAAC;CAAG;AAErE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,cAAc,EAAE,oBAAoB,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAoB,SAAQ,aAAa,CAAC,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,CAAC;IACrG,SAAS,CAAC,QAAQ,CAAC,aAAa,qUAAgC;IAEhE;;OAEG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,uBAAuB;IAEzE;;;;;;;;OAQG;IACH,SAAS,CAAC,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,uBAAuB;IAY9E;;OAEG;IACH,SAAS,CAAC,eAAe,IAAI,CAAC,eAAe,EAAE,MAAM,KAAK,MAAM;IAIhE;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,kBAAkB;CAoBnG;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,mBAAmB;IAC9D;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,uBAAuB;CAyB/E"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentAwareUseCase = exports.CustomConfigUseCase = void 0;
|
|
4
|
+
const base_ai_usecase_1 = require("../../middleware/usecases/base/base-ai.usecase");
|
|
5
|
+
const custom_config_messages_1 = require("./custom-config.messages");
|
|
6
|
+
/**
|
|
7
|
+
* Custom model configurations (not from the library's MODELS config)
|
|
8
|
+
* This demonstrates how to use your own model configuration source
|
|
9
|
+
*/
|
|
10
|
+
const MY_CUSTOM_MODELS = {
|
|
11
|
+
'PRODUCTION_MODEL': {
|
|
12
|
+
name: 'llama3.2:latest',
|
|
13
|
+
baseUrl: 'http://production-server.com:11434',
|
|
14
|
+
temperature: 0.7
|
|
15
|
+
},
|
|
16
|
+
'DEVELOPMENT_MODEL': {
|
|
17
|
+
name: 'llama3.2:latest',
|
|
18
|
+
baseUrl: 'http://localhost:11434',
|
|
19
|
+
temperature: 0.9
|
|
20
|
+
},
|
|
21
|
+
'STAGING_MODEL': {
|
|
22
|
+
name: 'llama3.2:latest',
|
|
23
|
+
baseUrl: 'http://staging-server.com:11434',
|
|
24
|
+
temperature: 0.8
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Custom Config Use Case Example
|
|
29
|
+
*
|
|
30
|
+
* This example demonstrates how to override the model configuration provider
|
|
31
|
+
* to use your own custom model configurations instead of the library's default MODELS config.
|
|
32
|
+
*
|
|
33
|
+
* Key Pattern: Override `getModelConfigProvider()` method
|
|
34
|
+
*
|
|
35
|
+
* Use Cases:
|
|
36
|
+
* - Multi-environment deployments (dev, staging, production)
|
|
37
|
+
* - Dynamic model selection based on runtime conditions
|
|
38
|
+
* - Using model configs from external sources (database, API, etc.)
|
|
39
|
+
* - Testing with different model configurations
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const useCase = new CustomConfigUseCase();
|
|
44
|
+
* const result = await useCase.execute({
|
|
45
|
+
* prompt: 'What is the capital of France?'
|
|
46
|
+
* });
|
|
47
|
+
* console.log(result.parsedResponse.response);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
class CustomConfigUseCase extends base_ai_usecase_1.BaseAIUseCase {
|
|
51
|
+
constructor() {
|
|
52
|
+
super(...arguments);
|
|
53
|
+
this.systemMessage = custom_config_messages_1.CUSTOM_CONFIG_SYSTEM_MESSAGE;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Override to use custom model configuration source
|
|
57
|
+
*
|
|
58
|
+
* This is the key method that allows you to provide your own model configurations.
|
|
59
|
+
* Instead of calling the library's getModelConfig(), we use our own MY_CUSTOM_MODELS.
|
|
60
|
+
*
|
|
61
|
+
* @param key - The model configuration key
|
|
62
|
+
* @returns Validated model configuration from our custom source
|
|
63
|
+
*/
|
|
64
|
+
getModelConfigProvider(key) {
|
|
65
|
+
const config = MY_CUSTOM_MODELS[key];
|
|
66
|
+
if (!config?.name) {
|
|
67
|
+
throw new Error(`Custom model ${key} not found. Available models: ${Object.keys(MY_CUSTOM_MODELS).join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
return config;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get user template for formatting the prompt
|
|
73
|
+
*/
|
|
74
|
+
getUserTemplate() {
|
|
75
|
+
return custom_config_messages_1.CUSTOM_CONFIG_USER_TEMPLATE;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create the result object from the AI response
|
|
79
|
+
*/
|
|
80
|
+
createResult(content, usedPrompt, thinking) {
|
|
81
|
+
let parsedResponse;
|
|
82
|
+
try {
|
|
83
|
+
parsedResponse = JSON.parse(content);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// Fallback if JSON parsing fails
|
|
87
|
+
parsedResponse = {
|
|
88
|
+
response: content
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
generatedContent: content,
|
|
93
|
+
model: this.modelConfig.name,
|
|
94
|
+
usedPrompt,
|
|
95
|
+
thinking,
|
|
96
|
+
parsedResponse
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CustomConfigUseCase = CustomConfigUseCase;
|
|
101
|
+
/**
|
|
102
|
+
* Default model to use - references our custom config
|
|
103
|
+
*/
|
|
104
|
+
CustomConfigUseCase.DEFAULT_MODEL_CONFIG_KEY = 'DEVELOPMENT_MODEL';
|
|
105
|
+
/**
|
|
106
|
+
* Environment-Aware Use Case Example
|
|
107
|
+
*
|
|
108
|
+
* This example shows how to dynamically select model configurations
|
|
109
|
+
* based on the runtime environment (NODE_ENV).
|
|
110
|
+
*/
|
|
111
|
+
class EnvironmentAwareUseCase extends CustomConfigUseCase {
|
|
112
|
+
/**
|
|
113
|
+
* Override to select model based on environment
|
|
114
|
+
*/
|
|
115
|
+
getModelConfigProvider(key) {
|
|
116
|
+
const env = process.env.NODE_ENV || 'development';
|
|
117
|
+
let selectedKey;
|
|
118
|
+
switch (env) {
|
|
119
|
+
case 'production':
|
|
120
|
+
selectedKey = 'PRODUCTION_MODEL';
|
|
121
|
+
break;
|
|
122
|
+
case 'staging':
|
|
123
|
+
selectedKey = 'STAGING_MODEL';
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
selectedKey = 'DEVELOPMENT_MODEL';
|
|
127
|
+
}
|
|
128
|
+
const config = MY_CUSTOM_MODELS[selectedKey];
|
|
129
|
+
if (!config?.name) {
|
|
130
|
+
throw new Error(`Model for environment ${env} (${selectedKey}) not found`);
|
|
131
|
+
}
|
|
132
|
+
console.log(`Using ${selectedKey} for environment: ${env}`);
|
|
133
|
+
return config;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.EnvironmentAwareUseCase = EnvironmentAwareUseCase;
|
|
137
|
+
//# sourceMappingURL=custom-config.usecase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-config.usecase.js","sourceRoot":"","sources":["../../../src/examples/custom-config/custom-config.usecase.ts"],"names":[],"mappings":";;;AAAA,oFAA+E;AAG/E,qEAGkC;AAElC;;;GAGG;AACH,MAAM,gBAAgB,GAA4C;IAChE,kBAAkB,EAAE;QAClB,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,oCAAoC;QAC7C,WAAW,EAAE,GAAG;KACjB;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,wBAAwB;QACjC,WAAW,EAAE,GAAG;KACjB;IACD,eAAe,EAAE;QACf,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,iCAAiC;QAC1C,WAAW,EAAE,GAAG;KACjB;CACF,CAAC;AAqBF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,mBAAoB,SAAQ,+BAA8D;IAAvG;;QACqB,kBAAa,GAAG,qDAA4B,CAAC;IA0DlE,CAAC;IAnDC;;;;;;;;OAQG;IACO,sBAAsB,CAAC,GAAmB;QAClD,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAErC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK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AAC;YAClB,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,KAAK,WAAW,aAAa,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,SAAS,WAAW,qBAAqB,GAAG,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA7BD,0DA6BC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LLMProvider } from '../../middleware/services/llm';
|
|
2
|
+
import { SimpleChatUseCase } from './chat.usecase';
|
|
3
|
+
/**
|
|
4
|
+
* Example: Chat use case using Anthropic Claude instead of Ollama
|
|
5
|
+
*
|
|
6
|
+
* This demonstrates how to override the default provider (Ollama)
|
|
7
|
+
* to use a different LLM provider like Anthropic Claude.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const anthropicChat = new AnthropicChatUseCase();
|
|
12
|
+
* const result = await anthropicChat.execute({
|
|
13
|
+
* prompt: "Hello, Claude!",
|
|
14
|
+
* authToken: process.env.ANTHROPIC_API_KEY
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class AnthropicChatUseCase extends SimpleChatUseCase {
|
|
19
|
+
/**
|
|
20
|
+
* Override to use Anthropic Claude provider
|
|
21
|
+
* @returns LLMProvider.ANTHROPIC
|
|
22
|
+
*/
|
|
23
|
+
protected getProvider(): LLMProvider;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=anthropic-chat.usecase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-chat.usecase.d.ts","sourceRoot":"","sources":["../../../src/examples/simple-chat/anthropic-chat.usecase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,SAAS,CAAC,WAAW,IAAI,WAAW;CAGrC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnthropicChatUseCase = void 0;
|
|
4
|
+
const llm_1 = require("../../middleware/services/llm");
|
|
5
|
+
const chat_usecase_1 = require("./chat.usecase");
|
|
6
|
+
/**
|
|
7
|
+
* Example: Chat use case using Anthropic Claude instead of Ollama
|
|
8
|
+
*
|
|
9
|
+
* This demonstrates how to override the default provider (Ollama)
|
|
10
|
+
* to use a different LLM provider like Anthropic Claude.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const anthropicChat = new AnthropicChatUseCase();
|
|
15
|
+
* const result = await anthropicChat.execute({
|
|
16
|
+
* prompt: "Hello, Claude!",
|
|
17
|
+
* authToken: process.env.ANTHROPIC_API_KEY
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class AnthropicChatUseCase extends chat_usecase_1.SimpleChatUseCase {
|
|
22
|
+
/**
|
|
23
|
+
* Override to use Anthropic Claude provider
|
|
24
|
+
* @returns LLMProvider.ANTHROPIC
|
|
25
|
+
*/
|
|
26
|
+
getProvider() {
|
|
27
|
+
return llm_1.LLMProvider.ANTHROPIC;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AnthropicChatUseCase = AnthropicChatUseCase;
|
|
31
|
+
//# sourceMappingURL=anthropic-chat.usecase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-chat.usecase.js","sourceRoot":"","sources":["../../../src/examples/simple-chat/anthropic-chat.usecase.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAC5D,iDAAmD;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAa,oBAAqB,SAAQ,gCAAiB;IACzD;;;OAGG;IACO,WAAW;QACnB,OAAO,iBAAW,CAAC,SAAS,CAAC;IAC/B,CAAC;CACF;AARD,oDAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/examples/simple-chat/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/examples/simple-chat/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAKhE,QAAA,MAAM,GAAG,6CAAY,CAAC;AAkDtB,eAAe,GAAG,CAAC"}
|
|
@@ -3,12 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicChatUseCase = exports.SimpleChatUseCase = void 0;
|
|
6
7
|
const express_1 = __importDefault(require("express"));
|
|
7
8
|
const cors_1 = __importDefault(require("cors"));
|
|
8
9
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
10
|
const chat_controller_1 = require("./chat.controller");
|
|
10
11
|
const app_config_1 = require("../../middleware/shared/config/app.config");
|
|
11
12
|
const logging_utils_1 = require("../../middleware/shared/utils/logging.utils");
|
|
13
|
+
// Export use cases for library users
|
|
14
|
+
var chat_usecase_1 = require("./chat.usecase");
|
|
15
|
+
Object.defineProperty(exports, "SimpleChatUseCase", { enumerable: true, get: function () { return chat_usecase_1.SimpleChatUseCase; } });
|
|
16
|
+
var anthropic_chat_usecase_1 = require("./anthropic-chat.usecase");
|
|
17
|
+
Object.defineProperty(exports, "AnthropicChatUseCase", { enumerable: true, get: function () { return anthropic_chat_usecase_1.AnthropicChatUseCase; } });
|
|
12
18
|
// Load environment variables
|
|
13
19
|
dotenv_1.default.config();
|
|
14
20
|
const app = (0, express_1.default)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/examples/simple-chat/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/examples/simple-chat/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,gDAAwB;AACxB,oDAA4B;AAC5B,uDAAmD;AACnD,0EAAsE;AACtE,+EAAqE;AAIrE,qCAAqC;AACrC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAE7B,6BAA6B;AAC7B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,MAAM,cAAc,GAAG,IAAI,gCAAc,EAAE,CAAC;AAE5C,aAAa;AACb,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAExB,gCAAgC;AAChC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACtD,GAAG,CAAC,UAAU,GAAG;QACf,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,SAAS;QAChD,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,IAAI,SAAS;QACvD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;IACF,IAAI,EAAE,CAAC;AACT,CAAC,CAAC,CAAC;AAEH,SAAS;AACT,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9B,GAAG,CAAC,IAAI,CAAC;QACP,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,OAAO,EAAE,wBAAwB;KAClC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAQ,EAAE,GAAa,EAAE,EAAE;IAChD,cAAc,CAAC,IAAI,CAAC,GAAsB,EAAE,GAAG,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC;AAEH,eAAe;AACf,MAAM,IAAI,GAAG,sBAAS,CAAC,MAAM,CAAC,IAAI,CAAC;AAEnC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,sBAAM,CAAC,IAAI,CAAC,8CAA8C,IAAI,EAAE,EAAE;QAChE,OAAO,EAAE,mBAAmB;QAC5B,QAAQ,EAAE;YACR,IAAI;YACJ,WAAW,EAAE,sBAAS,CAAC,MAAM,CAAC,WAAW;SAC1C;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,oDAAoD,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,SAAS,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,CAAC,2CAA2C,IAAI,WAAW,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IACrE,OAAO,CAAC,GAAG,CAAC,sBAAsB,sBAAS,CAAC,MAAM,CAAC,WAAW,KAAK,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC;AAEH,kBAAe,GAAG,CAAC"}
|
|
@@ -25,6 +25,22 @@ export declare abstract class BaseAIUseCase<TPrompt = string, TRequest extends B
|
|
|
25
25
|
* If not overridden, uses the default model config key
|
|
26
26
|
*/
|
|
27
27
|
protected get modelConfigKey(): ModelConfigKey;
|
|
28
|
+
/**
|
|
29
|
+
* Get the model configuration for a given key
|
|
30
|
+
* Override this method in subclasses to provide custom model configurations
|
|
31
|
+
*
|
|
32
|
+
* @param key - The model configuration key
|
|
33
|
+
* @returns Validated model configuration
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // In your custom use case base class:
|
|
38
|
+
* protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig {
|
|
39
|
+
* return myCustomGetModelConfig(key);
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig;
|
|
28
44
|
/**
|
|
29
45
|
* Get the model configuration for this use case
|
|
30
46
|
* Returns validated config with guaranteed model name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-ai.usecase.d.ts","sourceRoot":"","sources":["../../../../src/middleware/usecases/base/base-ai.usecase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAkB,cAAc,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAE5G,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAEpF,OAAO,EAAgC,uBAAuB,EAAE,MAAM,wEAAwE,CAAC;AAG/I;;;;;;GAMG;AACH,8BAAsB,aAAa,CACjC,OAAO,GAAG,MAAM,EAChB,QAAQ,SAAS,aAAa,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAChE,OAAO,SAAS,YAAY,GAAG,YAAY;IAE3C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAElD;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,cAAc,CAAY;IAE9E;;;OAGG;IACH,SAAS,KAAK,cAAc,IAAI,c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AAG,YAAY;IAE3C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAElD;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,EAAE,cAAc,CAAY;IAE9E;;;OAGG;IACH,SAAS,KAAK,cAAc,IAAI,cAAc,CAE7C;IAED;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,uBAAuB;IAI9E;;;OAGG;IACH,SAAS,KAAK,WAAW,IAAI,uBAAuB,CAEnD;IAED;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM;IAShD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,IAAI,CAAC,eAAe,EAAE,MAAM,KAAK,MAAM;IAEzE;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,IAAI,uBAAuB;IAI1D;;;;OAIG;IACH,SAAS,CAAC,WAAW,IAAI,WAAW;IAIpC;;;;OAIG;IACU,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IA+GzD;;;OAGG;cACa,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAIrG;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO;CACjG"}
|
|
@@ -21,12 +21,30 @@ class BaseAIUseCase {
|
|
|
21
21
|
get modelConfigKey() {
|
|
22
22
|
return this.constructor.DEFAULT_MODEL_CONFIG_KEY;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the model configuration for a given key
|
|
26
|
+
* Override this method in subclasses to provide custom model configurations
|
|
27
|
+
*
|
|
28
|
+
* @param key - The model configuration key
|
|
29
|
+
* @returns Validated model configuration
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // In your custom use case base class:
|
|
34
|
+
* protected getModelConfigProvider(key: ModelConfigKey): ValidatedLLMModelConfig {
|
|
35
|
+
* return myCustomGetModelConfig(key);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
getModelConfigProvider(key) {
|
|
40
|
+
return (0, models_config_1.getModelConfig)(key);
|
|
41
|
+
}
|
|
24
42
|
/**
|
|
25
43
|
* Get the model configuration for this use case
|
|
26
44
|
* Returns validated config with guaranteed model name
|
|
27
45
|
*/
|
|
28
46
|
get modelConfig() {
|
|
29
|
-
return
|
|
47
|
+
return this.getModelConfigProvider(this.modelConfigKey);
|
|
30
48
|
}
|
|
31
49
|
/**
|
|
32
50
|
* Creates a user message from the prompt
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-ai.usecase.js","sourceRoot":"","sources":["../../../../src/middleware/usecases/base/base-ai.usecase.ts"],"names":[],"mappings":";;;AAAA,4CAA6D;AAC7D,qEAA4G;AAC5G,0FAAqF;AAGrF,4HAA+I;AAC/I,oFAAqF;AAErF;;;;;;GAMG;AACH,MAAsB,aAAa;IAiBjC;;;OAGG;IACH,IAAc,cAAc;QAC1B,OAAQ,IAAI,CAAC,WAAoC,CAAC,wBAAwB,CAAC;IAC7E,CAAC;IAED;;;OAGG;IACH,IAAc,WAAW;QACvB,OAAO,
|
|
1
|
+
{"version":3,"file":"base-ai.usecase.js","sourceRoot":"","sources":["../../../../src/middleware/usecases/base/base-ai.usecase.ts"],"names":[],"mappings":";;;AAAA,4CAA6D;AAC7D,qEAA4G;AAC5G,0FAAqF;AAGrF,4HAA+I;AAC/I,oFAAqF;AAErF;;;;;;GAMG;AACH,MAAsB,aAAa;IAiBjC;;;OAGG;IACH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K,CAAC,eAAe,CAAC,QAAgB;QAC9C,OAAO,qDAAwB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;;AApNH,sCA8NC;AAnNC;;;GAGG;AACuB,sCAAwB,GAAmB,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loonylabs/llm-middleware",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Complete middleware infrastructure for LLM-based backends with multi-provider support (Ollama, Anthropic, OpenAI, Google)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|