llmjs2 1.0.1 → 1.0.5
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/README.md +39 -436
- package/grapes.jpg +0 -0
- package/index.d.ts +43 -0
- package/index.js +465 -0
- package/package.json +7 -47
- package/spec.txt +73 -0
- package/test-generate-tools-suite.js +100 -0
- package/test-generate-tools.js +57 -0
- package/test-generate.js +31 -0
- package/test.js +33 -0
- package/LICENSE +0 -21
- package/dist/agent.d.ts +0 -80
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -199
- package/dist/agent.js.map +0 -1
- package/dist/index.d.ts +0 -74
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -191
- package/dist/index.js.map +0 -1
- package/dist/providers/base.d.ts +0 -58
- package/dist/providers/base.d.ts.map +0 -1
- package/dist/providers/base.js +0 -149
- package/dist/providers/base.js.map +0 -1
- package/dist/providers/index.d.ts +0 -8
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -7
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/ollama.d.ts +0 -42
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js +0 -260
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -38
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -322
- package/dist/providers/openai.js.map +0 -1
- package/dist/types.d.ts +0 -191
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/src/agent.ts +0 -295
- package/src/index.ts +0 -268
- package/src/providers/base.ts +0 -216
- package/src/providers/index.ts +0 -8
- package/src/providers/ollama.ts +0 -429
- package/src/providers/openai.ts +0 -521
- package/src/types.ts +0 -243
package/dist/providers/ollama.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ollama provider implementation
|
|
3
|
-
*/
|
|
4
|
-
import { URL } from 'url';
|
|
5
|
-
import { BaseProvider, validateCompletionRequest, withRetry, LLMError, } from './base.js';
|
|
6
|
-
/**
|
|
7
|
-
* Ollama Provider implementation
|
|
8
|
-
*/
|
|
9
|
-
export class OllamaProvider extends BaseProvider {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
super(config);
|
|
12
|
-
this.baseUrl = 'https://ollama.com';
|
|
13
|
-
// Get API key from config or env variable
|
|
14
|
-
const apiKey = config.apiKey || process.env.OLLAMA_CLOUD_API_KEY;
|
|
15
|
-
if (apiKey) {
|
|
16
|
-
this.apiKey = apiKey;
|
|
17
|
-
// Default to Ollama Cloud for API key-based requests
|
|
18
|
-
if (!config.baseUrl) {
|
|
19
|
-
this.baseUrl = 'https://ollama.com';
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
this.baseUrl = config.baseUrl;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// Local Ollama setup
|
|
27
|
-
if (config.baseUrl) {
|
|
28
|
-
this.baseUrl = config.baseUrl;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Parse model string (e.g., 'ollama/mistral' -> 'mistral')
|
|
34
|
-
*/
|
|
35
|
-
parseModel(model) {
|
|
36
|
-
if (model.startsWith('ollama/')) {
|
|
37
|
-
return model.slice(7); // Remove 'ollama/' prefix
|
|
38
|
-
}
|
|
39
|
-
return model;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Validate configuration
|
|
43
|
-
*/
|
|
44
|
-
async validate() {
|
|
45
|
-
try {
|
|
46
|
-
// Make a simple request to verify Ollama is running
|
|
47
|
-
const response = await this.makeRequest('/api/tags', 'GET');
|
|
48
|
-
if (!Array.isArray(response.models)) {
|
|
49
|
-
throw new Error('Invalid Ollama response format');
|
|
50
|
-
}
|
|
51
|
-
this.logger('info', 'Ollama API validation successful');
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
throw new LLMError(`Ollama validation failed: ${error instanceof Error ? error.message : String(error)}`, 'VALIDATION_FAILED', undefined, null, true);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Create a completion
|
|
59
|
-
*/
|
|
60
|
-
async complete(request) {
|
|
61
|
-
validateCompletionRequest(request);
|
|
62
|
-
const model = this.parseModel(request.model);
|
|
63
|
-
return withRetry(async () => {
|
|
64
|
-
const ollamaRequest = {
|
|
65
|
-
model,
|
|
66
|
-
stream: false,
|
|
67
|
-
messages: request.messages.map((msg) => ({
|
|
68
|
-
role: msg.role,
|
|
69
|
-
content: msg.content,
|
|
70
|
-
})),
|
|
71
|
-
};
|
|
72
|
-
this.logger('debug', 'Ollama completion request', {
|
|
73
|
-
model,
|
|
74
|
-
messageCount: request.messages.length,
|
|
75
|
-
});
|
|
76
|
-
// Use non-streaming request for complete()
|
|
77
|
-
const response = await this.makeRequest('/api/chat', 'POST', ollamaRequest, request);
|
|
78
|
-
const fullResponse = response.message?.content || '';
|
|
79
|
-
const result = {
|
|
80
|
-
content: fullResponse,
|
|
81
|
-
model: model,
|
|
82
|
-
stopReason: 'stop_sequence',
|
|
83
|
-
raw: response,
|
|
84
|
-
};
|
|
85
|
-
this.logger('debug', 'Ollama completion response', {
|
|
86
|
-
model,
|
|
87
|
-
contentLength: fullResponse.length,
|
|
88
|
-
});
|
|
89
|
-
return result;
|
|
90
|
-
}, this.getRetryConfig(request));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Stream completion
|
|
94
|
-
*/
|
|
95
|
-
async *completeStream(request) {
|
|
96
|
-
validateCompletionRequest(request);
|
|
97
|
-
const model = this.parseModel(request.model);
|
|
98
|
-
const ollamaRequest = {
|
|
99
|
-
model,
|
|
100
|
-
stream: true,
|
|
101
|
-
messages: request.messages.map((msg) => ({
|
|
102
|
-
role: msg.role,
|
|
103
|
-
content: msg.content,
|
|
104
|
-
})),
|
|
105
|
-
};
|
|
106
|
-
this.logger('debug', 'Ollama stream request', { model });
|
|
107
|
-
const chunks = await this.streamCompletion(ollamaRequest, request);
|
|
108
|
-
for await (const chunk of chunks) {
|
|
109
|
-
if (chunk.message?.content) {
|
|
110
|
-
yield {
|
|
111
|
-
delta: chunk.message.content,
|
|
112
|
-
stopReason: chunk.done ? 'stop_sequence' : undefined,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Internal stream completion handler
|
|
119
|
-
*/
|
|
120
|
-
async *streamCompletion(body, request) {
|
|
121
|
-
const stream = await this.makeStreamRequest('/api/chat', 'POST', body, request);
|
|
122
|
-
for await (const chunk of stream) {
|
|
123
|
-
yield chunk;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Make HTTP request to Ollama API using fetch
|
|
128
|
-
*/
|
|
129
|
-
async makeRequest(path, method = 'POST', body, request) {
|
|
130
|
-
const url = new URL(path, this.baseUrl).toString();
|
|
131
|
-
const timeout = this.getTimeout(request);
|
|
132
|
-
const headers = {
|
|
133
|
-
'Content-Type': 'application/json',
|
|
134
|
-
...this.getHeaders(request),
|
|
135
|
-
};
|
|
136
|
-
if (this.apiKey) {
|
|
137
|
-
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
138
|
-
}
|
|
139
|
-
this.logger('info', '=== Ollama Request ===', {
|
|
140
|
-
url,
|
|
141
|
-
method,
|
|
142
|
-
headers,
|
|
143
|
-
body: JSON.stringify(body),
|
|
144
|
-
});
|
|
145
|
-
try {
|
|
146
|
-
const controller = new AbortController();
|
|
147
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
148
|
-
const response = await fetch(url, {
|
|
149
|
-
method,
|
|
150
|
-
headers,
|
|
151
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
152
|
-
signal: controller.signal,
|
|
153
|
-
});
|
|
154
|
-
clearTimeout(timeoutId);
|
|
155
|
-
if (!response.ok) {
|
|
156
|
-
const errorText = await response.text();
|
|
157
|
-
throw new LLMError(`Ollama API error: ${errorText}`, 'API_ERROR', response.status, null, response.status === 503 || response.status === 502);
|
|
158
|
-
}
|
|
159
|
-
const data = await response.json();
|
|
160
|
-
return data;
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
if (error instanceof LLMError) {
|
|
164
|
-
throw error;
|
|
165
|
-
}
|
|
166
|
-
if (error instanceof Error &&
|
|
167
|
-
error.name === 'AbortError') {
|
|
168
|
-
throw new LLMError('Ollama request timeout', 'TIMEOUT', undefined, null, true);
|
|
169
|
-
}
|
|
170
|
-
throw new LLMError(`Ollama request failed: ${error instanceof Error ? error.message : String(error)}`, 'REQUEST_FAILED', undefined, { error: error instanceof Error ? error.message : String(error) }, true);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Stream HTTP request using fetch
|
|
175
|
-
*/
|
|
176
|
-
makeStreamRequest(path, method = 'POST', body, request) {
|
|
177
|
-
const self = this;
|
|
178
|
-
return {
|
|
179
|
-
async *[Symbol.asyncIterator]() {
|
|
180
|
-
const url = new URL(path, self.baseUrl).toString();
|
|
181
|
-
const timeout = self.getTimeout(request);
|
|
182
|
-
const headers = {
|
|
183
|
-
'Content-Type': 'application/json',
|
|
184
|
-
...self.getHeaders(request),
|
|
185
|
-
};
|
|
186
|
-
if (self.apiKey) {
|
|
187
|
-
headers['Authorization'] = `Bearer ${self.apiKey}`;
|
|
188
|
-
}
|
|
189
|
-
self.logger('debug', 'Ollama stream request', {
|
|
190
|
-
url,
|
|
191
|
-
method,
|
|
192
|
-
headers,
|
|
193
|
-
body: JSON.stringify(body),
|
|
194
|
-
});
|
|
195
|
-
try {
|
|
196
|
-
const controller = new AbortController();
|
|
197
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
198
|
-
const response = await fetch(url, {
|
|
199
|
-
method,
|
|
200
|
-
headers,
|
|
201
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
202
|
-
signal: controller.signal,
|
|
203
|
-
});
|
|
204
|
-
clearTimeout(timeoutId);
|
|
205
|
-
if (!response.ok) {
|
|
206
|
-
const errorText = await response.text();
|
|
207
|
-
throw new LLMError(`Ollama stream error: ${errorText}`, 'STREAM_ERROR', response.status);
|
|
208
|
-
}
|
|
209
|
-
const reader = response.body?.getReader();
|
|
210
|
-
if (!reader) {
|
|
211
|
-
throw new LLMError('No response body', 'STREAM_ERROR', undefined);
|
|
212
|
-
}
|
|
213
|
-
const decoder = new TextDecoder();
|
|
214
|
-
let buffer = '';
|
|
215
|
-
while (true) {
|
|
216
|
-
const { done, value } = await reader.read();
|
|
217
|
-
if (done)
|
|
218
|
-
break;
|
|
219
|
-
buffer += decoder.decode(value, { stream: true });
|
|
220
|
-
const lines = buffer.split('\n');
|
|
221
|
-
buffer = lines[lines.length - 1];
|
|
222
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
223
|
-
const line = lines[i].trim();
|
|
224
|
-
if (!line)
|
|
225
|
-
continue;
|
|
226
|
-
try {
|
|
227
|
-
const chunk = JSON.parse(line);
|
|
228
|
-
yield chunk;
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
// Ignore parse errors in stream
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// Process any remaining data in buffer
|
|
236
|
-
if (buffer.trim()) {
|
|
237
|
-
try {
|
|
238
|
-
const chunk = JSON.parse(buffer);
|
|
239
|
-
yield chunk;
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
// Ignore parse errors
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
if (error instanceof LLMError) {
|
|
248
|
-
throw error;
|
|
249
|
-
}
|
|
250
|
-
if (error instanceof Error &&
|
|
251
|
-
error.name === 'AbortError') {
|
|
252
|
-
throw new LLMError('Ollama stream request timeout', 'TIMEOUT', undefined, null, true);
|
|
253
|
-
}
|
|
254
|
-
throw new LLMError(`Ollama stream request failed: ${error instanceof Error ? error.message : String(error)}`, 'REQUEST_FAILED', undefined, { error: error instanceof Error ? error.message : String(error) }, true);
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
//# sourceMappingURL=ollama.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAQ1B,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,SAAS,EACT,QAAQ,GACT,MAAM,WAAW,CAAC;AAsCnB;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAI9C,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;QAJR,YAAO,GAAW,oBAAoB,CAAC;QAM7C,0CAA0C;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAEjE,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,qDAAqD;YACrD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,IAAI,CAAC,OAAO,GAAG,oBAAoB,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAChC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,qBAAqB;YACrB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAa;QACtB,IAAI,KAAK,CAAC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K,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACjE,IAAI,CACL,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI provider implementation
|
|
3
|
-
*/
|
|
4
|
-
import { CompletionRequest, CompletionResponse, CompletionChunk, ProviderConfig } from '../types.js';
|
|
5
|
-
import { BaseProvider } from './base.js';
|
|
6
|
-
/**
|
|
7
|
-
* OpenAI Provider implementation
|
|
8
|
-
*/
|
|
9
|
-
export declare class OpenAIProvider extends BaseProvider {
|
|
10
|
-
private apiKey;
|
|
11
|
-
private baseUrl;
|
|
12
|
-
constructor(config: ProviderConfig);
|
|
13
|
-
/**
|
|
14
|
-
* Parse model string (e.g., 'openai/gpt-4' -> 'gpt-4')
|
|
15
|
-
*/
|
|
16
|
-
parseModel(model: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* Validate configuration
|
|
19
|
-
*/
|
|
20
|
-
validate(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Create a completion
|
|
23
|
-
*/
|
|
24
|
-
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
25
|
-
/**
|
|
26
|
-
* Stream completion
|
|
27
|
-
*/
|
|
28
|
-
completeStream(request: CompletionRequest): AsyncIterable<CompletionChunk>;
|
|
29
|
-
/**
|
|
30
|
-
* Make HTTP request to OpenAI API
|
|
31
|
-
*/
|
|
32
|
-
private makeRequest;
|
|
33
|
-
/**
|
|
34
|
-
* Stream HTTP request
|
|
35
|
-
*/
|
|
36
|
-
private makeStreamRequest;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EAIb,MAAM,WAAW,CAAC;AAwEnB;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAuC;gBAE1C,MAAM,EAAE,cAAc;IAclC;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOjC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoGvE;;OAEG;IACI,cAAc,CACnB,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAAC,eAAe,CAAC;IAsEjC;;OAEG;IACH,OAAO,CAAC,WAAW;IAsFnB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAgH1B"}
|
package/dist/providers/openai.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI provider implementation
|
|
3
|
-
*/
|
|
4
|
-
import https from 'https';
|
|
5
|
-
import http from 'http';
|
|
6
|
-
import { URL } from 'url';
|
|
7
|
-
import { BaseProvider, validateCompletionRequest, withRetry, LLMError, } from './base.js';
|
|
8
|
-
/**
|
|
9
|
-
* OpenAI Provider implementation
|
|
10
|
-
*/
|
|
11
|
-
export class OpenAIProvider extends BaseProvider {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
super(config);
|
|
14
|
-
this.baseUrl = 'https://api.openai.com/v1';
|
|
15
|
-
if (!config.apiKey) {
|
|
16
|
-
throw new Error('OpenAI API key is required');
|
|
17
|
-
}
|
|
18
|
-
this.apiKey = config.apiKey;
|
|
19
|
-
if (config.baseUrl) {
|
|
20
|
-
this.baseUrl = config.baseUrl;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Parse model string (e.g., 'openai/gpt-4' -> 'gpt-4')
|
|
25
|
-
*/
|
|
26
|
-
parseModel(model) {
|
|
27
|
-
if (model.startsWith('openai/')) {
|
|
28
|
-
return model.slice(7); // Remove 'openai/' prefix
|
|
29
|
-
}
|
|
30
|
-
return model;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Validate configuration
|
|
34
|
-
*/
|
|
35
|
-
async validate() {
|
|
36
|
-
try {
|
|
37
|
-
// Make a simple request to verify API key
|
|
38
|
-
await this.makeRequest('/models', 'GET');
|
|
39
|
-
this.logger('info', 'OpenAI API validation successful');
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
throw new LLMError(`OpenAI validation failed: ${error instanceof Error ? error.message : String(error)}`, 'VALIDATION_FAILED');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Create a completion
|
|
47
|
-
*/
|
|
48
|
-
async complete(request) {
|
|
49
|
-
validateCompletionRequest(request);
|
|
50
|
-
const model = this.parseModel(request.model);
|
|
51
|
-
return withRetry(async () => {
|
|
52
|
-
const openaiRequest = {
|
|
53
|
-
model,
|
|
54
|
-
messages: request.messages.map((msg) => ({
|
|
55
|
-
role: msg.role,
|
|
56
|
-
content: msg.content,
|
|
57
|
-
})),
|
|
58
|
-
};
|
|
59
|
-
// Add optional parameters
|
|
60
|
-
if (request.maxTokens)
|
|
61
|
-
openaiRequest.max_tokens = request.maxTokens;
|
|
62
|
-
if (request.temperature !== undefined)
|
|
63
|
-
openaiRequest.temperature = request.temperature;
|
|
64
|
-
if (request.topP !== undefined)
|
|
65
|
-
openaiRequest.top_p = request.topP;
|
|
66
|
-
if (request.frequencyPenalty !== undefined)
|
|
67
|
-
openaiRequest.frequency_penalty = request.frequencyPenalty;
|
|
68
|
-
if (request.presencePenalty !== undefined)
|
|
69
|
-
openaiRequest.presence_penalty = request.presencePenalty;
|
|
70
|
-
if (request.stop)
|
|
71
|
-
openaiRequest.stop = request.stop;
|
|
72
|
-
if (request.tools) {
|
|
73
|
-
openaiRequest.tools = request.tools.map((tool) => {
|
|
74
|
-
const finalName = 'function' in tool && tool.function?.name ? tool.function.name : tool.name;
|
|
75
|
-
const finalDescription = 'function' in tool && tool.function?.description ? tool.function.description : tool.description;
|
|
76
|
-
const finalParameters = 'function' in tool && tool.function?.parameters ? tool.function.parameters : tool.parameters;
|
|
77
|
-
return {
|
|
78
|
-
type: 'function',
|
|
79
|
-
function: {
|
|
80
|
-
name: finalName,
|
|
81
|
-
description: finalDescription,
|
|
82
|
-
parameters: finalParameters,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (request.toolChoice)
|
|
88
|
-
openaiRequest.tool_choice = request.toolChoice;
|
|
89
|
-
this.logger('debug', 'OpenAI completion request', {
|
|
90
|
-
model,
|
|
91
|
-
messageCount: request.messages.length,
|
|
92
|
-
});
|
|
93
|
-
const response = await this.makeRequest('/chat/completions', 'POST', openaiRequest, request);
|
|
94
|
-
if (!response.choices || response.choices.length === 0) {
|
|
95
|
-
throw new LLMError('No choices in OpenAI response', 'NO_CHOICES');
|
|
96
|
-
}
|
|
97
|
-
const choice = response.choices[0];
|
|
98
|
-
const message = choice.message;
|
|
99
|
-
if (!message) {
|
|
100
|
-
throw new LLMError('No message in OpenAI response choice', 'NO_MESSAGE');
|
|
101
|
-
}
|
|
102
|
-
const result = {
|
|
103
|
-
content: message.content || '',
|
|
104
|
-
model: response.model,
|
|
105
|
-
stopReason: choice.finish_reason,
|
|
106
|
-
raw: response,
|
|
107
|
-
};
|
|
108
|
-
if (response.usage) {
|
|
109
|
-
result.usage = {
|
|
110
|
-
promptTokens: response.usage.prompt_tokens,
|
|
111
|
-
completionTokens: response.usage.completion_tokens,
|
|
112
|
-
totalTokens: response.usage.total_tokens,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
116
|
-
result.toolCalls = message.tool_calls.map((call) => ({
|
|
117
|
-
id: call.id,
|
|
118
|
-
name: call.function.name,
|
|
119
|
-
arguments: JSON.parse(call.function.arguments),
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
this.logger('debug', 'OpenAI completion response', {
|
|
123
|
-
model: response.model,
|
|
124
|
-
tokens: response.usage?.total_tokens,
|
|
125
|
-
});
|
|
126
|
-
return result;
|
|
127
|
-
}, this.getRetryConfig(request));
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Stream completion
|
|
131
|
-
*/
|
|
132
|
-
async *completeStream(request) {
|
|
133
|
-
validateCompletionRequest(request);
|
|
134
|
-
const model = this.parseModel(request.model);
|
|
135
|
-
const openaiRequest = {
|
|
136
|
-
model,
|
|
137
|
-
stream: true,
|
|
138
|
-
messages: request.messages.map((msg) => ({
|
|
139
|
-
role: msg.role,
|
|
140
|
-
content: msg.content,
|
|
141
|
-
})),
|
|
142
|
-
};
|
|
143
|
-
if (request.maxTokens)
|
|
144
|
-
openaiRequest.max_tokens = request.maxTokens;
|
|
145
|
-
if (request.temperature !== undefined)
|
|
146
|
-
openaiRequest.temperature = request.temperature;
|
|
147
|
-
if (request.topP !== undefined)
|
|
148
|
-
openaiRequest.top_p = request.topP;
|
|
149
|
-
if (request.frequencyPenalty !== undefined)
|
|
150
|
-
openaiRequest.frequency_penalty = request.frequencyPenalty;
|
|
151
|
-
if (request.presencePenalty !== undefined)
|
|
152
|
-
openaiRequest.presence_penalty = request.presencePenalty;
|
|
153
|
-
if (request.stop)
|
|
154
|
-
openaiRequest.stop = request.stop;
|
|
155
|
-
if (request.tools) {
|
|
156
|
-
openaiRequest.tools = request.tools.map((tool) => {
|
|
157
|
-
if ('function' in tool && tool.function?.name) {
|
|
158
|
-
return {
|
|
159
|
-
type: 'function',
|
|
160
|
-
function: {
|
|
161
|
-
name: tool.function.name,
|
|
162
|
-
description: tool.function.description,
|
|
163
|
-
parameters: tool.function.parameters,
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
type: 'function',
|
|
169
|
-
function: {
|
|
170
|
-
name: tool.name,
|
|
171
|
-
description: tool.description,
|
|
172
|
-
parameters: tool.parameters,
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (request.toolChoice)
|
|
178
|
-
openaiRequest.tool_choice = request.toolChoice;
|
|
179
|
-
this.logger('debug', 'OpenAI stream request', { model });
|
|
180
|
-
const stream = await this.makeStreamRequest('/chat/completions', 'POST', openaiRequest, request);
|
|
181
|
-
for await (const chunk of stream) {
|
|
182
|
-
if (chunk.choices && chunk.choices.length > 0) {
|
|
183
|
-
const choice = chunk.choices[0];
|
|
184
|
-
if (choice.delta?.content) {
|
|
185
|
-
yield {
|
|
186
|
-
delta: choice.delta.content,
|
|
187
|
-
stopReason: choice.finish_reason,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Make HTTP request to OpenAI API
|
|
195
|
-
*/
|
|
196
|
-
makeRequest(path, method = 'POST', body, request) {
|
|
197
|
-
return new Promise((resolve, reject) => {
|
|
198
|
-
const url = new URL(path, this.baseUrl);
|
|
199
|
-
const timeout = this.getTimeout(request);
|
|
200
|
-
const requestOptions = {
|
|
201
|
-
method,
|
|
202
|
-
headers: {
|
|
203
|
-
'Content-Type': 'application/json',
|
|
204
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
205
|
-
...this.getHeaders(request),
|
|
206
|
-
},
|
|
207
|
-
timeout,
|
|
208
|
-
};
|
|
209
|
-
const protocol = this.baseUrl.startsWith('https') ? https : http;
|
|
210
|
-
const req = protocol.request(url, requestOptions, (res) => {
|
|
211
|
-
let data = '';
|
|
212
|
-
res.on('data', (chunk) => {
|
|
213
|
-
data += chunk;
|
|
214
|
-
});
|
|
215
|
-
res.on('end', () => {
|
|
216
|
-
if (!res.statusCode || res.statusCode >= 400) {
|
|
217
|
-
try {
|
|
218
|
-
const errorData = JSON.parse(data);
|
|
219
|
-
reject(new LLMError(errorData.error?.message || 'OpenAI API error', errorData.error?.code, res.statusCode, errorData, res.statusCode === 429 ||
|
|
220
|
-
res.statusCode === 502 ||
|
|
221
|
-
res.statusCode === 503));
|
|
222
|
-
}
|
|
223
|
-
catch {
|
|
224
|
-
reject(new LLMError(`OpenAI API error: ${data}`, 'API_ERROR', res.statusCode, null, false));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
try {
|
|
229
|
-
resolve(JSON.parse(data));
|
|
230
|
-
}
|
|
231
|
-
catch (error) {
|
|
232
|
-
reject(new LLMError('Failed to parse OpenAI response', 'PARSE_ERROR', undefined, { data }));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
req.on('error', (error) => {
|
|
238
|
-
reject(new LLMError(`OpenAI request failed: ${error.message}`, 'REQUEST_FAILED', undefined, { error: error.message }, true));
|
|
239
|
-
});
|
|
240
|
-
if (body) {
|
|
241
|
-
req.write(JSON.stringify(body));
|
|
242
|
-
}
|
|
243
|
-
req.end();
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Stream HTTP request
|
|
248
|
-
*/
|
|
249
|
-
makeStreamRequest(path, method = 'POST', body, request) {
|
|
250
|
-
const self = this;
|
|
251
|
-
return {
|
|
252
|
-
async *[Symbol.asyncIterator]() {
|
|
253
|
-
const url = new URL(path, self.baseUrl);
|
|
254
|
-
const timeout = self.getTimeout(request);
|
|
255
|
-
const requestOptions = {
|
|
256
|
-
method,
|
|
257
|
-
headers: {
|
|
258
|
-
'Content-Type': 'application/json',
|
|
259
|
-
Authorization: `Bearer ${self.apiKey}`,
|
|
260
|
-
...self.getHeaders(request),
|
|
261
|
-
},
|
|
262
|
-
timeout,
|
|
263
|
-
};
|
|
264
|
-
const protocol = self.baseUrl.startsWith('https') ? https : http;
|
|
265
|
-
const chunks = [];
|
|
266
|
-
await new Promise((resolve, reject) => {
|
|
267
|
-
const req = protocol.request(url, requestOptions, (res) => {
|
|
268
|
-
if (!res.statusCode || res.statusCode >= 400) {
|
|
269
|
-
let errorData = '';
|
|
270
|
-
res.on('data', (chunk) => {
|
|
271
|
-
errorData += chunk;
|
|
272
|
-
});
|
|
273
|
-
res.on('end', () => {
|
|
274
|
-
reject(new LLMError(`OpenAI stream error: ${errorData}`, 'STREAM_ERROR', res.statusCode));
|
|
275
|
-
});
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
let buffer = '';
|
|
279
|
-
res.on('data', (chunk) => {
|
|
280
|
-
buffer += chunk.toString();
|
|
281
|
-
const lines = buffer.split('\n');
|
|
282
|
-
buffer = lines[lines.length - 1];
|
|
283
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
284
|
-
const line = lines[i].trim();
|
|
285
|
-
if (!line || line === '[DONE]')
|
|
286
|
-
continue;
|
|
287
|
-
if (line.startsWith('data: ')) {
|
|
288
|
-
try {
|
|
289
|
-
const data = JSON.parse(line.slice(6));
|
|
290
|
-
chunks.push(data);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
// Ignore parse errors in stream
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
res.on('end', () => {
|
|
299
|
-
resolve();
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
req.on('error', (error) => {
|
|
303
|
-
reject(new LLMError(`OpenAI stream request failed: ${error.message}`, 'REQUEST_FAILED', undefined, { error: error.message }, true));
|
|
304
|
-
});
|
|
305
|
-
req.on('timeout', () => {
|
|
306
|
-
req.destroy();
|
|
307
|
-
reject(new LLMError('OpenAI stream request timeout', 'TIMEOUT', undefined, null, true));
|
|
308
|
-
});
|
|
309
|
-
if (body) {
|
|
310
|
-
req.write(JSON.stringify(body));
|
|
311
|
-
}
|
|
312
|
-
req.end();
|
|
313
|
-
});
|
|
314
|
-
// Yield collected chunks
|
|
315
|
-
for (const chunk of chunks) {
|
|
316
|
-
yield chunk;
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
//# sourceMappingURL=openai.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAQ1B,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,SAAS,EACT,QAAQ,GACT,MAAM,WAAW,CAAC;AAwEnB;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAI9C,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;QAHR,YAAO,GAAW,2BAA2B,CAAC;QAKpD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE5B,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAa;QACtB,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;QACnD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;O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