@iservu-inc/adf-cli 0.14.4 → 0.14.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/lib/ai/ai-client.js +5 -53
- package/lib/ai/ai-config.js +0 -69
- package/package.json +1 -1
package/lib/ai/ai-client.js
CHANGED
|
@@ -49,14 +49,6 @@ class AIClient {
|
|
|
49
49
|
});
|
|
50
50
|
break;
|
|
51
51
|
|
|
52
|
-
case 'perplexity':
|
|
53
|
-
const OpenAIForPerplexity = require('openai');
|
|
54
|
-
this.client = new OpenAIForPerplexity({
|
|
55
|
-
apiKey: this.apiKey,
|
|
56
|
-
baseURL: 'https://api.perplexity.ai'
|
|
57
|
-
});
|
|
58
|
-
break;
|
|
59
|
-
|
|
60
52
|
default:
|
|
61
53
|
throw new Error(`Unsupported provider: ${this.provider}`);
|
|
62
54
|
}
|
|
@@ -80,14 +72,11 @@ class AIClient {
|
|
|
80
72
|
case 'google':
|
|
81
73
|
return await this.googleRequest(prompt, maxTokens, temperature);
|
|
82
74
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
default: throw new Error(`Provider ${this.provider} not implemented`);
|
|
90
|
-
}
|
|
75
|
+
case 'openrouter':
|
|
76
|
+
return await this.openrouterRequest(prompt, maxTokens, temperature);
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`Provider ${this.provider} not implemented`); }
|
|
91
80
|
} catch (error) {
|
|
92
81
|
throw new Error(`AI request failed: ${error.message}`);
|
|
93
82
|
}
|
|
@@ -322,43 +311,6 @@ class AIClient {
|
|
|
322
311
|
}
|
|
323
312
|
}
|
|
324
313
|
|
|
325
|
-
/**
|
|
326
|
-
* Perplexity AI request (via OpenAI-compatible API)
|
|
327
|
-
*/
|
|
328
|
-
async perplexityRequest(prompt, maxTokens, temperature) {
|
|
329
|
-
try {
|
|
330
|
-
// Perplexity supports standard OpenAI chat completions
|
|
331
|
-
// but has some specific recommended parameters
|
|
332
|
-
const response = await this.client.chat.completions.create({
|
|
333
|
-
model: this.model,
|
|
334
|
-
messages: [
|
|
335
|
-
{
|
|
336
|
-
role: 'user',
|
|
337
|
-
content: prompt
|
|
338
|
-
}
|
|
339
|
-
],
|
|
340
|
-
max_tokens: maxTokens,
|
|
341
|
-
temperature: temperature,
|
|
342
|
-
// Optional: Perplexity specific headers can be passed if needed via client config
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
content: response.choices[0].message.content,
|
|
347
|
-
model: this.model,
|
|
348
|
-
provider: 'perplexity',
|
|
349
|
-
usage: {
|
|
350
|
-
promptTokens: response.usage?.prompt_tokens || 0,
|
|
351
|
-
completionTokens: response.usage?.completion_tokens || 0,
|
|
352
|
-
totalTokens: response.usage?.total_tokens || 0
|
|
353
|
-
},
|
|
354
|
-
// Include search citations if available (Perplexity feature)
|
|
355
|
-
citations: response.citations || []
|
|
356
|
-
};
|
|
357
|
-
} catch (error) {
|
|
358
|
-
throw new Error(`Perplexity request failed: ${error.message}`);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
314
|
/**
|
|
363
315
|
* Test connection with a simple prompt
|
|
364
316
|
*/
|
package/lib/ai/ai-config.js
CHANGED
|
@@ -70,20 +70,6 @@ const AI_PROVIDERS = {
|
|
|
70
70
|
'google/gemini-pro-1.5',
|
|
71
71
|
'meta-llama/llama-3.1-70b-instruct'
|
|
72
72
|
]
|
|
73
|
-
},
|
|
74
|
-
PERPLEXITY: {
|
|
75
|
-
id: 'perplexity',
|
|
76
|
-
name: 'Perplexity AI (Search + Reasoning)',
|
|
77
|
-
envVar: 'PERPLEXITY_API_KEY',
|
|
78
|
-
requiredFormat: 'pplx-',
|
|
79
|
-
website: 'https://www.perplexity.ai/api',
|
|
80
|
-
setup: 'Get your API key from https://www.perplexity.ai/settings/api',
|
|
81
|
-
defaultModels: [
|
|
82
|
-
'sonar-pro',
|
|
83
|
-
'sonar-reasoning-pro',
|
|
84
|
-
'sonar',
|
|
85
|
-
'sonar-deep-research'
|
|
86
|
-
]
|
|
87
73
|
}
|
|
88
74
|
};
|
|
89
75
|
|
|
@@ -273,27 +259,6 @@ async function validateAPIKeyWithProvider(provider, apiKey, model = null) {
|
|
|
273
259
|
}
|
|
274
260
|
break;
|
|
275
261
|
|
|
276
|
-
case 'perplexity':
|
|
277
|
-
// Perplexity doesn't support models.list() fully in all tiers or it might be static.
|
|
278
|
-
// We use a cheap "models" list call if supported, or rely on the fact that
|
|
279
|
-
// if we can create a client and it doesn't crash, we assume it's good enough
|
|
280
|
-
// for this stage, effectively deferring full validation to model testing.
|
|
281
|
-
// However, we can try to hit the chat/completions endpoint with dry-run style if possible.
|
|
282
|
-
// For now, we will perform a lightweight check using OpenAI compatibility.
|
|
283
|
-
try {
|
|
284
|
-
const OpenAI = require('openai');
|
|
285
|
-
const client = new OpenAI({
|
|
286
|
-
apiKey,
|
|
287
|
-
baseURL: 'https://api.perplexity.ai'
|
|
288
|
-
});
|
|
289
|
-
// Try listing models (Perplexity supports this via OpenAI compatibility)
|
|
290
|
-
await client.models.list();
|
|
291
|
-
} catch (error) {
|
|
292
|
-
// If list models fails, the key is likely invalid
|
|
293
|
-
throw new Error(`Perplexity API validation failed: ${error.message}`);
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
|
|
297
262
|
default:
|
|
298
263
|
throw new Error(`Validation not implemented for provider: ${provider.id}`);
|
|
299
264
|
}
|
|
@@ -416,35 +381,6 @@ async function fetchAvailableModels(provider, apiKey) {
|
|
|
416
381
|
console.log(chalk.yellow(' Using default model list\n'));
|
|
417
382
|
return provider.defaultModels;
|
|
418
383
|
|
|
419
|
-
case 'perplexity':
|
|
420
|
-
try {
|
|
421
|
-
// Perplexity doesn't have a list models endpoint, so we validate known ones
|
|
422
|
-
// by performing a very cheap token count or dry-run if possible,
|
|
423
|
-
// but for now we rely on the default list as it is static but we can try to validate
|
|
424
|
-
// the API key with a simple request to 'sonar' which is their fastest model.
|
|
425
|
-
const OpenAI = require('openai');
|
|
426
|
-
const client = new OpenAI({
|
|
427
|
-
apiKey,
|
|
428
|
-
baseURL: 'https://api.perplexity.ai'
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Simple validation check
|
|
432
|
-
await client.models.list(); // Some OpenAI compatible endpoints support this, let's try
|
|
433
|
-
|
|
434
|
-
// If list() works, we filter, otherwise we might fallback to defaults.
|
|
435
|
-
// Note: Perplexity API documentation says standard OpenAI endpoints are supported.
|
|
436
|
-
// If list() returns models, great. If not, we use defaults.
|
|
437
|
-
// However, Perplexity typically DOES NOT implement the /models endpoint fully dynamically
|
|
438
|
-
// like OpenAI. It often returns a static list or might error.
|
|
439
|
-
// Let's assume for safety we use the defaults but verified via a simple call.
|
|
440
|
-
|
|
441
|
-
spinner.succeed('Perplexity API connected');
|
|
442
|
-
return provider.defaultModels; // Return defaults as they are curated for the platform
|
|
443
|
-
} catch(error) {
|
|
444
|
-
spinner.warn(`Perplexity connectivity check failed: ${error.message}`);
|
|
445
|
-
}
|
|
446
|
-
return provider.defaultModels;
|
|
447
|
-
|
|
448
384
|
case 'openrouter':
|
|
449
385
|
try {
|
|
450
386
|
const fetch = require('node-fetch');
|
|
@@ -592,11 +528,6 @@ async function configureAIProvider(projectPath = process.cwd()) {
|
|
|
592
528
|
name: buildProviderName(AI_PROVIDERS.OPENROUTER, 'openrouter'),
|
|
593
529
|
value: 'openrouter',
|
|
594
530
|
short: 'OpenRouter'
|
|
595
|
-
},
|
|
596
|
-
{
|
|
597
|
-
name: buildProviderName(AI_PROVIDERS.PERPLEXITY, 'perplexity'),
|
|
598
|
-
value: 'perplexity',
|
|
599
|
-
short: 'Perplexity'
|
|
600
531
|
}
|
|
601
532
|
];
|
|
602
533
|
|