@euconform/core 1.0.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/.turbo/turbo-build.log +4 -0
- package/LICENSE +21 -0
- package/dist/fairness-metrics.d.ts +65 -0
- package/dist/fairness-metrics.d.ts.map +1 -0
- package/dist/fairness-metrics.js +394 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/inference/browser-inference.d.ts +60 -0
- package/dist/inference/browser-inference.d.ts.map +1 -0
- package/dist/inference/browser-inference.js +221 -0
- package/dist/inference/capability-detection.d.ts +183 -0
- package/dist/inference/capability-detection.d.ts.map +1 -0
- package/dist/inference/capability-detection.js +552 -0
- package/dist/inference/index.d.ts +43 -0
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/index.js +97 -0
- package/dist/inference/inference-factory.d.ts +73 -0
- package/dist/inference/inference-factory.d.ts.map +1 -0
- package/dist/inference/inference-factory.js +175 -0
- package/dist/inference/ollama-client.d.ts +114 -0
- package/dist/inference/ollama-client.d.ts.map +1 -0
- package/dist/inference/ollama-client.js +386 -0
- package/dist/legal-checks/annex-iv-report.d.ts +131 -0
- package/dist/legal-checks/annex-iv-report.d.ts.map +1 -0
- package/dist/legal-checks/annex-iv-report.js +62 -0
- package/dist/legal-checks/bias-metrics.d.ts +162 -0
- package/dist/legal-checks/bias-metrics.d.ts.map +1 -0
- package/dist/legal-checks/bias-metrics.js +408 -0
- package/dist/legal-checks/data-governance.d.ts +30 -0
- package/dist/legal-checks/data-governance.d.ts.map +1 -0
- package/dist/legal-checks/data-governance.js +99 -0
- package/dist/legal-checks/human-oversight-logging.d.ts +27 -0
- package/dist/legal-checks/human-oversight-logging.d.ts.map +1 -0
- package/dist/legal-checks/human-oversight-logging.js +106 -0
- package/dist/legal-checks/index.d.ts +13 -0
- package/dist/legal-checks/index.d.ts.map +1 -0
- package/dist/legal-checks/index.js +6 -0
- package/dist/legal-checks/risk-classifier.d.ts +35 -0
- package/dist/legal-checks/risk-classifier.d.ts.map +1 -0
- package/dist/legal-checks/risk-classifier.js +234 -0
- package/dist/legal-checks/robustness-transparency.d.ts +45 -0
- package/dist/legal-checks/robustness-transparency.d.ts.map +1 -0
- package/dist/legal-checks/robustness-transparency.js +111 -0
- package/dist/metrics/crows-pairs-bias.d.ts +41 -0
- package/dist/metrics/crows-pairs-bias.d.ts.map +1 -0
- package/dist/metrics/crows-pairs-bias.js +172 -0
- package/dist/metrics/index.d.ts +6 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +5 -0
- package/dist/metrics/stereotype-bias.d.ts +89 -0
- package/dist/metrics/stereotype-bias.d.ts.map +1 -0
- package/dist/metrics/stereotype-bias.js +157 -0
- package/dist/risk-engine.d.ts +23 -0
- package/dist/risk-engine.d.ts.map +1 -0
- package/dist/risk-engine.js +451 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/package.json +28 -0
- package/src/fairness-metrics.ts +498 -0
- package/src/index.ts +150 -0
- package/src/inference/browser-inference.ts +258 -0
- package/src/inference/capability-detection.ts +714 -0
- package/src/inference/index.ts +156 -0
- package/src/inference/inference-factory.ts +222 -0
- package/src/inference/ollama-client.ts +514 -0
- package/src/inference/transformers.d.ts +62 -0
- package/src/legal-checks/annex-iv-report.ts +157 -0
- package/src/legal-checks/bias-metrics.ts +590 -0
- package/src/legal-checks/data-governance.ts +148 -0
- package/src/legal-checks/human-oversight-logging.ts +135 -0
- package/src/legal-checks/index.ts +55 -0
- package/src/legal-checks/risk-classifier.ts +285 -0
- package/src/legal-checks/robustness-transparency.ts +162 -0
- package/src/metrics/crows-pairs-bias.ts +245 -0
- package/src/metrics/index.ts +22 -0
- package/src/metrics/stereotype-bias.ts +267 -0
- package/src/risk-engine.ts +525 -0
- package/src/types.ts +154 -0
- package/tests/annex-iv-report.test.ts +323 -0
- package/tests/crows-pairs-bias.test.ts +342 -0
- package/tests/fairness-metrics.test.ts +187 -0
- package/tests/integration/bias-calculation.integration.test.ts +688 -0
- package/tests/legal-checks.test.ts +53 -0
- package/tests/ollama-client.test.ts +427 -0
- package/tests/risk-engine.test.ts +149 -0
- package/tsconfig.json +11 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference Factory with Method Detection
|
|
3
|
+
* Provides unified interface for bias calculations across engines with automatic method detection
|
|
4
|
+
*/
|
|
5
|
+
import type { BiasCalculationMethod, BiasTestConfig, CrowsPairsBiasResult } from "../types";
|
|
6
|
+
import { BrowserInference } from "./browser-inference";
|
|
7
|
+
import type { ModelCapability } from "./capability-detection";
|
|
8
|
+
import { OllamaClient } from "./ollama-client";
|
|
9
|
+
/**
|
|
10
|
+
* Result wrapper that includes method metadata for all inference operations
|
|
11
|
+
*/
|
|
12
|
+
export interface InferenceResult<T> {
|
|
13
|
+
data: T;
|
|
14
|
+
method: BiasCalculationMethod;
|
|
15
|
+
engine: "browser" | "ollama";
|
|
16
|
+
model: string;
|
|
17
|
+
capability?: ModelCapability;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Inference Factory class that manages inference clients and provides unified interface
|
|
21
|
+
* Automatically detects best available calculation method and returns metadata
|
|
22
|
+
*/
|
|
23
|
+
export declare class InferenceFactory {
|
|
24
|
+
private browserClient;
|
|
25
|
+
private ollamaClient;
|
|
26
|
+
private statusCallback;
|
|
27
|
+
private selectedCapability;
|
|
28
|
+
constructor(statusCallback?: (status: string) => void);
|
|
29
|
+
/**
|
|
30
|
+
* Set the selected model capability for enhanced metadata tracking
|
|
31
|
+
*/
|
|
32
|
+
setSelectedCapability(capability: ModelCapability): void;
|
|
33
|
+
/**
|
|
34
|
+
* Create a bias calculation with automatic method detection
|
|
35
|
+
* Returns InferenceResult with both data and method metadata
|
|
36
|
+
*/
|
|
37
|
+
createBiasCalculation(config: BiasTestConfig): Promise<InferenceResult<CrowsPairsBiasResult>>;
|
|
38
|
+
/**
|
|
39
|
+
* Detect the best available calculation method for the given client
|
|
40
|
+
* Returns the method that should be used for bias calculations
|
|
41
|
+
*/
|
|
42
|
+
private detectBestMethod;
|
|
43
|
+
/**
|
|
44
|
+
* Get browser inference client (creates if needed)
|
|
45
|
+
*/
|
|
46
|
+
getBrowserClient(model: string): BrowserInference;
|
|
47
|
+
/**
|
|
48
|
+
* Get Ollama client (creates if needed)
|
|
49
|
+
*/
|
|
50
|
+
getOllamaClient(model: string): OllamaClient;
|
|
51
|
+
private validateConfiguration;
|
|
52
|
+
private getInferenceClient;
|
|
53
|
+
/**
|
|
54
|
+
* Create inference result wrapper for any data with method detection
|
|
55
|
+
* Useful for wrapping existing inference operations with metadata
|
|
56
|
+
*/
|
|
57
|
+
createInferenceResult<T>(data: T, engine: "browser" | "ollama", model: string, client?: BrowserInference | OllamaClient): Promise<InferenceResult<T>>;
|
|
58
|
+
/**
|
|
59
|
+
* Cleanup resources
|
|
60
|
+
*/
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a global inference factory instance
|
|
65
|
+
* Provides convenient access to factory methods
|
|
66
|
+
*/
|
|
67
|
+
export declare function createInferenceFactory(statusCallback?: (status: string) => void): InferenceFactory;
|
|
68
|
+
/**
|
|
69
|
+
* Utility function to detect best method for a given configuration
|
|
70
|
+
* Useful for pre-flight checks without creating full factory
|
|
71
|
+
*/
|
|
72
|
+
export declare function detectBestMethodForConfig(config: BiasTestConfig): Promise<BiasCalculationMethod>;
|
|
73
|
+
//# sourceMappingURL=inference-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-factory.d.ts","sourceRoot":"","sources":["../../src/inference/inference-factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAC5F,O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;CAMhB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACxC,gBAAgB,CAElB;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,qBAAqB,CAAC,CAYhC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference Factory with Method Detection
|
|
3
|
+
* Provides unified interface for bias calculations across engines with automatic method detection
|
|
4
|
+
*/
|
|
5
|
+
import { calculateCrowsPairsBias } from "../metrics/crows-pairs-bias";
|
|
6
|
+
import { BrowserInference } from "./browser-inference";
|
|
7
|
+
import { OllamaClient } from "./ollama-client";
|
|
8
|
+
/**
|
|
9
|
+
* Inference Factory class that manages inference clients and provides unified interface
|
|
10
|
+
* Automatically detects best available calculation method and returns metadata
|
|
11
|
+
*/
|
|
12
|
+
export class InferenceFactory {
|
|
13
|
+
browserClient = null;
|
|
14
|
+
ollamaClient = null;
|
|
15
|
+
statusCallback = null;
|
|
16
|
+
selectedCapability = null;
|
|
17
|
+
constructor(statusCallback) {
|
|
18
|
+
this.statusCallback = statusCallback || null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set the selected model capability for enhanced metadata tracking
|
|
22
|
+
*/
|
|
23
|
+
setSelectedCapability(capability) {
|
|
24
|
+
this.selectedCapability = capability;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a bias calculation with automatic method detection
|
|
28
|
+
* Returns InferenceResult with both data and method metadata
|
|
29
|
+
*/
|
|
30
|
+
async createBiasCalculation(config) {
|
|
31
|
+
const { engine, model } = config;
|
|
32
|
+
this.validateConfiguration(config);
|
|
33
|
+
const inferenceClient = await this.getInferenceClient(engine, model);
|
|
34
|
+
let _detectedMethod;
|
|
35
|
+
if (engine === "browser") {
|
|
36
|
+
_detectedMethod = "logprobs_exact";
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Use capability method if available, otherwise detect
|
|
40
|
+
_detectedMethod =
|
|
41
|
+
this.selectedCapability?.method ?? (await this.detectBestMethod(inferenceClient));
|
|
42
|
+
}
|
|
43
|
+
// Perform bias calculation
|
|
44
|
+
const biasResult = await calculateCrowsPairsBias(config, inferenceClient);
|
|
45
|
+
// Return result with metadata including capability information
|
|
46
|
+
return {
|
|
47
|
+
data: biasResult,
|
|
48
|
+
method: biasResult.method, // Use the method determined during calculation
|
|
49
|
+
engine,
|
|
50
|
+
model,
|
|
51
|
+
capability: this.selectedCapability || undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Detect the best available calculation method for the given client
|
|
56
|
+
* Returns the method that should be used for bias calculations
|
|
57
|
+
*/
|
|
58
|
+
async detectBestMethod(client) {
|
|
59
|
+
if (client instanceof BrowserInference) {
|
|
60
|
+
// Browser inference always supports exact log-probabilities
|
|
61
|
+
return "logprobs_exact";
|
|
62
|
+
}
|
|
63
|
+
if (client instanceof OllamaClient) {
|
|
64
|
+
// Check Ollama's log-probability support
|
|
65
|
+
const supportsLogProbs = await client.detectLogProbSupport();
|
|
66
|
+
return supportsLogProbs ? "logprobs_exact" : "logprobs_fallback_latency";
|
|
67
|
+
}
|
|
68
|
+
throw new Error("Unknown inference client type");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get browser inference client (creates if needed)
|
|
72
|
+
*/
|
|
73
|
+
getBrowserClient(model) {
|
|
74
|
+
if (!this.browserClient || this.browserClient.modelId !== model) {
|
|
75
|
+
this.browserClient = new BrowserInference(model, this.statusCallback);
|
|
76
|
+
}
|
|
77
|
+
return this.browserClient;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get Ollama client (creates if needed)
|
|
81
|
+
*/
|
|
82
|
+
getOllamaClient(model) {
|
|
83
|
+
if (!this.ollamaClient || this.ollamaClient.model !== model) {
|
|
84
|
+
this.ollamaClient = new OllamaClient(model);
|
|
85
|
+
}
|
|
86
|
+
return this.ollamaClient;
|
|
87
|
+
}
|
|
88
|
+
validateConfiguration(config) {
|
|
89
|
+
const { engine, model } = config;
|
|
90
|
+
if (!this.selectedCapability)
|
|
91
|
+
return;
|
|
92
|
+
if (this.selectedCapability.status !== "available") {
|
|
93
|
+
throw new Error(`Selected model ${model} is not available (status: ${this.selectedCapability.status})`);
|
|
94
|
+
}
|
|
95
|
+
if (this.selectedCapability.modelId !== model || this.selectedCapability.engine !== engine) {
|
|
96
|
+
throw new Error(`Configuration mismatch: expected ${this.selectedCapability.modelId} (${this.selectedCapability.engine}), got ${model} (${engine})`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async getInferenceClient(engine, model) {
|
|
100
|
+
if (engine === "browser") {
|
|
101
|
+
return this.getBrowserClient(model);
|
|
102
|
+
}
|
|
103
|
+
if (engine === "ollama") {
|
|
104
|
+
return this.getOllamaClient(model);
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Unsupported engine: ${engine}`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create inference result wrapper for any data with method detection
|
|
110
|
+
* Useful for wrapping existing inference operations with metadata
|
|
111
|
+
*/
|
|
112
|
+
async createInferenceResult(data, engine, model, client) {
|
|
113
|
+
let method;
|
|
114
|
+
// Use capability method if available, otherwise detect
|
|
115
|
+
const selectedMethod = this.selectedCapability?.method;
|
|
116
|
+
if (selectedMethod) {
|
|
117
|
+
method = selectedMethod;
|
|
118
|
+
}
|
|
119
|
+
else if (engine === "browser") {
|
|
120
|
+
method = "logprobs_exact";
|
|
121
|
+
}
|
|
122
|
+
else if (engine === "ollama") {
|
|
123
|
+
if (client instanceof OllamaClient) {
|
|
124
|
+
method = await this.detectBestMethod(client);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Create temporary client for method detection
|
|
128
|
+
const tempClient = new OllamaClient(model);
|
|
129
|
+
method = await this.detectBestMethod(tempClient);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new Error(`Unsupported engine: ${engine}`);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
data,
|
|
137
|
+
method,
|
|
138
|
+
engine,
|
|
139
|
+
model,
|
|
140
|
+
capability: this.selectedCapability || undefined,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Cleanup resources
|
|
145
|
+
*/
|
|
146
|
+
dispose() {
|
|
147
|
+
this.browserClient = null;
|
|
148
|
+
this.ollamaClient = null;
|
|
149
|
+
this.statusCallback = null;
|
|
150
|
+
this.selectedCapability = null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a global inference factory instance
|
|
155
|
+
* Provides convenient access to factory methods
|
|
156
|
+
*/
|
|
157
|
+
export function createInferenceFactory(statusCallback) {
|
|
158
|
+
return new InferenceFactory(statusCallback);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Utility function to detect best method for a given configuration
|
|
162
|
+
* Useful for pre-flight checks without creating full factory
|
|
163
|
+
*/
|
|
164
|
+
export async function detectBestMethodForConfig(config) {
|
|
165
|
+
const { engine, model } = config;
|
|
166
|
+
if (engine === "browser") {
|
|
167
|
+
return "logprobs_exact";
|
|
168
|
+
}
|
|
169
|
+
if (engine === "ollama") {
|
|
170
|
+
const client = new OllamaClient(model);
|
|
171
|
+
const supportsLogProbs = await client.detectLogProbSupport();
|
|
172
|
+
return supportsLogProbs ? "logprobs_exact" : "logprobs_fallback_latency";
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`Unsupported engine: ${engine}`);
|
|
175
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama Client for local LLM inference
|
|
3
|
+
* Connects to Ollama running on localhost:11434
|
|
4
|
+
*/
|
|
5
|
+
import type { BiasCalculationMethod } from "../types";
|
|
6
|
+
export interface OllamaModel {
|
|
7
|
+
name: string;
|
|
8
|
+
size: number;
|
|
9
|
+
digest: string;
|
|
10
|
+
modified_at: string;
|
|
11
|
+
}
|
|
12
|
+
export interface OllamaGenerateOptions {
|
|
13
|
+
model: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
stream?: boolean;
|
|
16
|
+
logprobs?: boolean | number;
|
|
17
|
+
options?: {
|
|
18
|
+
temperature?: number;
|
|
19
|
+
top_p?: number;
|
|
20
|
+
num_predict?: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface OllamaGenerateResponse {
|
|
24
|
+
model: string;
|
|
25
|
+
response: string;
|
|
26
|
+
done: boolean;
|
|
27
|
+
context?: number[];
|
|
28
|
+
total_duration?: number;
|
|
29
|
+
eval_count?: number;
|
|
30
|
+
logprobs?: Array<{
|
|
31
|
+
token: string;
|
|
32
|
+
logprob: number;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export interface OllamaLogProbResponse {
|
|
36
|
+
model: string;
|
|
37
|
+
prompt: string;
|
|
38
|
+
logprob: number;
|
|
39
|
+
}
|
|
40
|
+
export interface OllamaLogProbsOptions {
|
|
41
|
+
logprobs?: boolean | number;
|
|
42
|
+
}
|
|
43
|
+
export interface OllamaLogProbsResponse extends OllamaGenerateResponse {
|
|
44
|
+
logprobs?: Array<{
|
|
45
|
+
token: string;
|
|
46
|
+
logprob: number;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if Ollama is running and accessible
|
|
51
|
+
*/
|
|
52
|
+
export declare function detectOllama(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Get list of available models from Ollama
|
|
55
|
+
*/
|
|
56
|
+
export declare function listOllamaModels(): Promise<OllamaModel[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Generate text with Ollama
|
|
59
|
+
*/
|
|
60
|
+
export declare function ollamaGenerate(options: OllamaGenerateOptions): Promise<OllamaGenerateResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Get log probability for a prompt (for bias scoring)
|
|
63
|
+
* Uses the /api/generate endpoint with num_predict: 0 to get prompt logprobs
|
|
64
|
+
*/
|
|
65
|
+
export declare function getLogProb(model: string, prompt: string): Promise<number>;
|
|
66
|
+
/**
|
|
67
|
+
* Calculate perplexity for a text (alternative bias metric)
|
|
68
|
+
*/
|
|
69
|
+
export declare function getPerplexity(model: string, text: string): Promise<number>;
|
|
70
|
+
/**
|
|
71
|
+
* Ollama client class for stateful operations
|
|
72
|
+
*/
|
|
73
|
+
export declare class OllamaClient {
|
|
74
|
+
private baseUrl;
|
|
75
|
+
readonly model: string;
|
|
76
|
+
private capabilityCache;
|
|
77
|
+
constructor(model: string, baseUrl?: string);
|
|
78
|
+
/**
|
|
79
|
+
* Ensures the model is available in Ollama before proceeding
|
|
80
|
+
* Throws an error if the model is not found
|
|
81
|
+
*/
|
|
82
|
+
ensureModelLoaded(): Promise<void>;
|
|
83
|
+
isAvailable(): Promise<boolean>;
|
|
84
|
+
generate(prompt: string): Promise<string>;
|
|
85
|
+
getLogProb(prompt: string): Promise<number>;
|
|
86
|
+
getPerplexity(text: string): Promise<number>;
|
|
87
|
+
/**
|
|
88
|
+
* Test if the current model supports log-probabilities
|
|
89
|
+
* Sends a test request with "Der" prompt to detect capability
|
|
90
|
+
*/
|
|
91
|
+
private testLogProbCapability;
|
|
92
|
+
/**
|
|
93
|
+
* Get cached capability result from localStorage
|
|
94
|
+
*/
|
|
95
|
+
private getCachedCapability;
|
|
96
|
+
/**
|
|
97
|
+
* Cache capability result in localStorage
|
|
98
|
+
*/
|
|
99
|
+
private setCachedCapability;
|
|
100
|
+
/**
|
|
101
|
+
* Detect if the current model supports log-probabilities
|
|
102
|
+
* Checks cache first, then runs test if needed
|
|
103
|
+
*/
|
|
104
|
+
detectLogProbSupport(): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Get log-probability with automatic fallback to latency method
|
|
107
|
+
* Returns both the calculated value and the method used
|
|
108
|
+
*/
|
|
109
|
+
getLogProbWithFallback(prompt: string): Promise<{
|
|
110
|
+
logprob: number;
|
|
111
|
+
method: BiasCalculationMethod;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=ollama-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama-client.d.ts","sourceRoot":"","sources":["../../src/inference/ollama-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,UAAU,CAAC;AAE5E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;I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