@llumiverse/drivers 0.8.4 → 0.9.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.
Files changed (34) hide show
  1. package/lib/cjs/index.js +3 -2
  2. package/lib/cjs/index.js.map +1 -1
  3. package/lib/cjs/mistral/index.js +147 -0
  4. package/lib/cjs/mistral/index.js.map +1 -0
  5. package/lib/cjs/mistral/types.js +83 -0
  6. package/lib/cjs/mistral/types.js.map +1 -0
  7. package/lib/cjs/togetherai/index.js +5 -14
  8. package/lib/cjs/togetherai/index.js.map +1 -1
  9. package/lib/cjs/vertexai/models/palm-model-base.js +6 -14
  10. package/lib/cjs/vertexai/models/palm-model-base.js.map +1 -1
  11. package/lib/esm/index.js +3 -2
  12. package/lib/esm/index.js.map +1 -1
  13. package/lib/esm/mistral/index.js +143 -0
  14. package/lib/esm/mistral/index.js.map +1 -0
  15. package/lib/esm/mistral/types.js +80 -0
  16. package/lib/esm/mistral/types.js.map +1 -0
  17. package/lib/esm/togetherai/index.js +5 -14
  18. package/lib/esm/togetherai/index.js.map +1 -1
  19. package/lib/esm/vertexai/models/palm-model-base.js +5 -13
  20. package/lib/esm/vertexai/models/palm-model-base.js.map +1 -1
  21. package/lib/types/index.d.ts +3 -2
  22. package/lib/types/index.d.ts.map +1 -1
  23. package/lib/types/mistral/index.d.ts +32 -0
  24. package/lib/types/mistral/index.d.ts.map +1 -0
  25. package/lib/types/mistral/types.d.ts +131 -0
  26. package/lib/types/mistral/types.d.ts.map +1 -0
  27. package/lib/types/togetherai/index.d.ts.map +1 -1
  28. package/lib/types/vertexai/models/palm-model-base.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/index.ts +4 -2
  31. package/src/mistral/index.ts +193 -0
  32. package/src/mistral/types.ts +211 -0
  33. package/src/togetherai/index.ts +6 -14
  34. package/src/vertexai/models/palm-model-base.ts +6 -17
@@ -0,0 +1,211 @@
1
+ // Copied from https://github.com/mistralai/client-js/blob/main/src/client.d.ts
2
+ // MistralAI Types
3
+
4
+ export interface ModelPermission {
5
+ id: string;
6
+ object: 'model_permission';
7
+ created: number;
8
+ allow_create_engine: boolean;
9
+ allow_sampling: boolean;
10
+ allow_logprobs: boolean;
11
+ allow_search_indices: boolean;
12
+ allow_view: boolean;
13
+ allow_fine_tuning: boolean;
14
+ organization: string;
15
+ group: string | null;
16
+ is_blocking: boolean;
17
+ }
18
+
19
+ export interface Model {
20
+ id: string;
21
+ object: 'model';
22
+ created: number;
23
+ owned_by: string;
24
+ root: string | null;
25
+ parent: string | null;
26
+ permission: ModelPermission[];
27
+ }
28
+
29
+ export interface ListModelsResponse {
30
+ object: 'list';
31
+ data: Model[];
32
+ }
33
+
34
+ export interface Function {
35
+ name: string;
36
+ description: string;
37
+ parameters: object;
38
+ }
39
+
40
+ export enum ToolType {
41
+ function = 'function',
42
+ }
43
+
44
+ export interface FunctionCall {
45
+ name: string;
46
+ arguments: string;
47
+ }
48
+
49
+ export interface ToolCalls {
50
+ id: 'null';
51
+ type: ToolType;
52
+ function: FunctionCall;
53
+ }
54
+
55
+ export enum ResponseFormats {
56
+ text = 'text',
57
+ json_object = 'json_object',
58
+ }
59
+
60
+ export enum ToolChoice {
61
+ auto = 'auto',
62
+ any = 'any',
63
+ none = 'none',
64
+ }
65
+
66
+ export interface ResponseFormat {
67
+ type: ResponseFormats;
68
+ }
69
+
70
+ export interface TokenUsage {
71
+ prompt_tokens: number;
72
+ completion_tokens: number;
73
+ total_tokens: number;
74
+ }
75
+
76
+ export interface ChatCompletionResponseChoice {
77
+ index: number;
78
+ message: {
79
+ role: string;
80
+ content: string;
81
+ };
82
+ finish_reason: string;
83
+ }
84
+
85
+ export interface ChatCompletionResponseChunkChoice {
86
+ index: number;
87
+ delta: {
88
+ role?: string;
89
+ content?: string;
90
+ tool_calls?: ToolCalls[];
91
+ };
92
+ finish_reason: string;
93
+ }
94
+
95
+ export interface ChatCompletionResponse {
96
+ id: string;
97
+ object: 'chat.completion';
98
+ created: number;
99
+ model: string;
100
+ choices: ChatCompletionResponseChoice[];
101
+ usage: TokenUsage;
102
+ }
103
+
104
+ export interface ChatCompletionResponseChunk {
105
+ id: string;
106
+ object: 'chat.completion.chunk';
107
+ created: number;
108
+ model: string;
109
+ choices: ChatCompletionResponseChunkChoice[];
110
+ }
111
+
112
+ export interface Embedding {
113
+ id: string;
114
+ object: 'embedding';
115
+ embedding: number[];
116
+ }
117
+
118
+ export interface EmbeddingResponse {
119
+ id: string;
120
+ object: 'list';
121
+ data: Embedding[];
122
+ model: string;
123
+ usage: TokenUsage;
124
+ }
125
+
126
+ export interface CompletionRequestParams {
127
+ model: string,
128
+ messages: Array<{ role: string; name?: string, content: string | string[], tool_calls?: ToolCalls[]; }>,
129
+ tools?: Array<{ type: string; function: Function; }>,
130
+ temperature?: number,
131
+ maxTokens?: number,
132
+ topP?: number,
133
+ randomSeed?: number,
134
+ stream?: boolean,
135
+ /**
136
+ * @deprecated use safePrompt instead
137
+ */
138
+ safeMode?: boolean,
139
+ safePrompt?: boolean,
140
+ toolChoice?: ToolChoice,
141
+ responseFormat?: ResponseFormat
142
+ }
143
+
144
+ // class MistralClient {
145
+ // constructor(apiKey?: string, endpoint?: string);
146
+
147
+ // private _request(
148
+ // method: string,
149
+ // path: string,
150
+ // request: unknown
151
+ // ): Promise<unknown>;
152
+
153
+ // private _makeChatCompletionRequest(
154
+ // model: string,
155
+ // messages: Array<{ role: string; name?: string, content: string | string[], tool_calls?: ToolCalls[]; }>,
156
+ // tools?: Array<{ type: string; function: Function; }>,
157
+ // temperature?: number,
158
+ // maxTokens?: number,
159
+ // topP?: number,
160
+ // randomSeed?: number,
161
+ // stream?: boolean,
162
+ // /**
163
+ // * @deprecated use safePrompt instead
164
+ // */
165
+ // safeMode?: boolean,
166
+ // safePrompt?: boolean,
167
+ // toolChoice?: ToolChoice,
168
+ // responseFormat?: ResponseFormat
169
+ // ): object;
170
+
171
+ // listModels(): Promise<ListModelsResponse>;
172
+
173
+ // chat(options: {
174
+ // model: string;
175
+ // messages: Array<{ role: string; name?: string, content: string | string[], tool_calls?: ToolCalls[]; }>;
176
+ // tools?: Array<{ type: string; function: Function; }>;
177
+ // temperature?: number;
178
+ // maxTokens?: number;
179
+ // topP?: number;
180
+ // randomSeed?: number;
181
+ // /**
182
+ // * @deprecated use safePrompt instead
183
+ // */
184
+ // safeMode?: boolean;
185
+ // safePrompt?: boolean;
186
+ // toolChoice?: ToolChoice;
187
+ // responseFormat?: ResponseFormat;
188
+ // }): Promise<ChatCompletionResponse>;
189
+
190
+ // chatStream(options: {
191
+ // model: string;
192
+ // messages: Array<{ role: string; name?: string, content: string | string[], tool_calls?: ToolCalls[]; }>;
193
+ // tools?: Array<{ type: string; function: Function; }>;
194
+ // temperature?: number;
195
+ // maxTokens?: number;
196
+ // topP?: number;
197
+ // randomSeed?: number;
198
+ // /**
199
+ // * @deprecated use safePrompt instead
200
+ // */
201
+ // safeMode?: boolean;
202
+ // safePrompt?: boolean;
203
+ // toolChoice?: ToolChoice;
204
+ // responseFormat?: ResponseFormat;
205
+ // }): AsyncGenerator<ChatCompletionResponseChunk, void, unknown>;
206
+
207
+ // embeddings(options: {
208
+ // model: string;
209
+ // input: string | string[];
210
+ // }): Promise<EmbeddingResponse>;
211
+ // }
@@ -1,5 +1,6 @@
1
1
  import { AIModel, AbstractDriver, Completion, DriverOptions, ExecutionOptions, PromptFormats } from "@llumiverse/core";
2
- import { FetchClient, ServerSentEvent } from "api-fetch-client";
2
+ import { transformSSEStream } from "@llumiverse/core/async";
3
+ import { FetchClient } from "api-fetch-client";
3
4
  import { TogetherModelInfo } from "./interfaces.js";
4
5
 
5
6
  interface TogetherAIDriverOptions extends DriverOptions {
@@ -75,19 +76,10 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
75
76
  reader: 'sse'
76
77
  })
77
78
 
78
- return stream.pipeThrough(new TransformStream<ServerSentEvent, string>({
79
- transform(event: ServerSentEvent, controller) {
80
- if (event.type === 'event' && event.data && event.data !== '[DONE]') {
81
- try {
82
- const data = JSON.parse(event.data);
83
- controller.enqueue(data.choices[0]?.text ?? '');
84
- } catch (err) {
85
- // double check for the last event whicb is not a JSON - at this time togetherai returrns the string [DONE]
86
- // do nothing - happens if data is not a JSON - the last event data is the [DONE] string
87
- }
88
- }
89
- }
90
- }));
79
+ return transformSSEStream(stream, (data: string) => {
80
+ const json = JSON.parse(data);
81
+ return json.choices[0]?.text ?? '';
82
+ });
91
83
 
92
84
  }
93
85
 
@@ -1,9 +1,9 @@
1
1
  import { AIModel, Completion, ExecutionOptions, PromptOptions, PromptSegment } from "@llumiverse/core";
2
+ import { transformSSEStream } from "@llumiverse/core/async";
2
3
  import { VertexAIDriver } from "../index.js";
3
4
  import { ModelDefinition } from "../models.js";
4
5
  import { PromptParamatersBase } from "../utils/prompts.js";
5
6
  import { generateStreamingPrompt } from "../utils/tensor.js";
6
- import { ServerSentEvent } from "api-fetch-client";
7
7
 
8
8
  export interface NonStreamingPromptBase<InstanceType = any> {
9
9
  instances: InstanceType[];
@@ -99,24 +99,13 @@ export abstract class AbstractPalmModelDefinition<NonStreamingPromptT extends No
99
99
  payload: newPrompt,
100
100
  reader: 'sse'
101
101
  });
102
- return eventStrean.pipeThrough(new ChunkTransformStream(this));
103
102
 
104
- }
105
-
106
- }
107
-
108
- class ChunkTransformStream<NonStreamingPromptT extends NonStreamingPromptBase, StreamingPromptT extends StreamingPromptBase> extends TransformStream {
109
- constructor(def: AbstractPalmModelDefinition<NonStreamingPromptT, StreamingPromptT>) {
110
- super({
111
- transform(event: ServerSentEvent, controller: TransformStreamDefaultController) {
112
- if (event.type === 'event' && event.data) {
113
- const data = JSON.parse(event.data);
114
- const stringChunk = def.extractContentFromResponseChunk(data);
115
- controller.enqueue(Array.isArray(stringChunk) ? stringChunk.join('') : stringChunk);
116
- }
117
- }
103
+ return transformSSEStream(eventStrean, (data: string) => {
104
+ const json = JSON.parse(data);
105
+ const stringChunk = this.extractContentFromResponseChunk(json);
106
+ return Array.isArray(stringChunk) ? stringChunk.join('') : stringChunk;
118
107
  })
119
108
  }
120
- }
121
109
 
110
+ }
122
111