ai.matey.frontend 0.2.0 → 0.3.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/CHANGELOG.md +40 -0
- package/dist/cjs/adapters/anthropic.js +156 -16
- package/dist/cjs/adapters/anthropic.js.map +1 -1
- package/dist/cjs/adapters/chrome-ai.js +58 -0
- package/dist/cjs/adapters/chrome-ai.js.map +1 -1
- package/dist/cjs/adapters/gemini.js +57 -0
- package/dist/cjs/adapters/gemini.js.map +1 -1
- package/dist/cjs/adapters/generic.js +56 -4
- package/dist/cjs/adapters/generic.js.map +1 -1
- package/dist/cjs/adapters/mistral.js +59 -0
- package/dist/cjs/adapters/mistral.js.map +1 -1
- package/dist/cjs/adapters/ollama.js +59 -0
- package/dist/cjs/adapters/ollama.js.map +1 -1
- package/dist/cjs/adapters/openai.js +199 -32
- package/dist/cjs/adapters/openai.js.map +1 -1
- package/dist/esm/adapters/anthropic.js +156 -16
- package/dist/esm/adapters/anthropic.js.map +1 -1
- package/dist/esm/adapters/chrome-ai.js +58 -0
- package/dist/esm/adapters/chrome-ai.js.map +1 -1
- package/dist/esm/adapters/gemini.js +57 -0
- package/dist/esm/adapters/gemini.js.map +1 -1
- package/dist/esm/adapters/generic.js +56 -4
- package/dist/esm/adapters/generic.js.map +1 -1
- package/dist/esm/adapters/mistral.js +59 -0
- package/dist/esm/adapters/mistral.js.map +1 -1
- package/dist/esm/adapters/ollama.js +59 -0
- package/dist/esm/adapters/ollama.js.map +1 -1
- package/dist/esm/adapters/openai.js +199 -32
- package/dist/esm/adapters/openai.js.map +1 -1
- package/dist/types/adapters/anthropic.d.ts +254 -8
- package/dist/types/adapters/anthropic.d.ts.map +1 -1
- package/dist/types/adapters/chrome-ai.d.ts +95 -0
- package/dist/types/adapters/chrome-ai.d.ts.map +1 -1
- package/dist/types/adapters/gemini.d.ts +170 -0
- package/dist/types/adapters/gemini.d.ts.map +1 -1
- package/dist/types/adapters/generic.d.ts +56 -4
- package/dist/types/adapters/generic.d.ts.map +1 -1
- package/dist/types/adapters/mistral.d.ts +143 -0
- package/dist/types/adapters/mistral.d.ts.map +1 -1
- package/dist/types/adapters/ollama.d.ts +132 -0
- package/dist/types/adapters/ollama.d.ts.map +1 -1
- package/dist/types/adapters/openai.d.ts +252 -8
- package/dist/types/adapters/openai.d.ts.map +1 -1
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvB,qEAAqE;IACrE,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAA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;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAkCpD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IA8BzD;;;;;;;;;;;;;;;;;;OAkBG;IACI,YAAY,CACjB,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,EACrC,QAAQ,CAAC,EAAE,uBAAuB,GACjC,cAAc,CAAC,MAAM,CAAC;CAS1B"}
|
|
@@ -83,17 +83,69 @@ export declare class GenericFrontendAdapter implements FrontendAdapter<IRChatReq
|
|
|
83
83
|
private readonly config;
|
|
84
84
|
constructor(config?: GenericFrontendConfig);
|
|
85
85
|
/**
|
|
86
|
-
* Pass through IR request
|
|
86
|
+
* Pass through Universal IR request without conversion.
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* This method accepts an IR request and returns it directly, as this is
|
|
89
|
+
* a passthrough adapter. When provenance tracking is enabled (default),
|
|
90
|
+
* it adds the frontend adapter name to the provenance metadata for
|
|
91
|
+
* tracking purposes, but otherwise performs no transformations.
|
|
92
|
+
*
|
|
93
|
+
* @param request - Universal IR chat request
|
|
94
|
+
* @returns Promise resolving to the same IR request (with optional provenance)
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const adapter = new GenericFrontendAdapter();
|
|
99
|
+
* const irRequest = await adapter.toIR({
|
|
100
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
101
|
+
* parameters: { model: 'gpt-4', temperature: 0.7 },
|
|
102
|
+
* metadata: { requestId: 'req_123', timestamp: Date.now(), provenance: {} }
|
|
103
|
+
* });
|
|
104
|
+
* // Returns the same request with provenance.frontend = 'generic-frontend'
|
|
105
|
+
* ```
|
|
89
106
|
*/
|
|
90
107
|
toIR(request: IRChatRequest): Promise<IRChatRequest>;
|
|
91
108
|
/**
|
|
92
|
-
* Pass through IR response
|
|
109
|
+
* Pass through Universal IR response without conversion.
|
|
110
|
+
*
|
|
111
|
+
* This method accepts an IR response and returns it directly without
|
|
112
|
+
* any transformation. Since this is a passthrough adapter, the response
|
|
113
|
+
* remains in IR format, allowing applications to work directly with
|
|
114
|
+
* the universal format.
|
|
115
|
+
*
|
|
116
|
+
* @param response - Universal IR chat response
|
|
117
|
+
* @returns Promise resolving to the same IR response
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const adapter = new GenericFrontendAdapter();
|
|
122
|
+
* const irResponse = await adapter.fromIR(irResponse);
|
|
123
|
+
* // Returns the exact same response unchanged
|
|
124
|
+
* console.log(irResponse.message.content);
|
|
125
|
+
* ```
|
|
93
126
|
*/
|
|
94
127
|
fromIR(response: IRChatResponse): Promise<IRChatResponse>;
|
|
95
128
|
/**
|
|
96
|
-
* Pass through IR stream chunks
|
|
129
|
+
* Pass through Universal IR stream chunks without conversion.
|
|
130
|
+
*
|
|
131
|
+
* This async generator method accepts an IR stream and yields each chunk
|
|
132
|
+
* directly without any transformation. Unlike other frontend adapters that
|
|
133
|
+
* convert to provider-specific formats (SSE, JSON, etc.), this maintains
|
|
134
|
+
* the raw IR chunk structure for direct consumption.
|
|
135
|
+
*
|
|
136
|
+
* @param stream - Universal IR chat stream
|
|
137
|
+
* @param _options - Optional stream conversion options (currently unused)
|
|
138
|
+
* @yields IR stream chunks unchanged
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const adapter = new GenericFrontendAdapter();
|
|
143
|
+
* for await (const chunk of adapter.fromIRStream(irStream)) {
|
|
144
|
+
* if (chunk.type === 'content') {
|
|
145
|
+
* console.log(chunk.delta); // Access IR structure directly
|
|
146
|
+
* }
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
97
149
|
*/
|
|
98
150
|
fromIRStream(stream: IRChatStream, _options?: StreamConversionOptions): AsyncGenerator<IRStreamChunk, void, undefined>;
|
|
99
151
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/adapters/generic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAMxB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,sBAAuB,YAAW,eAAe,CAC5D,aAAa,EACb,cAAc,EACd,aAAa,CACd;IACC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;gBAEnC,MAAM,GAAE,qBAA0B;IAyB9C
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/adapters/generic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,uBA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
|
@@ -8,40 +8,183 @@
|
|
|
8
8
|
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
9
9
|
import type { IRChatRequest, IRChatResponse, IRStreamChunk } from 'ai.matey.types';
|
|
10
10
|
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
11
|
+
/**
|
|
12
|
+
* Mistral message structure.
|
|
13
|
+
*
|
|
14
|
+
* Mistral uses a straightforward message format similar to OpenAI with
|
|
15
|
+
* system, user, and assistant roles. Content is always a simple string.
|
|
16
|
+
*
|
|
17
|
+
* @see MistralRequest
|
|
18
|
+
*/
|
|
11
19
|
export interface MistralMessage {
|
|
20
|
+
/** Message role: system, user, or assistant */
|
|
12
21
|
role: 'system' | 'user' | 'assistant';
|
|
22
|
+
/** Message content as plain text */
|
|
13
23
|
content: string;
|
|
14
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Mistral AI API request structure.
|
|
27
|
+
*
|
|
28
|
+
* Follows OpenAI-compatible format with some Mistral-specific features like
|
|
29
|
+
* safe_mode and random_seed. Compatible with Mistral's chat completion endpoint.
|
|
30
|
+
*
|
|
31
|
+
* @see MistralMessage
|
|
32
|
+
* @see MistralResponse
|
|
33
|
+
* @see https://docs.mistral.ai/api/
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const request: MistralRequest = {
|
|
38
|
+
* model: 'mistral-small',
|
|
39
|
+
* messages: [
|
|
40
|
+
* { role: 'user', content: 'Hello!' }
|
|
41
|
+
* ],
|
|
42
|
+
* temperature: 0.7,
|
|
43
|
+
* max_tokens: 150
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
15
47
|
export interface MistralRequest {
|
|
48
|
+
/** Model ID (e.g., 'mistral-small', 'mistral-medium', 'mistral-large') */
|
|
16
49
|
model: string;
|
|
50
|
+
/** Array of conversation messages */
|
|
17
51
|
messages: MistralMessage[];
|
|
52
|
+
/** Sampling temperature 0-1. Higher = more random */
|
|
18
53
|
temperature?: number;
|
|
54
|
+
/** Maximum tokens to generate */
|
|
19
55
|
max_tokens?: number;
|
|
56
|
+
/** Nucleus sampling parameter 0-1 */
|
|
20
57
|
top_p?: number;
|
|
58
|
+
/** Enable streaming responses */
|
|
21
59
|
stream?: boolean;
|
|
60
|
+
/** Enable Mistral's content safety filter */
|
|
22
61
|
safe_mode?: boolean;
|
|
62
|
+
/** Deterministic sampling seed */
|
|
23
63
|
random_seed?: number;
|
|
24
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Mistral AI API response structure.
|
|
67
|
+
*
|
|
68
|
+
* OpenAI-compatible response format with Mistral-specific finish reasons.
|
|
69
|
+
* Includes generated message and token usage statistics.
|
|
70
|
+
*
|
|
71
|
+
* @see MistralRequest
|
|
72
|
+
* @see MistralMessage
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const response: MistralResponse = {
|
|
77
|
+
* id: 'cmpl-123',
|
|
78
|
+
* object: 'chat.completion',
|
|
79
|
+
* created: 1677652288,
|
|
80
|
+
* model: 'mistral-small',
|
|
81
|
+
* choices: [{
|
|
82
|
+
* index: 0,
|
|
83
|
+
* message: {
|
|
84
|
+
* role: 'assistant',
|
|
85
|
+
* content: 'Hello! How can I help?'
|
|
86
|
+
* },
|
|
87
|
+
* finish_reason: 'stop'
|
|
88
|
+
* }],
|
|
89
|
+
* usage: {
|
|
90
|
+
* prompt_tokens: 10,
|
|
91
|
+
* completion_tokens: 6,
|
|
92
|
+
* total_tokens: 16
|
|
93
|
+
* }
|
|
94
|
+
* };
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
25
97
|
export interface MistralResponse {
|
|
98
|
+
/** Unique completion identifier */
|
|
26
99
|
id: string;
|
|
100
|
+
/** Object type - always 'chat.completion' */
|
|
27
101
|
object: 'chat.completion';
|
|
102
|
+
/** Unix timestamp of creation */
|
|
28
103
|
created: number;
|
|
104
|
+
/** Model used for generation */
|
|
29
105
|
model: string;
|
|
106
|
+
/** Array of completion choices (usually one) */
|
|
30
107
|
choices: Array<{
|
|
108
|
+
/** Choice index */
|
|
31
109
|
index: number;
|
|
110
|
+
/** Generated message */
|
|
32
111
|
message: MistralMessage;
|
|
112
|
+
/** Stop reason: 'stop', 'length', 'model_length', or null */
|
|
33
113
|
finish_reason: 'stop' | 'length' | 'model_length' | null;
|
|
34
114
|
}>;
|
|
115
|
+
/** Token usage statistics */
|
|
35
116
|
usage: {
|
|
117
|
+
/** Tokens in prompt */
|
|
36
118
|
prompt_tokens: number;
|
|
119
|
+
/** Tokens in completion */
|
|
37
120
|
completion_tokens: number;
|
|
121
|
+
/** Total tokens used */
|
|
38
122
|
total_tokens: number;
|
|
39
123
|
};
|
|
40
124
|
}
|
|
41
125
|
export declare class MistralFrontendAdapter implements FrontendAdapter<MistralRequest, MistralResponse> {
|
|
42
126
|
readonly metadata: AdapterMetadata;
|
|
127
|
+
/**
|
|
128
|
+
* Convert Mistral API request to Universal IR format.
|
|
129
|
+
*
|
|
130
|
+
* This method transforms a Mistral-formatted request into the standardized
|
|
131
|
+
* Intermediate Representation (IR) format. Since Mistral's format is similar
|
|
132
|
+
* to OpenAI and close to IR, this is largely a pass-through adapter with
|
|
133
|
+
* field name mapping (e.g., random_seed → seed).
|
|
134
|
+
*
|
|
135
|
+
* @param request - Mistral API request
|
|
136
|
+
* @returns Promise resolving to IR chat request
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const adapter = new MistralFrontendAdapter();
|
|
141
|
+
* const irRequest = await adapter.toIR({
|
|
142
|
+
* model: 'mistral-small',
|
|
143
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
144
|
+
* temperature: 0.7
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
43
148
|
toIR(request: MistralRequest): Promise<IRChatRequest>;
|
|
149
|
+
/**
|
|
150
|
+
* Convert Universal IR response back to Mistral API format.
|
|
151
|
+
*
|
|
152
|
+
* This method transforms the standardized IR response into the format
|
|
153
|
+
* expected by Mistral's API. It handles message conversion, finish reason
|
|
154
|
+
* mapping (stop, length, model_length), and usage statistics formatting
|
|
155
|
+
* specific to Mistral's response structure.
|
|
156
|
+
*
|
|
157
|
+
* @param response - Universal IR chat response
|
|
158
|
+
* @returns Promise resolving to Mistral API response
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const adapter = new MistralFrontendAdapter();
|
|
163
|
+
* const mistralResponse = await adapter.fromIR(irResponse);
|
|
164
|
+
* console.log(mistralResponse.choices[0].message.content);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
44
167
|
fromIR(response: IRChatResponse): Promise<MistralResponse>;
|
|
168
|
+
/**
|
|
169
|
+
* Convert Universal IR stream to Mistral Server-Sent Events format.
|
|
170
|
+
*
|
|
171
|
+
* This async generator method transforms a stream of IR chunks into
|
|
172
|
+
* Mistral-formatted SSE responses. It yields Server-Sent Event strings
|
|
173
|
+
* with the "data: " prefix containing JSON with delta content, and
|
|
174
|
+
* emits "data: [DONE]" when the stream completes.
|
|
175
|
+
*
|
|
176
|
+
* @param stream - Universal IR chat stream
|
|
177
|
+
* @param _options - Optional stream conversion options (currently unused)
|
|
178
|
+
* @yields Server-Sent Event formatted strings
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const adapter = new MistralFrontendAdapter();
|
|
183
|
+
* for await (const sseData of adapter.fromIRStream(irStream)) {
|
|
184
|
+
* console.log(sseData); // "data: {...}\n\n" or "data: [DONE]\n\n"
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
45
188
|
fromIRStream(stream: AsyncGenerator<IRStreamChunk>, _options?: StreamConversionOptions): AsyncGenerator<string>;
|
|
46
189
|
}
|
|
47
190
|
//# sourceMappingURL=mistral.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../../src/adapters/mistral.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAG9D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../../src/adapters/mistral.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAG9D;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IAEtC,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IAEd,qCAAqC;IACrC,QAAQ,EAAE,cAAc,EAAE,CAAC;IAE3B,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,iCAAiC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,6CAA6C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AM,CAAC;CAS1B"}
|
|
@@ -9,36 +9,168 @@
|
|
|
9
9
|
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
10
10
|
import type { IRChatRequest, IRChatResponse, IRStreamChunk } from 'ai.matey.types';
|
|
11
11
|
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
12
|
+
/**
|
|
13
|
+
* Ollama message structure.
|
|
14
|
+
*
|
|
15
|
+
* Simple message format for local Ollama models with standard roles.
|
|
16
|
+
*
|
|
17
|
+
* @see OllamaRequest
|
|
18
|
+
*/
|
|
12
19
|
export interface OllamaMessage {
|
|
20
|
+
/** Message role */
|
|
13
21
|
role: 'system' | 'user' | 'assistant';
|
|
22
|
+
/** Message content */
|
|
14
23
|
content: string;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Ollama API request structure for local models.
|
|
27
|
+
*
|
|
28
|
+
* Ollama provides a local server for running LLMs. Parameters are nested
|
|
29
|
+
* in an `options` object, and uses `num_predict` instead of `max_tokens`.
|
|
30
|
+
*
|
|
31
|
+
* @see OllamaMessage
|
|
32
|
+
* @see OllamaResponse
|
|
33
|
+
* @see https://github.com/ollama/ollama/blob/main/docs/api.md
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const request: OllamaRequest = {
|
|
38
|
+
* model: 'llama2',
|
|
39
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
40
|
+
* options: {
|
|
41
|
+
* temperature: 0.7,
|
|
42
|
+
* num_predict: 100
|
|
43
|
+
* }
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
16
47
|
export interface OllamaRequest {
|
|
48
|
+
/** Local model name (e.g., 'llama2', 'mistral', 'codellama') */
|
|
17
49
|
model: string;
|
|
50
|
+
/** Conversation messages */
|
|
18
51
|
messages: OllamaMessage[];
|
|
52
|
+
/** Model parameters nested in options object */
|
|
19
53
|
options?: {
|
|
54
|
+
/** Sampling temperature */
|
|
20
55
|
temperature?: number;
|
|
56
|
+
/** Nucleus sampling */
|
|
21
57
|
top_p?: number;
|
|
58
|
+
/** Top-K sampling */
|
|
22
59
|
top_k?: number;
|
|
60
|
+
/** Maximum tokens to predict (Ollama uses 'predict' not 'tokens') */
|
|
23
61
|
num_predict?: number;
|
|
62
|
+
/** Stop sequences */
|
|
24
63
|
stop?: string[];
|
|
25
64
|
};
|
|
65
|
+
/** Enable streaming responses */
|
|
26
66
|
stream?: boolean;
|
|
27
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Ollama API response structure.
|
|
70
|
+
*
|
|
71
|
+
* Includes the generated message plus performance metrics like duration
|
|
72
|
+
* and token counts specific to local model execution.
|
|
73
|
+
*
|
|
74
|
+
* @see OllamaRequest
|
|
75
|
+
* @see OllamaMessage
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const response: OllamaResponse = {
|
|
80
|
+
* model: 'llama2',
|
|
81
|
+
* created_at: '2024-01-15T12:00:00Z',
|
|
82
|
+
* message: {
|
|
83
|
+
* role: 'assistant',
|
|
84
|
+
* content: 'Hello! How can I help?'
|
|
85
|
+
* },
|
|
86
|
+
* done: true,
|
|
87
|
+
* total_duration: 1500000000,
|
|
88
|
+
* prompt_eval_count: 10,
|
|
89
|
+
* eval_count: 6
|
|
90
|
+
* };
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
28
93
|
export interface OllamaResponse {
|
|
94
|
+
/** Model that generated the response */
|
|
29
95
|
model: string;
|
|
96
|
+
/** ISO 8601 timestamp */
|
|
30
97
|
created_at: string;
|
|
98
|
+
/** Generated message */
|
|
31
99
|
message: OllamaMessage;
|
|
100
|
+
/** Whether generation is complete */
|
|
32
101
|
done: boolean;
|
|
102
|
+
/** Total inference duration in nanoseconds */
|
|
33
103
|
total_duration?: number;
|
|
104
|
+
/** Model loading duration in nanoseconds */
|
|
34
105
|
load_duration?: number;
|
|
106
|
+
/** Number of tokens in prompt evaluation */
|
|
35
107
|
prompt_eval_count?: number;
|
|
108
|
+
/** Number of tokens in generation */
|
|
36
109
|
eval_count?: number;
|
|
37
110
|
}
|
|
38
111
|
export declare class OllamaFrontendAdapter implements FrontendAdapter<OllamaRequest, OllamaResponse> {
|
|
39
112
|
readonly metadata: AdapterMetadata;
|
|
113
|
+
/**
|
|
114
|
+
* Convert Ollama API request to Universal IR format.
|
|
115
|
+
*
|
|
116
|
+
* This method transforms an Ollama-formatted request into the standardized
|
|
117
|
+
* Intermediate Representation (IR) format. It handles Ollama's unique
|
|
118
|
+
* structure where parameters are nested in an `options` object, and maps
|
|
119
|
+
* Ollama-specific field names (e.g., num_predict → maxTokens).
|
|
120
|
+
*
|
|
121
|
+
* @param request - Ollama API request
|
|
122
|
+
* @returns Promise resolving to IR chat request
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const adapter = new OllamaFrontendAdapter();
|
|
127
|
+
* const irRequest = await adapter.toIR({
|
|
128
|
+
* model: 'llama2',
|
|
129
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
130
|
+
* options: { temperature: 0.7, num_predict: 100 }
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
40
134
|
toIR(request: OllamaRequest): Promise<IRChatRequest>;
|
|
135
|
+
/**
|
|
136
|
+
* Convert Universal IR response back to Ollama API format.
|
|
137
|
+
*
|
|
138
|
+
* This method transforms the standardized IR response into the format
|
|
139
|
+
* expected by Ollama's API. It handles message conversion, formats the
|
|
140
|
+
* timestamp as ISO string, and maps usage statistics to Ollama's format
|
|
141
|
+
* (prompt_eval_count and eval_count instead of token counts).
|
|
142
|
+
*
|
|
143
|
+
* @param response - Universal IR chat response
|
|
144
|
+
* @returns Promise resolving to Ollama API response
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const adapter = new OllamaFrontendAdapter();
|
|
149
|
+
* const ollamaResponse = await adapter.fromIR(irResponse);
|
|
150
|
+
* console.log(ollamaResponse.message.content);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
41
153
|
fromIR(response: IRChatResponse): Promise<OllamaResponse>;
|
|
154
|
+
/**
|
|
155
|
+
* Convert Universal IR stream to Ollama streaming format.
|
|
156
|
+
*
|
|
157
|
+
* This async generator method transforms a stream of IR chunks into
|
|
158
|
+
* Ollama-formatted responses. It yields newline-delimited JSON objects
|
|
159
|
+
* (not SSE format) with each chunk containing a message and done flag,
|
|
160
|
+
* emitting `done: true` when the stream completes.
|
|
161
|
+
*
|
|
162
|
+
* @param stream - Universal IR chat stream
|
|
163
|
+
* @param _options - Optional stream conversion options (currently unused)
|
|
164
|
+
* @yields Newline-delimited JSON strings
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const adapter = new OllamaFrontendAdapter();
|
|
169
|
+
* for await (const jsonLine of adapter.fromIRStream(irStream)) {
|
|
170
|
+
* console.log(jsonLine); // '{"message":{"content":"text"},"done":false}\n'
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
42
174
|
fromIRStream(stream: AsyncGenerator<IRStreamChunk>, _options?: StreamConversionOptions): AsyncGenerator<string>;
|
|
43
175
|
}
|
|
44
176
|
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/adapters/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAA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