rentabots-sdk 1.6.3 → 1.6.4
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/dist/index.d.ts +6 -0
- package/dist/index.js +12 -10
- package/dist/llm.d.ts +34 -0
- package/dist/llm.js +129 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -159,6 +159,12 @@ export declare class Agent extends EventEmitter {
|
|
|
159
159
|
checks: any[];
|
|
160
160
|
}>;
|
|
161
161
|
markComplete(jobId: string): Promise<any>;
|
|
162
|
+
private llmClient?;
|
|
163
|
+
initLLM(config?: {
|
|
164
|
+
provider?: 'groq' | 'openai' | 'anthropic' | 'google' | 'nvidia';
|
|
165
|
+
apiKey?: string;
|
|
166
|
+
model?: string;
|
|
167
|
+
}): Promise<void>;
|
|
162
168
|
generate(prompt: string, options?: {
|
|
163
169
|
model?: string;
|
|
164
170
|
temperature?: number;
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Agent = exports.MessageSchema = exports.JobSchema = exports.JobStatusSchema = void 0;
|
|
40
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const llm_1 = require("./llm");
|
|
41
42
|
const socket_io_client_1 = require("socket.io-client");
|
|
42
43
|
const zod_1 = require("zod");
|
|
43
44
|
const events_1 = require("events");
|
|
@@ -529,18 +530,19 @@ class Agent extends events_1.EventEmitter {
|
|
|
529
530
|
}
|
|
530
531
|
return res.data;
|
|
531
532
|
}
|
|
532
|
-
|
|
533
|
+
async initLLM(config) {
|
|
534
|
+
this.llmClient = new llm_1.LLMClient(config);
|
|
535
|
+
}
|
|
533
536
|
async generate(prompt, options = {}) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
catch (e) {
|
|
542
|
-
return { success: false, error: e.response?.data?.error || e.message };
|
|
537
|
+
if (!this.llmClient) {
|
|
538
|
+
try {
|
|
539
|
+
this.llmClient = new llm_1.LLMClient();
|
|
540
|
+
}
|
|
541
|
+
catch (e) {
|
|
542
|
+
return { success: false, error: e.message };
|
|
543
|
+
}
|
|
543
544
|
}
|
|
545
|
+
return this.llmClient.generate(prompt, options);
|
|
544
546
|
}
|
|
545
547
|
async analyzeRequirements(job) {
|
|
546
548
|
const prompt = 'Analyze job, return JSON with techStack, features, deliverables, timeline, risks. Title: ' + job.title + ' Desc: ' + job.description.slice(0, 500);
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider Configuration
|
|
3
|
+
* Agents use their own API keys - no server proxy needed
|
|
4
|
+
*/
|
|
5
|
+
export interface LLMConfig {
|
|
6
|
+
provider: 'groq' | 'openai' | 'anthropic' | 'google' | 'nvidia';
|
|
7
|
+
apiKey: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface LLMResponse {
|
|
12
|
+
success: boolean;
|
|
13
|
+
text?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
usage?: {
|
|
16
|
+
promptTokens: number;
|
|
17
|
+
completionTokens: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class LLMClient {
|
|
21
|
+
private config;
|
|
22
|
+
private client;
|
|
23
|
+
constructor(config?: Partial<LLMConfig>);
|
|
24
|
+
private detectProvider;
|
|
25
|
+
private getApiKey;
|
|
26
|
+
generate(prompt: string, options?: {
|
|
27
|
+
system?: string;
|
|
28
|
+
temperature?: number;
|
|
29
|
+
maxTokens?: number;
|
|
30
|
+
model?: string;
|
|
31
|
+
}): Promise<LLMResponse>;
|
|
32
|
+
private callAnthropic;
|
|
33
|
+
}
|
|
34
|
+
export default LLMClient;
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LLMClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const PROVIDER_CONFIGS = {
|
|
9
|
+
groq: {
|
|
10
|
+
baseUrl: 'https://api.groq.com/openai/v1',
|
|
11
|
+
defaultModel: 'llama-3.3-70b-versatile',
|
|
12
|
+
apiFormat: 'openai'
|
|
13
|
+
},
|
|
14
|
+
openai: {
|
|
15
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
16
|
+
defaultModel: 'gpt-4o-mini',
|
|
17
|
+
apiFormat: 'openai'
|
|
18
|
+
},
|
|
19
|
+
anthropic: {
|
|
20
|
+
baseUrl: 'https://api.anthropic.com',
|
|
21
|
+
defaultModel: 'claude-3-sonnet-20240229',
|
|
22
|
+
apiFormat: 'anthropic'
|
|
23
|
+
},
|
|
24
|
+
google: {
|
|
25
|
+
baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
|
|
26
|
+
defaultModel: 'gemini-1.5-flash',
|
|
27
|
+
apiFormat: 'openai'
|
|
28
|
+
},
|
|
29
|
+
nvidia: {
|
|
30
|
+
baseUrl: 'https://integrate.api.nvidia.com/v1',
|
|
31
|
+
defaultModel: 'meta/llama-3.1-405b-instruct',
|
|
32
|
+
apiFormat: 'openai'
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
class LLMClient {
|
|
36
|
+
constructor(config) {
|
|
37
|
+
// Auto-detect from environment
|
|
38
|
+
const provider = config?.provider || this.detectProvider();
|
|
39
|
+
const apiKey = config?.apiKey || this.getApiKey(provider);
|
|
40
|
+
if (!apiKey) {
|
|
41
|
+
throw new Error(`No API key found for LLM provider '${provider}'. Set ${provider.toUpperCase()}_API_KEY or GROQ_API_KEY`);
|
|
42
|
+
}
|
|
43
|
+
const preset = PROVIDER_CONFIGS[provider];
|
|
44
|
+
this.config = {
|
|
45
|
+
provider,
|
|
46
|
+
apiKey,
|
|
47
|
+
baseUrl: config?.baseUrl || preset?.baseUrl,
|
|
48
|
+
model: config?.model || preset?.defaultModel
|
|
49
|
+
};
|
|
50
|
+
this.client = axios_1.default.create({
|
|
51
|
+
baseURL: this.config.baseUrl,
|
|
52
|
+
headers: provider === 'anthropic'
|
|
53
|
+
? { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01' }
|
|
54
|
+
: { 'Authorization': `Bearer ${apiKey}` }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
detectProvider() {
|
|
58
|
+
if (process.env.ANTHROPIC_API_KEY)
|
|
59
|
+
return 'anthropic';
|
|
60
|
+
if (process.env.OPENAI_API_KEY)
|
|
61
|
+
return 'openai';
|
|
62
|
+
if (process.env.GOOGLE_API_KEY)
|
|
63
|
+
return 'google';
|
|
64
|
+
if (process.env.NVIDIA_API_KEY)
|
|
65
|
+
return 'nvidia';
|
|
66
|
+
return 'groq'; // Default
|
|
67
|
+
}
|
|
68
|
+
getApiKey(provider) {
|
|
69
|
+
const envMap = {
|
|
70
|
+
groq: 'GROQ_API_KEY',
|
|
71
|
+
openai: 'OPENAI_API_KEY',
|
|
72
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
73
|
+
google: 'GOOGLE_API_KEY',
|
|
74
|
+
nvidia: 'NVIDIA_API_KEY'
|
|
75
|
+
};
|
|
76
|
+
return process.env[envMap[provider]] || process.env.GROQ_API_KEY || process.env.RENTABOTS_LLM_KEY;
|
|
77
|
+
}
|
|
78
|
+
async generate(prompt, options = {}) {
|
|
79
|
+
const model = options.model || this.config.model;
|
|
80
|
+
try {
|
|
81
|
+
if (this.config.provider === 'anthropic') {
|
|
82
|
+
return await this.callAnthropic(prompt, options, model);
|
|
83
|
+
}
|
|
84
|
+
// OpenAI-compatible format
|
|
85
|
+
const res = await this.client.post('/chat/completions', {
|
|
86
|
+
model,
|
|
87
|
+
messages: [
|
|
88
|
+
...(options.system ? [{ role: 'system', content: options.system }] : []),
|
|
89
|
+
{ role: 'user', content: prompt }
|
|
90
|
+
],
|
|
91
|
+
temperature: options.temperature ?? 0.7,
|
|
92
|
+
max_tokens: options.maxTokens ?? 2048
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
text: res.data.choices[0]?.message?.content,
|
|
97
|
+
usage: res.data.usage ? {
|
|
98
|
+
promptTokens: res.data.usage.prompt_tokens,
|
|
99
|
+
completionTokens: res.data.usage.completion_tokens
|
|
100
|
+
} : undefined
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: error.response?.data?.error?.message || error.message
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async callAnthropic(prompt, options, model) {
|
|
111
|
+
const res = await this.client.post('/v1/messages', {
|
|
112
|
+
model,
|
|
113
|
+
messages: [{ role: 'user', content: prompt }],
|
|
114
|
+
system: options.system,
|
|
115
|
+
temperature: options.temperature ?? 0.7,
|
|
116
|
+
max_tokens: options.maxTokens ?? 2048
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
text: res.data.content[0]?.text,
|
|
121
|
+
usage: {
|
|
122
|
+
promptTokens: res.data.usage?.input_tokens || 0,
|
|
123
|
+
completionTokens: res.data.usage?.output_tokens || 0
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.LLMClient = LLMClient;
|
|
129
|
+
exports.default = LLMClient;
|