@sedum-dev/provider-clef 0.1.0-alpha.22 → 0.1.0-alpha.23
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 +1 -6
- package/dist/index.js +26 -34
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -42,12 +42,7 @@ declare class ClefAdapter implements Resolver, Judge, ClassificationProvider, Go
|
|
|
42
42
|
verifyItems(sentence: string, items: readonly ResolverItem[], options?: ProviderCallOptions): Promise<ItemVerdict>;
|
|
43
43
|
holds(claim: string, digest: JudgePageDigest, options?: ProviderCallOptions): Promise<JudgeDecision>;
|
|
44
44
|
chooseGoal(state: GoalState, options?: ProviderCallOptions): Promise<GoalDecision>;
|
|
45
|
-
scoreRelevance(diff: string, tests: Parameters<RelevanceProvider["scoreRelevance"]>[1], options?: ProviderCallOptions): Promise<
|
|
46
|
-
probabilities: number[];
|
|
47
|
-
calls: _sedum_dev_core.ProviderCall[];
|
|
48
|
-
chunkCount: number;
|
|
49
|
-
oversized: number[];
|
|
50
|
-
}>;
|
|
45
|
+
scoreRelevance(diff: string, tests: Parameters<RelevanceProvider["scoreRelevance"]>[1], options?: ProviderCallOptions): Promise<_sedum_dev_core.RelevanceScores>;
|
|
51
46
|
classifyBatch(sentences: readonly string[], options?: ProviderCallOptions): Promise<{
|
|
52
47
|
answers: ModelClassification[];
|
|
53
48
|
calls: _sedum_dev_core.ProviderCall[];
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
backoffDelay,
|
|
10
10
|
cooldownDelay,
|
|
11
11
|
parseRetryAfter,
|
|
12
|
-
goalOperations
|
|
12
|
+
goalOperations,
|
|
13
|
+
scoreRelevancePlan
|
|
13
14
|
} from "@sedum-dev/core";
|
|
14
15
|
|
|
15
16
|
// src/protocol.ts
|
|
@@ -235,12 +236,16 @@ function buildItemsRequest(sentence, items, model = MODEL) {
|
|
|
235
236
|
|
|
236
237
|
// src/relevance.ts
|
|
237
238
|
import { buildRelevanceBatches } from "@sedum-dev/core";
|
|
239
|
+
var limits = {
|
|
240
|
+
clef: { pair: 3e4, batch: 6e4, questions: 64, minDiff: 2e3 },
|
|
241
|
+
"clef-flash": { pair: 22e3, batch: 22e3, questions: 64, minDiff: 2e3 }
|
|
242
|
+
};
|
|
238
243
|
function buildRelevanceRequests(diff, tests, model) {
|
|
239
244
|
return buildRelevanceBatches(
|
|
240
245
|
diff,
|
|
241
246
|
tests,
|
|
242
247
|
(text, questions) => ({ model, state: { diff: text }, questions }),
|
|
243
|
-
|
|
248
|
+
limits[model] ?? limits["clef-flash"]
|
|
244
249
|
);
|
|
245
250
|
}
|
|
246
251
|
|
|
@@ -799,39 +804,26 @@ var ClefAdapter = class {
|
|
|
799
804
|
}
|
|
800
805
|
}
|
|
801
806
|
async scoreRelevance(diff, tests, options) {
|
|
802
|
-
|
|
803
|
-
diff,
|
|
804
|
-
tests,
|
|
805
|
-
|
|
807
|
+
return scoreRelevancePlan(
|
|
808
|
+
buildRelevanceRequests(diff, tests, this.model),
|
|
809
|
+
tests.length,
|
|
810
|
+
async (request, indexes) => {
|
|
811
|
+
const got = await this.ask(request, options);
|
|
812
|
+
const call = this.complete(got.response, got.meta);
|
|
813
|
+
try {
|
|
814
|
+
const a = answersOf(got.response), keys = indexes.map((i) => `test${i}`);
|
|
815
|
+
if (Object.keys(a).length !== keys.length || Object.keys(a).some((k) => !keys.includes(k)))
|
|
816
|
+
throw new ProviderError4(
|
|
817
|
+
"invalid-response",
|
|
818
|
+
"Relevance answer keys do not match the tests."
|
|
819
|
+
);
|
|
820
|
+
return { call, scores: keys.map((key) => validateNoul(a[key])) };
|
|
821
|
+
} catch (error) {
|
|
822
|
+
throw responseError(error, call);
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
options
|
|
806
826
|
);
|
|
807
|
-
const probabilities = tests.map(() => 0);
|
|
808
|
-
const calls = [];
|
|
809
|
-
for (const chunk of chunks) {
|
|
810
|
-
const got = await this.ask(chunk.request, options);
|
|
811
|
-
const call = this.complete(got.response, got.meta);
|
|
812
|
-
calls.push(call);
|
|
813
|
-
try {
|
|
814
|
-
const a = answersOf(got.response), keys = chunk.indexes.map((i) => `test${i}`);
|
|
815
|
-
if (Object.keys(a).length !== keys.length || Object.keys(a).some((k) => !keys.includes(k)))
|
|
816
|
-
throw new ProviderError4(
|
|
817
|
-
"invalid-response",
|
|
818
|
-
"Relevance answer keys do not match the tests."
|
|
819
|
-
);
|
|
820
|
-
for (const i of chunk.indexes)
|
|
821
|
-
probabilities[i] = Math.max(
|
|
822
|
-
probabilities[i],
|
|
823
|
-
validateNoul(a[`test${i}`])
|
|
824
|
-
);
|
|
825
|
-
} catch (error) {
|
|
826
|
-
throw responseError(error, call);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return {
|
|
830
|
-
probabilities,
|
|
831
|
-
calls,
|
|
832
|
-
chunkCount: new Set(chunks.map((chunk) => chunk.chunkIndex)).size,
|
|
833
|
-
oversized
|
|
834
|
-
};
|
|
835
827
|
}
|
|
836
828
|
async classifyBatch(sentences, options) {
|
|
837
829
|
const answers = Array(sentences.length), calls = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sedum-dev/provider-clef",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.23",
|
|
4
4
|
"repository": "https://github.com/sedum-dev/sedum",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sedum-dev/core": "0.1.0-alpha.
|
|
22
|
+
"@sedum-dev/core": "0.1.0-alpha.23"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsup src/index.ts --format esm --dts --clean --out-dir dist",
|