@chainfuse/ai-tools 0.12.1 → 0.12.3
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.
|
@@ -97,7 +97,7 @@ export class AiCustomProviders extends AiBase {
|
|
|
97
97
|
textEmbeddingModels: await server.textEmbeddingModelAvailability.reduce(async (accPromise, model) => {
|
|
98
98
|
const acc = await accPromise;
|
|
99
99
|
// @ts-expect-error override for types
|
|
100
|
-
acc[model] = (await raw.azOpenai(args, server)).textEmbeddingModel(model);
|
|
100
|
+
acc[model.name] = (await raw.azOpenai(args, server)).textEmbeddingModel(model.name);
|
|
101
101
|
return acc;
|
|
102
102
|
}, Promise.resolve({})),
|
|
103
103
|
// An optional fallback provider to use when a requested model is not found in the custom provider.
|
|
@@ -4,32 +4,38 @@ export class AiRawProviders extends AiBase {
|
|
|
4
4
|
// 2628288 seconds is what cf defines as 1 month in their cache rules
|
|
5
5
|
cacheTtl = 2628288;
|
|
6
6
|
async updateGatewayLog(response, metadataHeader, startRoundTrip, modelTime) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
const logId = response.headers.get('cf-aig-log-id');
|
|
8
|
+
if (logId) {
|
|
9
|
+
const updateMetadata = import('@chainfuse/helpers')
|
|
10
|
+
.then(({ NetHelpers }) => NetHelpers.cfApi(this.config.gateway.apiToken))
|
|
11
|
+
.then((cf) => cf.aiGateway.logs.edit(this.gatewayName, logId, {
|
|
12
|
+
account_id: this.config.gateway.accountId,
|
|
13
|
+
metadata: {
|
|
14
|
+
...Object.entries({
|
|
15
|
+
...metadataHeader,
|
|
16
|
+
serverInfo: {
|
|
17
|
+
...JSON.parse(metadataHeader.serverInfo),
|
|
18
|
+
timing: {
|
|
19
|
+
fromCache: response.headers.get('cf-aig-cache-status')?.toLowerCase() === 'hit',
|
|
20
|
+
totalRoundtripTime: performance.now() - startRoundTrip,
|
|
21
|
+
modelTime,
|
|
22
|
+
},
|
|
20
23
|
},
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
}).reduce((acc, [key, value]) => {
|
|
25
|
+
acc[key] = typeof value === 'string' ? value : JSON.stringify(value);
|
|
26
|
+
return acc;
|
|
27
|
+
}, {}),
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
if (this.config.backgroundContext) {
|
|
31
|
+
this.config.backgroundContext.waitUntil(updateMetadata);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await updateMetadata;
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
else {
|
|
32
|
-
|
|
38
|
+
console.warn('Not updating gateway log, no cf-aig-log-id header');
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
oaiOpenai(args) {
|
package/dist/serverSelector.mjs
CHANGED
|
@@ -115,7 +115,7 @@ export class ServerSelector extends AiBase {
|
|
|
115
115
|
}
|
|
116
116
|
// Skip over the rest of logic if the server can't handle the incoming request
|
|
117
117
|
// @ts-expect-error it's always strings, just sometimes string literals
|
|
118
|
-
const featureFilteredServers = requiredCapability ? servers.filter((server) => server.languageModelAvailability.includes(requiredCapability) || server.textEmbeddingModelAvailability.includes(requiredCapability)) : servers;
|
|
118
|
+
const featureFilteredServers = requiredCapability ? servers.filter((server) => server.languageModelAvailability.map((model) => model.name).includes(requiredCapability) || server.textEmbeddingModelAvailability.map((model) => model.name).includes(requiredCapability)) : servers;
|
|
119
119
|
if (featureFilteredServers.length > 0) {
|
|
120
120
|
// Skip over servers not in the save privacy region except if undefined, then you can use any
|
|
121
121
|
const privacyRegionFilteredServers = featureFilteredServers.filter((server) => privacyRegion.length === 0 || ('privacyRegion' in server && privacyRegion.includes(server.privacyRegion)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/ai-tools",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "ChainFuse",
|
|
6
6
|
"homepage": "https://github.com/ChainFuse/packages/tree/main/packages/ai-tools#readme",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"@ai-sdk/azure": "^1.3.6",
|
|
53
53
|
"@ai-sdk/google": "^1.2.5",
|
|
54
54
|
"@ai-sdk/openai": "^1.0.5",
|
|
55
|
-
"@ai-sdk/openai-compatible": "^0.2.
|
|
56
|
-
"@chainfuse/helpers": "^2.2.
|
|
57
|
-
"@chainfuse/types": "^2.
|
|
55
|
+
"@ai-sdk/openai-compatible": "^0.2.5",
|
|
56
|
+
"@chainfuse/helpers": "^2.2.4",
|
|
57
|
+
"@chainfuse/types": "^2.4.0",
|
|
58
58
|
"ai": "^4.2.10",
|
|
59
59
|
"chalk": "^5.4.1",
|
|
60
60
|
"haversine-distance": "^1.2.3",
|
|
61
|
-
"workers-ai-provider": "^0.
|
|
61
|
+
"workers-ai-provider": "^0.3.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@cloudflare/workers-types": "^4.
|
|
65
|
-
"openai": "^4.91.
|
|
64
|
+
"@cloudflare/workers-types": "^4.20250402.0",
|
|
65
|
+
"openai": "^4.91.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "03a624d8b16b8043fdd51595a2f293aaf3017f51"
|
|
68
68
|
}
|