@semiont/inference 0.2.34-build.91 → 0.2.34-build.92
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/dist/index.d.ts +5 -4
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvironmentConfig } from '@semiont/core';
|
|
1
|
+
import { EnvironmentConfig, Logger } from '@semiont/core';
|
|
2
2
|
|
|
3
3
|
interface InferenceResponse {
|
|
4
4
|
text: string;
|
|
@@ -31,8 +31,8 @@ interface InferenceClientConfig {
|
|
|
31
31
|
endpoint?: string;
|
|
32
32
|
baseURL?: string;
|
|
33
33
|
}
|
|
34
|
-
declare function createInferenceClient(config: InferenceClientConfig): InferenceClient;
|
|
35
|
-
declare function getInferenceClient(config: EnvironmentConfig): Promise<InferenceClient>;
|
|
34
|
+
declare function createInferenceClient(config: InferenceClientConfig, logger?: Logger): InferenceClient;
|
|
35
|
+
declare function getInferenceClient(config: EnvironmentConfig, logger?: Logger): Promise<InferenceClient>;
|
|
36
36
|
/**
|
|
37
37
|
* Get the configured model name
|
|
38
38
|
*/
|
|
@@ -41,7 +41,8 @@ declare function getInferenceModel(config: EnvironmentConfig): string;
|
|
|
41
41
|
declare class AnthropicInferenceClient implements InferenceClient {
|
|
42
42
|
private client;
|
|
43
43
|
private model;
|
|
44
|
-
|
|
44
|
+
private logger?;
|
|
45
|
+
constructor(apiKey: string, model: string, baseURL?: string, logger?: Logger);
|
|
45
46
|
generateText(prompt: string, maxTokens: number, temperature: number): Promise<string>;
|
|
46
47
|
generateTextWithMetadata(prompt: string, maxTokens: number, temperature: number): Promise<InferenceResponse>;
|
|
47
48
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,19 +3,26 @@ import Anthropic from "@anthropic-ai/sdk";
|
|
|
3
3
|
var AnthropicInferenceClient = class {
|
|
4
4
|
client;
|
|
5
5
|
model;
|
|
6
|
-
|
|
6
|
+
logger;
|
|
7
|
+
constructor(apiKey, model, baseURL, logger) {
|
|
7
8
|
this.client = new Anthropic({
|
|
8
9
|
apiKey,
|
|
9
10
|
baseURL: baseURL || "https://api.anthropic.com"
|
|
10
11
|
});
|
|
11
12
|
this.model = model;
|
|
13
|
+
this.logger = logger;
|
|
12
14
|
}
|
|
13
15
|
async generateText(prompt, maxTokens, temperature) {
|
|
14
16
|
const response = await this.generateTextWithMetadata(prompt, maxTokens, temperature);
|
|
15
17
|
return response.text;
|
|
16
18
|
}
|
|
17
19
|
async generateTextWithMetadata(prompt, maxTokens, temperature) {
|
|
18
|
-
|
|
20
|
+
this.logger?.debug("Generating text with inference client", {
|
|
21
|
+
model: this.model,
|
|
22
|
+
promptLength: prompt.length,
|
|
23
|
+
maxTokens,
|
|
24
|
+
temperature
|
|
25
|
+
});
|
|
19
26
|
const response = await this.client.messages.create({
|
|
20
27
|
model: this.model,
|
|
21
28
|
max_tokens: maxTokens,
|
|
@@ -27,13 +34,24 @@ var AnthropicInferenceClient = class {
|
|
|
27
34
|
}
|
|
28
35
|
]
|
|
29
36
|
});
|
|
30
|
-
|
|
37
|
+
this.logger?.debug("Inference response received", {
|
|
38
|
+
model: this.model,
|
|
39
|
+
contentBlocks: response.content.length,
|
|
40
|
+
stopReason: response.stop_reason
|
|
41
|
+
});
|
|
31
42
|
const textContent = response.content.find((c) => c.type === "text");
|
|
32
43
|
if (!textContent || textContent.type !== "text") {
|
|
33
|
-
|
|
44
|
+
this.logger?.error("No text content in inference response", {
|
|
45
|
+
model: this.model,
|
|
46
|
+
contentTypes: response.content.map((c) => c.type)
|
|
47
|
+
});
|
|
34
48
|
throw new Error("No text content in inference response");
|
|
35
49
|
}
|
|
36
|
-
|
|
50
|
+
this.logger?.info("Text generation completed", {
|
|
51
|
+
model: this.model,
|
|
52
|
+
textLength: textContent.text.length,
|
|
53
|
+
stopReason: response.stop_reason
|
|
54
|
+
});
|
|
37
55
|
return {
|
|
38
56
|
text: textContent.text,
|
|
39
57
|
stopReason: response.stop_reason || "unknown"
|
|
@@ -42,7 +60,7 @@ var AnthropicInferenceClient = class {
|
|
|
42
60
|
};
|
|
43
61
|
|
|
44
62
|
// src/factory.ts
|
|
45
|
-
function createInferenceClient(config) {
|
|
63
|
+
function createInferenceClient(config, logger) {
|
|
46
64
|
switch (config.type) {
|
|
47
65
|
case "anthropic": {
|
|
48
66
|
if (!config.apiKey || config.apiKey.trim() === "") {
|
|
@@ -51,7 +69,8 @@ function createInferenceClient(config) {
|
|
|
51
69
|
return new AnthropicInferenceClient(
|
|
52
70
|
config.apiKey,
|
|
53
71
|
config.model,
|
|
54
|
-
config.endpoint || config.baseURL
|
|
72
|
+
config.endpoint || config.baseURL,
|
|
73
|
+
logger
|
|
55
74
|
);
|
|
56
75
|
}
|
|
57
76
|
default:
|
|
@@ -68,7 +87,7 @@ function evaluateEnvVar(value) {
|
|
|
68
87
|
return envValue;
|
|
69
88
|
});
|
|
70
89
|
}
|
|
71
|
-
async function getInferenceClient(config) {
|
|
90
|
+
async function getInferenceClient(config, logger) {
|
|
72
91
|
const inferenceConfig = config.services.inference;
|
|
73
92
|
if (!inferenceConfig) {
|
|
74
93
|
throw new Error("services.inference is required in environment config");
|
|
@@ -83,14 +102,17 @@ async function getInferenceClient(config) {
|
|
|
83
102
|
endpoint: inferenceConfig.endpoint,
|
|
84
103
|
baseURL: inferenceConfig.baseURL
|
|
85
104
|
};
|
|
86
|
-
|
|
105
|
+
logger?.info("Loading inference client configuration", {
|
|
87
106
|
type: clientConfig.type,
|
|
88
107
|
model: clientConfig.model,
|
|
89
108
|
endpoint: clientConfig.endpoint,
|
|
90
109
|
hasApiKey: !!clientConfig.apiKey
|
|
91
110
|
});
|
|
92
|
-
const client = createInferenceClient(clientConfig);
|
|
93
|
-
|
|
111
|
+
const client = createInferenceClient(clientConfig, logger);
|
|
112
|
+
logger?.info("Inference client initialized", {
|
|
113
|
+
type: inferenceConfig.type,
|
|
114
|
+
model: inferenceConfig.model
|
|
115
|
+
});
|
|
94
116
|
return client;
|
|
95
117
|
}
|
|
96
118
|
function getInferenceModel(config) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/implementations/anthropic.ts","../src/factory.ts","../src/implementations/mock.ts"],"sourcesContent":["// Anthropic Claude implementation of InferenceClient interface\n\nimport Anthropic from '@anthropic-ai/sdk';\nimport { InferenceClient, InferenceResponse } from '../interface.js';\n\nexport class AnthropicInferenceClient implements InferenceClient {\n private client: Anthropic;\n private model: string;\n\n constructor(apiKey: string, model: string, baseURL?: string) {\n this.client = new Anthropic({\n apiKey,\n baseURL: baseURL || 'https://api.anthropic.com',\n });\n this.model = model;\n }\n\n async generateText(prompt: string, maxTokens: number, temperature: number): Promise<string> {\n const response = await this.generateTextWithMetadata(prompt, maxTokens, temperature);\n return response.text;\n }\n\n async generateTextWithMetadata(prompt: string, maxTokens: number, temperature: number): Promise<InferenceResponse> {\n console.log('generateText called with prompt length:', prompt.length, 'maxTokens:', maxTokens, 'temp:', temperature);\n\n const response = await this.client.messages.create({\n model: this.model,\n max_tokens: maxTokens,\n temperature,\n messages: [\n {\n role: 'user',\n content: prompt\n }\n ]\n });\n\n console.log('Inference response received, content blocks:', response.content.length);\n\n const textContent = response.content.find(c => c.type === 'text');\n\n if (!textContent || textContent.type !== 'text') {\n console.error('No text content in response:', response.content);\n throw new Error('No text content in inference response');\n }\n\n console.log('Returning text content of length:', textContent.text.length);\n\n return {\n text: textContent.text,\n stopReason: response.stop_reason || 'unknown'\n };\n }\n}\n","// Factory for creating inference client instances based on configuration\n\nimport type { EnvironmentConfig } from '@semiont/core';\nimport { InferenceClient } from './interface.js';\nimport { AnthropicInferenceClient } from './implementations/anthropic.js';\n\nexport type InferenceClientType = 'anthropic';\n\nexport interface InferenceClientConfig {\n type: InferenceClientType;\n apiKey?: string;\n model: string;\n endpoint?: string;\n baseURL?: string;\n}\n\nexport function createInferenceClient(config: InferenceClientConfig): InferenceClient {\n switch (config.type) {\n case 'anthropic': {\n if (!config.apiKey || config.apiKey.trim() === '') {\n throw new Error('apiKey is required for Anthropic inference client');\n }\n return new AnthropicInferenceClient(\n config.apiKey,\n config.model,\n config.endpoint || config.baseURL\n );\n }\n\n default:\n throw new Error(`Unsupported inference client type: ${config.type}`);\n }\n}\n\n// Helper function to evaluate environment variable placeholders\nfunction evaluateEnvVar(value: string | undefined): string | undefined {\n if (!value) return undefined;\n\n // Replace ${VAR_NAME} with actual environment variable value\n return value.replace(/\\$\\{([^}]+)\\}/g, (match, varName) => {\n const envValue = process.env[varName];\n if (!envValue) {\n throw new Error(`Environment variable ${varName} is not set. Referenced in configuration as ${match}`);\n }\n return envValue;\n });\n}\n\nexport async function getInferenceClient(config: EnvironmentConfig): Promise<InferenceClient> {\n const inferenceConfig = config.services.inference;\n if (!inferenceConfig) {\n throw new Error('services.inference is required in environment config');\n }\n\n if (!inferenceConfig.model) {\n throw new Error('services.inference.model is required in environment config');\n }\n\n const clientConfig: InferenceClientConfig = {\n type: inferenceConfig.type as InferenceClientType,\n apiKey: evaluateEnvVar(inferenceConfig.apiKey),\n model: inferenceConfig.model,\n endpoint: inferenceConfig.endpoint,\n baseURL: inferenceConfig.baseURL,\n };\n\n console.log('Inference config loaded:', {\n type: clientConfig.type,\n model: clientConfig.model,\n endpoint: clientConfig.endpoint,\n hasApiKey: !!clientConfig.apiKey\n });\n\n const client = createInferenceClient(clientConfig);\n\n console.log(`Initialized ${inferenceConfig.type} inference client with model ${inferenceConfig.model}`);\n return client;\n}\n\n/**\n * Get the configured model name\n */\nexport function getInferenceModel(config: EnvironmentConfig): string {\n const inferenceConfig = config.services.inference;\n if (!inferenceConfig?.model) {\n throw new Error('Inference model not configured! Set it in your environment configuration.');\n }\n return inferenceConfig.model;\n}\n\n","// Mock implementation of InferenceClient for testing\n\nimport { InferenceClient, InferenceResponse } from '../interface.js';\n\nexport class MockInferenceClient implements InferenceClient {\n private responses: string[] = [];\n private responseIndex: number = 0;\n private stopReasons: string[] = [];\n public calls: Array<{ prompt: string; maxTokens: number; temperature: number }> = [];\n\n constructor(responses: string[] = ['Mock response'], stopReasons?: string[]) {\n this.responses = responses;\n this.stopReasons = stopReasons || responses.map(() => 'end_turn');\n }\n\n async generateText(prompt: string, maxTokens: number, temperature: number): Promise<string> {\n const response = await this.generateTextWithMetadata(prompt, maxTokens, temperature);\n return response.text;\n }\n\n async generateTextWithMetadata(prompt: string, maxTokens: number, temperature: number): Promise<InferenceResponse> {\n this.calls.push({ prompt, maxTokens, temperature });\n\n const text = this.responses[this.responseIndex];\n const stopReason = this.stopReasons[this.responseIndex] || 'end_turn';\n\n if (this.responseIndex < this.responses.length - 1) {\n this.responseIndex++;\n }\n\n return { text, stopReason };\n }\n\n // Test helper methods\n reset(): void {\n this.calls = [];\n this.responseIndex = 0;\n }\n\n setResponses(responses: string[], stopReasons?: string[]): void {\n this.responses = responses;\n this.stopReasons = stopReasons || responses.map(() => 'end_turn');\n this.responseIndex = 0;\n }\n}\n"],"mappings":";AAEA,OAAO,eAAe;AAGf,IAAM,2BAAN,MAA0D;AAAA,EACvD;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,OAAe,SAAkB;AAC3D,SAAK,SAAS,IAAI,UAAU;AAAA,MAC1B;AAAA,MACA,SAAS,WAAW;AAAA,IACtB,CAAC;AACD,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,MAAM,aAAa,QAAgB,WAAmB,aAAsC;AAC1F,UAAM,WAAW,MAAM,KAAK,yBAAyB,QAAQ,WAAW,WAAW;AACnF,WAAO,SAAS;AAAA,EAClB;AAAA,EAEA,MAAM,yBAAyB,QAAgB,WAAmB,aAAiD;AACjH,YAAQ,IAAI,2CAA2C,OAAO,QAAQ,cAAc,WAAW,SAAS,WAAW;AAEnH,UAAM,WAAW,MAAM,KAAK,OAAO,SAAS,OAAO;AAAA,MACjD,OAAO,KAAK;AAAA,MACZ,YAAY;AAAA,MACZ;AAA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K,UAAU,KAAK,aAAa;AAC9C,UAAM,aAAa,KAAK,YAAY,KAAK,aAAa,KAAK;AAE3D,QAAI,KAAK,gBAAgB,KAAK,UAAU,SAAS,GAAG;AAClD,WAAK;AAAA,IACP;AAEA,WAAO,EAAE,MAAM,WAAW;AAAA,EAC5B;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,QAAQ,CAAC;AACd,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,aAAa,WAAqB,aAA8B;AAC9D,SAAK,YAAY;AACjB,SAAK,cAAc,eAAe,UAAU,IAAI,MAAM,UAAU;AAChE,SAAK,gBAAgB;AAAA,EACvB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/implementations/anthropic.ts","../src/factory.ts","../src/implementations/mock.ts"],"sourcesContent":["// Anthropic Claude implementation of InferenceClient interface\n\nimport Anthropic from '@anthropic-ai/sdk';\nimport type { Logger } from '@semiont/core';\nimport { InferenceClient, InferenceResponse } from '../interface.js';\n\nexport class AnthropicInferenceClient implements InferenceClient {\n private client: Anthropic;\n private model: string;\n private logger?: Logger;\n\n constructor(apiKey: string, model: string, baseURL?: string, logger?: Logger) {\n this.client = new Anthropic({\n apiKey,\n baseURL: baseURL || 'https://api.anthropic.com',\n });\n this.model = model;\n this.logger = logger;\n }\n\n async generateText(prompt: string, maxTokens: number, temperature: number): Promise<string> {\n const response = await this.generateTextWithMetadata(prompt, maxTokens, temperature);\n return response.text;\n }\n\n async generateTextWithMetadata(prompt: string, maxTokens: number, temperature: number): Promise<InferenceResponse> {\n this.logger?.debug('Generating text with inference client', {\n model: this.model,\n promptLength: prompt.length,\n maxTokens,\n temperature\n });\n\n const response = await this.client.messages.create({\n model: this.model,\n max_tokens: maxTokens,\n temperature,\n messages: [\n {\n role: 'user',\n content: prompt\n }\n ]\n });\n\n this.logger?.debug('Inference response received', {\n model: this.model,\n contentBlocks: response.content.length,\n stopReason: response.stop_reason\n });\n\n const textContent = response.content.find(c => c.type === 'text');\n\n if (!textContent || textContent.type !== 'text') {\n this.logger?.error('No text content in inference response', {\n model: this.model,\n contentTypes: response.content.map(c => c.type)\n });\n throw new Error('No text content in inference response');\n }\n\n this.logger?.info('Text generation completed', {\n model: this.model,\n textLength: textContent.text.length,\n stopReason: response.stop_reason\n });\n\n return {\n text: textContent.text,\n stopReason: response.stop_reason || 'unknown'\n };\n }\n}\n","// Factory for creating inference client instances based on configuration\n\nimport type { EnvironmentConfig, Logger } from '@semiont/core';\nimport { InferenceClient } from './interface.js';\nimport { AnthropicInferenceClient } from './implementations/anthropic.js';\n\nexport type InferenceClientType = 'anthropic';\n\nexport interface InferenceClientConfig {\n type: InferenceClientType;\n apiKey?: string;\n model: string;\n endpoint?: string;\n baseURL?: string;\n}\n\nexport function createInferenceClient(config: InferenceClientConfig, logger?: Logger): InferenceClient {\n switch (config.type) {\n case 'anthropic': {\n if (!config.apiKey || config.apiKey.trim() === '') {\n throw new Error('apiKey is required for Anthropic inference client');\n }\n return new AnthropicInferenceClient(\n config.apiKey,\n config.model,\n config.endpoint || config.baseURL,\n logger\n );\n }\n\n default:\n throw new Error(`Unsupported inference client type: ${config.type}`);\n }\n}\n\n// Helper function to evaluate environment variable placeholders\nfunction evaluateEnvVar(value: string | undefined): string | undefined {\n if (!value) return undefined;\n\n // Replace ${VAR_NAME} with actual environment variable value\n return value.replace(/\\$\\{([^}]+)\\}/g, (match, varName) => {\n const envValue = process.env[varName];\n if (!envValue) {\n throw new Error(`Environment variable ${varName} is not set. Referenced in configuration as ${match}`);\n }\n return envValue;\n });\n}\n\nexport async function getInferenceClient(config: EnvironmentConfig, logger?: Logger): Promise<InferenceClient> {\n const inferenceConfig = config.services.inference;\n if (!inferenceConfig) {\n throw new Error('services.inference is required in environment config');\n }\n\n if (!inferenceConfig.model) {\n throw new Error('services.inference.model is required in environment config');\n }\n\n const clientConfig: InferenceClientConfig = {\n type: inferenceConfig.type as InferenceClientType,\n apiKey: evaluateEnvVar(inferenceConfig.apiKey),\n model: inferenceConfig.model,\n endpoint: inferenceConfig.endpoint,\n baseURL: inferenceConfig.baseURL,\n };\n\n logger?.info('Loading inference client configuration', {\n type: clientConfig.type,\n model: clientConfig.model,\n endpoint: clientConfig.endpoint,\n hasApiKey: !!clientConfig.apiKey\n });\n\n const client = createInferenceClient(clientConfig, logger);\n\n logger?.info('Inference client initialized', {\n type: inferenceConfig.type,\n model: inferenceConfig.model\n });\n return client;\n}\n\n/**\n * Get the configured model name\n */\nexport function getInferenceModel(config: EnvironmentConfig): string {\n const inferenceConfig = config.services.inference;\n if (!inferenceConfig?.model) {\n throw new Error('Inference model not configured! Set it in your environment configuration.');\n }\n return inferenceConfig.model;\n}\n\n","// Mock implementation of InferenceClient for testing\n\nimport { InferenceClient, InferenceResponse } from '../interface.js';\n\nexport class MockInferenceClient implements InferenceClient {\n private responses: string[] = [];\n private responseIndex: number = 0;\n private stopReasons: string[] = [];\n public calls: Array<{ prompt: string; maxTokens: number; temperature: number }> = [];\n\n constructor(responses: string[] = ['Mock response'], stopReasons?: string[]) {\n this.responses = responses;\n this.stopReasons = stopReasons || responses.map(() => 'end_turn');\n }\n\n async generateText(prompt: string, maxTokens: number, temperature: number): Promise<string> {\n const response = await this.generateTextWithMetadata(prompt, maxTokens, temperature);\n return response.text;\n }\n\n async generateTextWithMetadata(prompt: string, maxTokens: number, temperature: number): Promise<InferenceResponse> {\n this.calls.push({ prompt, maxTokens, temperature });\n\n const text = this.responses[this.responseIndex];\n const stopReason = this.stopReasons[this.responseIndex] || 'end_turn';\n\n if (this.responseIndex < this.responses.length - 1) {\n this.responseIndex++;\n }\n\n return { text, stopReason };\n }\n\n // Test helper methods\n reset(): void {\n this.calls = [];\n this.responseIndex = 0;\n }\n\n setResponses(responses: string[], stopReasons?: string[]): void {\n this.responses = responses;\n this.stopReasons = stopReasons || responses.map(() => 'end_turn');\n this.responseIndex = 0;\n }\n}\n"],"mappings":";AAEA,OAAO,eAAe;AAIf,IAAM,2BAAN,MAA0D;AAAA,EACvD;AAAA,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