@flutchai/flutch-sdk 0.2.8 → 0.2.9
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.cjs +80 -392
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -21
- package/dist/index.d.ts +9 -21
- package/dist/index.js +80 -392
- package/dist/index.js.map +1 -1
- package/package.json +56 -15
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import axios2 from 'axios';
|
|
|
20
20
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
21
21
|
import { parseCallbackConfigArg, CallbackManager } from '@langchain/core/callbacks/manager';
|
|
22
22
|
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
|
23
|
-
import {
|
|
23
|
+
import { ChatBedrockConverse } from '@langchain/aws';
|
|
24
24
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
25
25
|
import { ChatCohere, CohereRerank } from '@langchain/cohere';
|
|
26
26
|
import { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';
|
|
@@ -6390,10 +6390,6 @@ McpRuntimeHttpClient = __decorateClass([
|
|
|
6390
6390
|
|
|
6391
6391
|
// src/models/enums.ts
|
|
6392
6392
|
var ModelProvider = /* @__PURE__ */ ((ModelProvider2) => {
|
|
6393
|
-
ModelProvider2["FLUTCH"] = "flutch";
|
|
6394
|
-
ModelProvider2["FLUTCH_MISTRAL"] = "flutch-mistral";
|
|
6395
|
-
ModelProvider2["FLUTCH_OPENAI"] = "flutch-openai";
|
|
6396
|
-
ModelProvider2["FLUTCH_ANTHROPIC"] = "flutch-anthropic";
|
|
6397
6393
|
ModelProvider2["MISTRAL"] = "mistral";
|
|
6398
6394
|
ModelProvider2["OPENAI"] = "openai";
|
|
6399
6395
|
ModelProvider2["ANTHROPIC"] = "anthropic";
|
|
@@ -6436,6 +6432,25 @@ function generateModelCacheKey(modelId, temperature, maxTokens, toolsConfig) {
|
|
|
6436
6432
|
}
|
|
6437
6433
|
return parts.join(":");
|
|
6438
6434
|
}
|
|
6435
|
+
function buildOpenAIModelConfig(modelName, temperature, maxTokens, apiToken) {
|
|
6436
|
+
if (isReasoningModel(modelName)) {
|
|
6437
|
+
return {
|
|
6438
|
+
modelName,
|
|
6439
|
+
temperature: 1,
|
|
6440
|
+
// Reasoning models only support temperature=1
|
|
6441
|
+
maxCompletionTokens: maxTokens,
|
|
6442
|
+
streaming: true,
|
|
6443
|
+
openAIApiKey: apiToken
|
|
6444
|
+
};
|
|
6445
|
+
}
|
|
6446
|
+
return {
|
|
6447
|
+
modelName,
|
|
6448
|
+
temperature,
|
|
6449
|
+
maxTokens,
|
|
6450
|
+
streaming: true,
|
|
6451
|
+
openAIApiKey: apiToken
|
|
6452
|
+
};
|
|
6453
|
+
}
|
|
6439
6454
|
var VoyageAIRerank = class extends BaseDocumentCompressor {
|
|
6440
6455
|
apiKey;
|
|
6441
6456
|
model;
|
|
@@ -6487,235 +6502,10 @@ var VoyageAIRerank = class extends BaseDocumentCompressor {
|
|
|
6487
6502
|
}
|
|
6488
6503
|
}
|
|
6489
6504
|
};
|
|
6490
|
-
function patchChatOpenAIForGPT5() {
|
|
6491
|
-
const logger2 = new Logger("ModelInitializer.Patch");
|
|
6492
|
-
logger2.warn(
|
|
6493
|
-
`TEMPORARY WORKAROUND: Applying monkey patch for GPT-5 support in LangChain. Fixes: max_tokens->max_completion_tokens, temperature->1. This patch will be removed once LangChain officially supports GPT-5 models.`
|
|
6494
|
-
);
|
|
6495
|
-
const prototypes = [
|
|
6496
|
-
ChatOpenAI.prototype,
|
|
6497
|
-
AzureChatOpenAI.prototype
|
|
6498
|
-
];
|
|
6499
|
-
prototypes.forEach((prototype, index) => {
|
|
6500
|
-
const modelName = index === 0 ? "ChatOpenAI" : "AzureChatOpenAI";
|
|
6501
|
-
logger2.warn(`Patching ${modelName} for GPT-5 support`);
|
|
6502
|
-
const originalInvocationParams = prototype.invocationParams;
|
|
6503
|
-
if (originalInvocationParams) {
|
|
6504
|
-
prototype.invocationParams = function(options) {
|
|
6505
|
-
const params = originalInvocationParams.call(this, options);
|
|
6506
|
-
if (params.model && (params.model.includes("gpt-5") || /^gpt-(5|6|7|8|9)/.test(params.model))) {
|
|
6507
|
-
if (params.max_tokens !== void 0) {
|
|
6508
|
-
params.max_completion_tokens = params.max_tokens;
|
|
6509
|
-
delete params.max_tokens;
|
|
6510
|
-
}
|
|
6511
|
-
if (params.max_output_tokens !== void 0 && !params.max_completion_tokens) {
|
|
6512
|
-
params.max_completion_tokens = params.max_output_tokens;
|
|
6513
|
-
delete params.max_output_tokens;
|
|
6514
|
-
}
|
|
6515
|
-
const originalTemperature = params.temperature;
|
|
6516
|
-
if (params.temperature !== void 0 && params.temperature !== 1) {
|
|
6517
|
-
params.temperature = 1;
|
|
6518
|
-
logger2.debug(
|
|
6519
|
-
`Fixed temperature for ${params.model}: ${originalTemperature} -> 1 (GPT-5 models only support temperature=1)`
|
|
6520
|
-
);
|
|
6521
|
-
}
|
|
6522
|
-
}
|
|
6523
|
-
if (params.model && (params.model.includes("gpt-5") || /^gpt-(5|6|7|8|9)/.test(params.model))) {
|
|
6524
|
-
if (!params.stream_options) {
|
|
6525
|
-
params.stream_options = { include_usage: true };
|
|
6526
|
-
logger2.warn(
|
|
6527
|
-
`[GPT-5 PATCH] Added stream_options.include_usage=true for ${params.model}`
|
|
6528
|
-
);
|
|
6529
|
-
} else if (params.stream_options.include_usage !== true) {
|
|
6530
|
-
params.stream_options.include_usage = true;
|
|
6531
|
-
logger2.warn(
|
|
6532
|
-
`[GPT-5 PATCH] Updated stream_options.include_usage=true for ${params.model}`
|
|
6533
|
-
);
|
|
6534
|
-
}
|
|
6535
|
-
}
|
|
6536
|
-
return params;
|
|
6537
|
-
};
|
|
6538
|
-
logger2.warn(
|
|
6539
|
-
`Successfully patched ${modelName}.invocationParams for GPT-5 support (TEMPORARY WORKAROUND)`
|
|
6540
|
-
);
|
|
6541
|
-
} else {
|
|
6542
|
-
logger2.warn(
|
|
6543
|
-
`Could not find invocationParams method to patch in ${modelName}`
|
|
6544
|
-
);
|
|
6545
|
-
}
|
|
6546
|
-
const originalCompletionWithRetry = prototype.completionWithRetry;
|
|
6547
|
-
if (originalCompletionWithRetry) {
|
|
6548
|
-
prototype.completionWithRetry = async function(request, options) {
|
|
6549
|
-
if (request?.model && (request.model.includes("gpt-5") || /^gpt-(5|6|7|8|9)/.test(request.model))) {
|
|
6550
|
-
let hasChanges = false;
|
|
6551
|
-
if (request.max_tokens !== void 0) {
|
|
6552
|
-
request.max_completion_tokens = request.max_tokens;
|
|
6553
|
-
delete request.max_tokens;
|
|
6554
|
-
hasChanges = true;
|
|
6555
|
-
}
|
|
6556
|
-
if (request.temperature !== void 0 && request.temperature !== 1) {
|
|
6557
|
-
const originalTemp = request.temperature;
|
|
6558
|
-
request.temperature = 1;
|
|
6559
|
-
logger2.debug(
|
|
6560
|
-
`Fixed temperature in completionWithRetry for ${request.model}: ${originalTemp} -> 1`
|
|
6561
|
-
);
|
|
6562
|
-
hasChanges = true;
|
|
6563
|
-
}
|
|
6564
|
-
if (!request.stream_options) {
|
|
6565
|
-
request.stream_options = { include_usage: true };
|
|
6566
|
-
logger2.debug(
|
|
6567
|
-
`Added stream_options.include_usage=true in completionWithRetry for ${request.model}`
|
|
6568
|
-
);
|
|
6569
|
-
hasChanges = true;
|
|
6570
|
-
} else if (request.stream_options.include_usage !== true) {
|
|
6571
|
-
request.stream_options.include_usage = true;
|
|
6572
|
-
logger2.debug(
|
|
6573
|
-
`Updated stream_options.include_usage=true in completionWithRetry for ${request.model}`
|
|
6574
|
-
);
|
|
6575
|
-
hasChanges = true;
|
|
6576
|
-
}
|
|
6577
|
-
if (hasChanges) {
|
|
6578
|
-
logger2.debug(
|
|
6579
|
-
`Fixed request params in completionWithRetry for ${request.model}`
|
|
6580
|
-
);
|
|
6581
|
-
}
|
|
6582
|
-
}
|
|
6583
|
-
const result = await originalCompletionWithRetry.call(
|
|
6584
|
-
this,
|
|
6585
|
-
request,
|
|
6586
|
-
options
|
|
6587
|
-
);
|
|
6588
|
-
if (request?.model && (request.model.includes("gpt-5") || /^gpt-(5|6|7|8|9)/.test(request.model))) {
|
|
6589
|
-
logger2.warn(
|
|
6590
|
-
`[GPT-5 PATCH] Azure OpenAI Response for ${request.model}:`
|
|
6591
|
-
);
|
|
6592
|
-
logger2.warn(`Response keys: ${Object.keys(result || {}).join(", ")}`);
|
|
6593
|
-
if (result?.usage) {
|
|
6594
|
-
logger2.warn(
|
|
6595
|
-
`Usage found: ${JSON.stringify(result.usage, null, 2)}`
|
|
6596
|
-
);
|
|
6597
|
-
} else {
|
|
6598
|
-
logger2.warn(`No usage found in response`);
|
|
6599
|
-
}
|
|
6600
|
-
if (result?.choices && result.choices[0]) {
|
|
6601
|
-
logger2.warn(
|
|
6602
|
-
`First choice keys: ${Object.keys(result.choices[0]).join(", ")}`
|
|
6603
|
-
);
|
|
6604
|
-
}
|
|
6605
|
-
}
|
|
6606
|
-
return result;
|
|
6607
|
-
};
|
|
6608
|
-
logger2.warn(
|
|
6609
|
-
`Successfully patched ${modelName}.completionWithRetry for GPT-5 support (TEMPORARY WORKAROUND)`
|
|
6610
|
-
);
|
|
6611
|
-
}
|
|
6612
|
-
const originalIsReasoningModel = prototype.isReasoningModel;
|
|
6613
|
-
if (originalIsReasoningModel) {
|
|
6614
|
-
prototype.isReasoningModel = function() {
|
|
6615
|
-
const model = this.modelName || this.model || this.lc_kwargs?.modelName;
|
|
6616
|
-
const isReasoning = /^o\d/.test(model) || model.includes("gpt-5") || /^gpt-(6|7|8|9)/.test(model);
|
|
6617
|
-
const originalResult = originalIsReasoningModel.call(this);
|
|
6618
|
-
logger2.warn(
|
|
6619
|
-
`[GPT-5 PATCH] isReasoningModel check for "${model}": patched=${isReasoning}, original=${originalResult}, modelName=${this.modelName}, model=${this.model}, lc_kwargs=${JSON.stringify(this.lc_kwargs?.modelName)}`
|
|
6620
|
-
);
|
|
6621
|
-
return isReasoning;
|
|
6622
|
-
};
|
|
6623
|
-
logger2.warn(
|
|
6624
|
-
`Successfully patched ${modelName}.isReasoningModel for GPT-5+ reasoning models (TEMPORARY WORKAROUND)`
|
|
6625
|
-
);
|
|
6626
|
-
} else {
|
|
6627
|
-
logger2.warn(
|
|
6628
|
-
`Could not find isReasoningModel method to patch in ${modelName}`
|
|
6629
|
-
);
|
|
6630
|
-
}
|
|
6631
|
-
const originalInvoke = prototype.invoke;
|
|
6632
|
-
if (originalInvoke) {
|
|
6633
|
-
prototype.invoke = async function(...args) {
|
|
6634
|
-
const model = this.modelName || this.model || this.lc_kwargs?.modelName;
|
|
6635
|
-
if (model && model.includes("gpt-5")) {
|
|
6636
|
-
logger2.warn(`[GPT-5 PATCH] Starting invoke for ${model}`);
|
|
6637
|
-
if (args[1]) {
|
|
6638
|
-
const config = args[1];
|
|
6639
|
-
logger2.warn(
|
|
6640
|
-
`[GPT-5 PATCH] Invoke config keys: ${Object.keys(config || {}).join(", ")}`
|
|
6641
|
-
);
|
|
6642
|
-
if (config.tools) {
|
|
6643
|
-
logger2.warn(
|
|
6644
|
-
`[GPT-5 PATCH] Tools in config: ${config.tools.length} tools`
|
|
6645
|
-
);
|
|
6646
|
-
}
|
|
6647
|
-
}
|
|
6648
|
-
const boundTools = this.bound || this.boundTools || this.tools;
|
|
6649
|
-
if (boundTools) {
|
|
6650
|
-
logger2.warn(
|
|
6651
|
-
`[GPT-5 PATCH] Model has bound tools: ${Array.isArray(boundTools) ? boundTools.length : "yes"}`
|
|
6652
|
-
);
|
|
6653
|
-
} else {
|
|
6654
|
-
logger2.warn(`[GPT-5 PATCH] Model has NO bound tools`);
|
|
6655
|
-
}
|
|
6656
|
-
}
|
|
6657
|
-
let result;
|
|
6658
|
-
try {
|
|
6659
|
-
result = await originalInvoke.apply(this, args);
|
|
6660
|
-
} catch (error) {
|
|
6661
|
-
if (model && model.includes("gpt-5")) {
|
|
6662
|
-
logger2.error(
|
|
6663
|
-
`[GPT-5 PATCH] Azure OpenAI invoke failed for ${model}:`,
|
|
6664
|
-
{
|
|
6665
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
6666
|
-
errorStack: error instanceof Error ? error.stack : void 0,
|
|
6667
|
-
errorType: error?.constructor?.name,
|
|
6668
|
-
args: args.length,
|
|
6669
|
-
hasConfig: !!args[1],
|
|
6670
|
-
configKeys: args[1] ? Object.keys(args[1] || {}) : [],
|
|
6671
|
-
tools: args[1]?.tools?.length || 0
|
|
6672
|
-
}
|
|
6673
|
-
);
|
|
6674
|
-
}
|
|
6675
|
-
throw error;
|
|
6676
|
-
}
|
|
6677
|
-
if (model && model.includes("gpt-5")) {
|
|
6678
|
-
logger2.warn(`[GPT-5 PATCH] Azure OpenAI invoke result for ${model}:`);
|
|
6679
|
-
logger2.warn(`Result keys: ${Object.keys(result || {}).join(", ")}`);
|
|
6680
|
-
if (result?.usage_metadata || result?.usageMetadata) {
|
|
6681
|
-
const usage = result.usage_metadata || result.usageMetadata;
|
|
6682
|
-
logger2.warn(
|
|
6683
|
-
`Usage metadata found: ${JSON.stringify(usage, null, 2)}`
|
|
6684
|
-
);
|
|
6685
|
-
}
|
|
6686
|
-
if (result?.response_metadata || result?.responseMetadata) {
|
|
6687
|
-
const responseMetadata = result.response_metadata || result.responseMetadata;
|
|
6688
|
-
logger2.warn(
|
|
6689
|
-
`Response metadata found: ${JSON.stringify(responseMetadata, null, 2)}`
|
|
6690
|
-
);
|
|
6691
|
-
if (!result.usage_metadata && responseMetadata?.estimatedTokenUsage) {
|
|
6692
|
-
const estimatedUsage = responseMetadata.estimatedTokenUsage;
|
|
6693
|
-
result.usage_metadata = {
|
|
6694
|
-
input_tokens: estimatedUsage.promptTokens || 0,
|
|
6695
|
-
output_tokens: estimatedUsage.completionTokens || 0,
|
|
6696
|
-
total_tokens: estimatedUsage.totalTokens || 0
|
|
6697
|
-
};
|
|
6698
|
-
logger2.warn(
|
|
6699
|
-
`[GPT-5 PATCH] Created usage_metadata from estimatedTokenUsage: ${JSON.stringify(result.usage_metadata, null, 2)}`
|
|
6700
|
-
);
|
|
6701
|
-
}
|
|
6702
|
-
}
|
|
6703
|
-
if (!result?.usage_metadata && !result?.usageMetadata) {
|
|
6704
|
-
logger2.warn(`No usage_metadata found in invoke result`);
|
|
6705
|
-
}
|
|
6706
|
-
}
|
|
6707
|
-
return result;
|
|
6708
|
-
};
|
|
6709
|
-
logger2.warn(
|
|
6710
|
-
`Successfully patched ${modelName}.invoke for GPT-5 response logging (TEMPORARY WORKAROUND)`
|
|
6711
|
-
);
|
|
6712
|
-
}
|
|
6713
|
-
});
|
|
6714
|
-
}
|
|
6715
|
-
patchChatOpenAIForGPT5();
|
|
6716
6505
|
var ModelInitializer = class _ModelInitializer {
|
|
6717
|
-
constructor(configFetcher, logger2) {
|
|
6506
|
+
constructor(configFetcher, logger2, apiKeyResolver) {
|
|
6718
6507
|
this.configFetcher = configFetcher;
|
|
6508
|
+
this.apiKeyResolver = apiKeyResolver;
|
|
6719
6509
|
this.logger = logger2 || new Logger(_ModelInitializer.name);
|
|
6720
6510
|
}
|
|
6721
6511
|
logger;
|
|
@@ -6723,9 +6513,30 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6723
6513
|
modelConfigCache = /* @__PURE__ */ new Map();
|
|
6724
6514
|
// Cache for model instances to avoid recreating identical models
|
|
6725
6515
|
modelInstanceCache = /* @__PURE__ */ new Map();
|
|
6516
|
+
static DEFAULT_ENV_MAP = {
|
|
6517
|
+
["openai" /* OPENAI */]: "OPENAI_API_KEY",
|
|
6518
|
+
["anthropic" /* ANTHROPIC */]: "ANTHROPIC_API_KEY",
|
|
6519
|
+
["mistral" /* MISTRAL */]: "MISTRAL_API_KEY",
|
|
6520
|
+
["cohere" /* COHERE */]: "COHERE_API_KEY",
|
|
6521
|
+
["voyageai" /* VOYAGEAI */]: "VOYAGEAI_API_KEY"
|
|
6522
|
+
};
|
|
6726
6523
|
/**
|
|
6727
|
-
*
|
|
6524
|
+
* Resolve API key for a provider.
|
|
6525
|
+
* Uses custom resolver if provided, falls back to process.env.
|
|
6728
6526
|
*/
|
|
6527
|
+
resolveApiKey(provider) {
|
|
6528
|
+
if (this.apiKeyResolver) {
|
|
6529
|
+
return this.apiKeyResolver(provider);
|
|
6530
|
+
}
|
|
6531
|
+
const envVar = _ModelInitializer.DEFAULT_ENV_MAP[provider];
|
|
6532
|
+
return envVar ? process.env[envVar] : void 0;
|
|
6533
|
+
}
|
|
6534
|
+
/**
|
|
6535
|
+
* Resolve AWS region for Bedrock.
|
|
6536
|
+
*/
|
|
6537
|
+
resolveBedrockRegion() {
|
|
6538
|
+
return process.env.BEDROCK_AWS_REGION || process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || "us-east-1";
|
|
6539
|
+
}
|
|
6729
6540
|
/**
|
|
6730
6541
|
* Generate hash from toolsConfig for cache key
|
|
6731
6542
|
* Uses MD5 hash to create short, unique identifier
|
|
@@ -6746,29 +6557,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6746
6557
|
config.toolsConfig
|
|
6747
6558
|
);
|
|
6748
6559
|
}
|
|
6749
|
-
|
|
6750
|
-
* TEMPORARY SOLUTION for compatibility with new OpenAI models
|
|
6751
|
-
*
|
|
6752
|
-
* OpenAI changed the API for new models (gpt-5, o-series):
|
|
6753
|
-
* - Old models (gpt-3.5, gpt-4, gpt-4o): use maxTokens, support custom temperature
|
|
6754
|
-
* - New reasoning models (gpt-5, gpt-o1, gpt-o3, gpt-o4): use maxCompletionTokens, only temperature = 1
|
|
6755
|
-
*
|
|
6756
|
-
* Patch fixes:
|
|
6757
|
-
* 1. max_tokens -> max_completion_tokens for reasoning GPT-5+ models
|
|
6758
|
-
* 2. temperature -> 1 (forced) for reasoning GPT-5+ models
|
|
6759
|
-
*
|
|
6760
|
-
* @param modelName - OpenAI model name
|
|
6761
|
-
* @returns true if model requires maxCompletionTokens and temperature = 1
|
|
6762
|
-
*/
|
|
6763
|
-
requiresMaxCompletionTokens(modelName) {
|
|
6764
|
-
const requiresNew = isReasoningModel(modelName);
|
|
6765
|
-
this.logger.debug(`Checking token parameter for model "${modelName}"`, {
|
|
6766
|
-
modelName,
|
|
6767
|
-
requiresMaxCompletionTokens: requiresNew
|
|
6768
|
-
});
|
|
6769
|
-
return requiresNew;
|
|
6770
|
-
}
|
|
6771
|
-
// Chat model creators (inherit from original LLMInitializer)
|
|
6560
|
+
// Chat model creators
|
|
6772
6561
|
chatModelCreators = {
|
|
6773
6562
|
["openai" /* OPENAI */]: ({
|
|
6774
6563
|
modelName,
|
|
@@ -6776,36 +6565,13 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6776
6565
|
defaultMaxTokens,
|
|
6777
6566
|
apiToken
|
|
6778
6567
|
}) => {
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
// Only this parameter for new models
|
|
6787
|
-
streaming: true,
|
|
6788
|
-
openAIApiKey: apiToken || process.env.OPENAI_API_KEY
|
|
6789
|
-
};
|
|
6790
|
-
if (defaultTemperature !== 1) {
|
|
6791
|
-
this.logger.debug(
|
|
6792
|
-
`Fixed temperature for GPT-5+ model ${modelName}: ${defaultTemperature} -> 1 (GPT-5+ models only support temperature=1)`
|
|
6793
|
-
);
|
|
6794
|
-
}
|
|
6795
|
-
const chatOpenAI = new ChatOpenAI(config);
|
|
6796
|
-
return chatOpenAI;
|
|
6797
|
-
} else {
|
|
6798
|
-
const config = {
|
|
6799
|
-
modelName,
|
|
6800
|
-
temperature: defaultTemperature,
|
|
6801
|
-
maxTokens: defaultMaxTokens,
|
|
6802
|
-
// Only this parameter for legacy models
|
|
6803
|
-
streaming: true,
|
|
6804
|
-
openAIApiKey: apiToken || process.env.OPENAI_API_KEY
|
|
6805
|
-
};
|
|
6806
|
-
const chatOpenAI = new ChatOpenAI(config);
|
|
6807
|
-
return chatOpenAI;
|
|
6808
|
-
}
|
|
6568
|
+
const config = buildOpenAIModelConfig(
|
|
6569
|
+
modelName,
|
|
6570
|
+
defaultTemperature,
|
|
6571
|
+
defaultMaxTokens,
|
|
6572
|
+
apiToken || this.resolveApiKey("openai" /* OPENAI */) || ""
|
|
6573
|
+
);
|
|
6574
|
+
return new ChatOpenAI(config);
|
|
6809
6575
|
},
|
|
6810
6576
|
["anthropic" /* ANTHROPIC */]: ({
|
|
6811
6577
|
modelName,
|
|
@@ -6816,7 +6582,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6816
6582
|
modelName,
|
|
6817
6583
|
temperature: defaultTemperature,
|
|
6818
6584
|
maxTokens: defaultMaxTokens,
|
|
6819
|
-
anthropicApiKey: apiToken ||
|
|
6585
|
+
anthropicApiKey: apiToken || this.resolveApiKey("anthropic" /* ANTHROPIC */)
|
|
6820
6586
|
}),
|
|
6821
6587
|
["cohere" /* COHERE */]: ({
|
|
6822
6588
|
modelName,
|
|
@@ -6826,8 +6592,7 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6826
6592
|
}) => new ChatCohere({
|
|
6827
6593
|
model: modelName,
|
|
6828
6594
|
temperature: defaultTemperature,
|
|
6829
|
-
|
|
6830
|
-
apiKey: apiToken || process.env.COHERE_API_KEY
|
|
6595
|
+
apiKey: apiToken || this.resolveApiKey("cohere" /* COHERE */)
|
|
6831
6596
|
}),
|
|
6832
6597
|
["mistral" /* MISTRAL */]: ({
|
|
6833
6598
|
modelName,
|
|
@@ -6838,91 +6603,8 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6838
6603
|
model: modelName,
|
|
6839
6604
|
temperature: defaultTemperature,
|
|
6840
6605
|
maxTokens: defaultMaxTokens,
|
|
6841
|
-
apiKey: apiToken ||
|
|
6606
|
+
apiKey: apiToken || this.resolveApiKey("mistral" /* MISTRAL */)
|
|
6842
6607
|
}),
|
|
6843
|
-
// AWS Bedrock support removed - use Anthropic or OpenAI directly instead
|
|
6844
|
-
["flutch-openai" /* FLUTCH_OPENAI */]: ({
|
|
6845
|
-
modelName,
|
|
6846
|
-
defaultTemperature,
|
|
6847
|
-
defaultMaxTokens,
|
|
6848
|
-
apiToken
|
|
6849
|
-
}) => {
|
|
6850
|
-
if (this.requiresMaxCompletionTokens(modelName)) {
|
|
6851
|
-
const fixedTemperature = 1;
|
|
6852
|
-
const config = {
|
|
6853
|
-
modelName,
|
|
6854
|
-
temperature: fixedTemperature,
|
|
6855
|
-
// Force set to 1
|
|
6856
|
-
maxCompletionTokens: defaultMaxTokens,
|
|
6857
|
-
// Only this parameter for new models
|
|
6858
|
-
streaming: true,
|
|
6859
|
-
openAIApiKey: apiToken || process.env.OPENAI_API_KEY
|
|
6860
|
-
};
|
|
6861
|
-
if (defaultTemperature !== 1) {
|
|
6862
|
-
this.logger.debug(
|
|
6863
|
-
`Fixed temperature for FLUTCH GPT-5+ model ${modelName}: ${defaultTemperature} -> 1 (GPT-5+ models only support temperature=1)`
|
|
6864
|
-
);
|
|
6865
|
-
}
|
|
6866
|
-
this.logger.debug(`Creating FLUTCH GPT-5+ model with config`, {
|
|
6867
|
-
modelName,
|
|
6868
|
-
maxCompletionTokens: defaultMaxTokens,
|
|
6869
|
-
temperature: fixedTemperature,
|
|
6870
|
-
originalTemperature: defaultTemperature,
|
|
6871
|
-
hasApiKey: !!config.openAIApiKey
|
|
6872
|
-
});
|
|
6873
|
-
const chatOpenAI = new ChatOpenAI(config);
|
|
6874
|
-
this.logger.debug(`FLUTCH ChatOpenAI GPT-5+ instance created`, {
|
|
6875
|
-
modelName,
|
|
6876
|
-
// Use modelName from parameters
|
|
6877
|
-
maxTokens: chatOpenAI.maxTokens,
|
|
6878
|
-
maxCompletionTokens: chatOpenAI.maxCompletionTokens,
|
|
6879
|
-
temperature: chatOpenAI.temperature,
|
|
6880
|
-
streaming: chatOpenAI.streaming,
|
|
6881
|
-
// Try to get internal parameters
|
|
6882
|
-
clientConfig: chatOpenAI.clientConfig,
|
|
6883
|
-
kwargs: chatOpenAI.kwargs
|
|
6884
|
-
});
|
|
6885
|
-
return chatOpenAI;
|
|
6886
|
-
} else {
|
|
6887
|
-
const config = {
|
|
6888
|
-
modelName,
|
|
6889
|
-
temperature: defaultTemperature,
|
|
6890
|
-
maxTokens: defaultMaxTokens,
|
|
6891
|
-
// Only this parameter for legacy models
|
|
6892
|
-
streaming: true,
|
|
6893
|
-
openAIApiKey: apiToken || process.env.OPENAI_API_KEY
|
|
6894
|
-
};
|
|
6895
|
-
this.logger.debug(`Creating FLUTCH legacy model with config`, {
|
|
6896
|
-
modelName,
|
|
6897
|
-
maxTokens: defaultMaxTokens,
|
|
6898
|
-
temperature: defaultTemperature,
|
|
6899
|
-
hasApiKey: !!config.openAIApiKey
|
|
6900
|
-
});
|
|
6901
|
-
const chatOpenAI = new ChatOpenAI(config);
|
|
6902
|
-
this.logger.debug(`FLUTCH ChatOpenAI legacy instance created`, {
|
|
6903
|
-
modelName,
|
|
6904
|
-
// Use modelName from parameters
|
|
6905
|
-
maxTokens: chatOpenAI.maxTokens,
|
|
6906
|
-
maxCompletionTokens: chatOpenAI.maxCompletionTokens,
|
|
6907
|
-
temperature: chatOpenAI.temperature,
|
|
6908
|
-
streaming: chatOpenAI.streaming,
|
|
6909
|
-
// Try to get internal parameters
|
|
6910
|
-
clientConfig: chatOpenAI.clientConfig,
|
|
6911
|
-
kwargs: chatOpenAI.kwargs
|
|
6912
|
-
});
|
|
6913
|
-
return chatOpenAI;
|
|
6914
|
-
}
|
|
6915
|
-
},
|
|
6916
|
-
// Other providers not yet implemented for chat
|
|
6917
|
-
["flutch" /* FLUTCH */]: () => {
|
|
6918
|
-
throw new Error("Flutch chat models not implemented");
|
|
6919
|
-
},
|
|
6920
|
-
["flutch-mistral" /* FLUTCH_MISTRAL */]: () => {
|
|
6921
|
-
throw new Error("Flutch Mistral chat models not implemented");
|
|
6922
|
-
},
|
|
6923
|
-
["flutch-anthropic" /* FLUTCH_ANTHROPIC */]: () => {
|
|
6924
|
-
throw new Error("Flutch Anthropic chat models not implemented");
|
|
6925
|
-
},
|
|
6926
6608
|
["voyageai" /* VOYAGEAI */]: () => {
|
|
6927
6609
|
throw new Error("VoyageAI chat models not implemented");
|
|
6928
6610
|
}
|
|
@@ -6931,14 +6613,14 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6931
6613
|
rerankModelCreators = {
|
|
6932
6614
|
["cohere" /* COHERE */]: ({ modelName, apiToken, maxDocuments }) => {
|
|
6933
6615
|
return new CohereRerank({
|
|
6934
|
-
apiKey: apiToken ||
|
|
6616
|
+
apiKey: apiToken || this.resolveApiKey("cohere" /* COHERE */),
|
|
6935
6617
|
model: modelName,
|
|
6936
6618
|
topN: maxDocuments || 20
|
|
6937
6619
|
});
|
|
6938
6620
|
},
|
|
6939
6621
|
["voyageai" /* VOYAGEAI */]: ({ modelName, apiToken, maxDocuments }) => {
|
|
6940
6622
|
return new VoyageAIRerank({
|
|
6941
|
-
apiKey: apiToken ||
|
|
6623
|
+
apiKey: apiToken || this.resolveApiKey("voyageai" /* VOYAGEAI */),
|
|
6942
6624
|
model: modelName,
|
|
6943
6625
|
topN: maxDocuments || 20
|
|
6944
6626
|
});
|
|
@@ -6947,27 +6629,19 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6947
6629
|
["openai" /* OPENAI */]: void 0,
|
|
6948
6630
|
["anthropic" /* ANTHROPIC */]: void 0,
|
|
6949
6631
|
["mistral" /* MISTRAL */]: void 0,
|
|
6950
|
-
["aws" /* AWS */]: void 0
|
|
6951
|
-
["flutch" /* FLUTCH */]: void 0,
|
|
6952
|
-
["flutch-mistral" /* FLUTCH_MISTRAL */]: void 0,
|
|
6953
|
-
["flutch-openai" /* FLUTCH_OPENAI */]: void 0,
|
|
6954
|
-
["flutch-anthropic" /* FLUTCH_ANTHROPIC */]: void 0
|
|
6632
|
+
["aws" /* AWS */]: void 0
|
|
6955
6633
|
};
|
|
6956
6634
|
// Embedding model creators
|
|
6957
6635
|
embeddingModelCreators = {
|
|
6958
6636
|
["openai" /* OPENAI */]: ({ modelName, apiToken }) => new OpenAIEmbeddings({
|
|
6959
6637
|
model: modelName,
|
|
6960
|
-
apiKey: apiToken ||
|
|
6638
|
+
apiKey: apiToken || this.resolveApiKey("openai" /* OPENAI */)
|
|
6961
6639
|
}),
|
|
6962
6640
|
// Other providers not yet implemented for embeddings
|
|
6963
6641
|
["anthropic" /* ANTHROPIC */]: void 0,
|
|
6964
6642
|
["cohere" /* COHERE */]: void 0,
|
|
6965
6643
|
["mistral" /* MISTRAL */]: void 0,
|
|
6966
6644
|
["aws" /* AWS */]: void 0,
|
|
6967
|
-
["flutch" /* FLUTCH */]: void 0,
|
|
6968
|
-
["flutch-mistral" /* FLUTCH_MISTRAL */]: void 0,
|
|
6969
|
-
["flutch-openai" /* FLUTCH_OPENAI */]: void 0,
|
|
6970
|
-
["flutch-anthropic" /* FLUTCH_ANTHROPIC */]: void 0,
|
|
6971
6645
|
["voyageai" /* VOYAGEAI */]: void 0
|
|
6972
6646
|
};
|
|
6973
6647
|
async initializeChatModel(config) {
|
|
@@ -6983,12 +6657,6 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6983
6657
|
`Model ${config.modelId} is not a chat model (type: ${modelConfig.modelType})`
|
|
6984
6658
|
);
|
|
6985
6659
|
}
|
|
6986
|
-
const creator = this.chatModelCreators[modelConfig.provider];
|
|
6987
|
-
if (!creator) {
|
|
6988
|
-
throw new Error(
|
|
6989
|
-
`Chat models not supported for provider: ${modelConfig.provider}`
|
|
6990
|
-
);
|
|
6991
|
-
}
|
|
6992
6660
|
const finalConfig = {
|
|
6993
6661
|
...modelConfig,
|
|
6994
6662
|
defaultTemperature: Number(
|
|
@@ -6999,7 +6667,27 @@ var ModelInitializer = class _ModelInitializer {
|
|
|
6999
6667
|
)
|
|
7000
6668
|
};
|
|
7001
6669
|
this.logger.debug(`Creating new chat model instance: ${cacheKey}`);
|
|
7002
|
-
|
|
6670
|
+
let model;
|
|
6671
|
+
if (finalConfig.useBedrock && finalConfig.bedrockModelId) {
|
|
6672
|
+
this.logger.debug(
|
|
6673
|
+
`Using Bedrock for model ${finalConfig.modelName}, bedrockModelId: ${finalConfig.bedrockModelId}`
|
|
6674
|
+
);
|
|
6675
|
+
model = new ChatBedrockConverse({
|
|
6676
|
+
model: finalConfig.bedrockModelId,
|
|
6677
|
+
region: this.resolveBedrockRegion(),
|
|
6678
|
+
temperature: finalConfig.defaultTemperature,
|
|
6679
|
+
maxTokens: finalConfig.defaultMaxTokens,
|
|
6680
|
+
streaming: true
|
|
6681
|
+
});
|
|
6682
|
+
} else {
|
|
6683
|
+
const creator = this.chatModelCreators[modelConfig.provider];
|
|
6684
|
+
if (!creator) {
|
|
6685
|
+
throw new Error(
|
|
6686
|
+
`Chat models not supported for provider: ${modelConfig.provider}`
|
|
6687
|
+
);
|
|
6688
|
+
}
|
|
6689
|
+
model = creator(finalConfig);
|
|
6690
|
+
}
|
|
7003
6691
|
model.metadata = {
|
|
7004
6692
|
...model.metadata,
|
|
7005
6693
|
modelId: config.modelId
|