movie-agent 1.0.0 ā 1.1.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/README.md +310 -39
- package/bin/movie-agent +33 -8
- package/dist/agent.d.ts +26 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +77 -1
- package/dist/agent.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +23 -1
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/llm.d.ts +33 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +210 -0
- package/dist/llm.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@ An intelligent movie recommendation system that helps users discover movies base
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- š¬ Personalized movie recommendations based on mood, genre, and preferences
|
|
8
|
+
- š¤ AI-powered output formatting with LangChain and Google Gemini
|
|
9
|
+
- š Streaming and non-streaming output modes
|
|
8
10
|
- šŗ Real-time streaming availability for Canadian platforms
|
|
9
11
|
- ā” Fast responses using TMDb API
|
|
10
12
|
- šÆ Smart filtering by runtime, release year, and streaming platforms
|
|
@@ -14,6 +16,9 @@ An intelligent movie recommendation system that helps users discover movies base
|
|
|
14
16
|
|
|
15
17
|
- Node.js (v18 or higher)
|
|
16
18
|
- TMDb API key ([Get one here](https://www.themoviedb.org/settings/api))
|
|
19
|
+
- LLM API key for AI formatting (optional):
|
|
20
|
+
- Google Gemini API key - [Get one here](https://aistudio.google.com/app/apikey)
|
|
21
|
+
- **OR** Azure OpenAI credentials - [Learn more](https://azure.microsoft.com/en-us/products/ai-services/openai-service)
|
|
17
22
|
|
|
18
23
|
## Installation
|
|
19
24
|
|
|
@@ -23,55 +28,185 @@ npm install movie-agent
|
|
|
23
28
|
|
|
24
29
|
## Quick Start
|
|
25
30
|
|
|
26
|
-
###
|
|
31
|
+
### Basic Usage - Get Structured Data
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { MovieAgent } from 'movie-agent';
|
|
35
|
+
|
|
36
|
+
// Create agent
|
|
37
|
+
const agent = new MovieAgent();
|
|
38
|
+
|
|
39
|
+
// Get structured recommendations
|
|
40
|
+
const response = await agent.getRecommendations({
|
|
41
|
+
mood: 'excited',
|
|
42
|
+
platforms: ['Netflix', 'Prime Video'],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(response.recommendations);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### AI-Formatted Output - Invoke Mode (Waits for complete response)
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { MovieAgent } from 'movie-agent';
|
|
52
|
+
|
|
53
|
+
const agent = new MovieAgent();
|
|
54
|
+
|
|
55
|
+
// Get AI-formatted markdown output
|
|
56
|
+
const output = await agent.invoke({
|
|
57
|
+
mood: 'happy',
|
|
58
|
+
platforms: ['Netflix'],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(output); // Formatted markdown string
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### AI-Formatted Output - Stream Mode (Real-time streaming)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { MovieAgent } from 'movie-agent';
|
|
68
|
+
|
|
69
|
+
const agent = new MovieAgent();
|
|
70
|
+
|
|
71
|
+
// Stream AI-formatted output in real-time
|
|
72
|
+
await agent.stream({
|
|
73
|
+
mood: 'excited',
|
|
74
|
+
platforms: ['Netflix'],
|
|
75
|
+
}, (chunk) => {
|
|
76
|
+
process.stdout.write(chunk); // or update your UI
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Using with MovieAgentFactory
|
|
27
81
|
|
|
28
82
|
```typescript
|
|
29
83
|
import { MovieAgentFactory } from 'movie-agent';
|
|
30
84
|
|
|
31
|
-
// Create agent with explicit configuration
|
|
85
|
+
// Create agent with explicit configuration (Gemini)
|
|
32
86
|
const agent = MovieAgentFactory.create({
|
|
33
87
|
tmdbApiKey: process.env.TMDB_API_KEY!,
|
|
34
88
|
tmdbRegion: 'CA',
|
|
35
|
-
|
|
89
|
+
llmProvider: 'gemini',
|
|
90
|
+
geminiApiKey: process.env.GEMINI_API_KEY,
|
|
91
|
+
debug: true,
|
|
36
92
|
});
|
|
37
93
|
|
|
38
|
-
//
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
94
|
+
// Or use Azure OpenAI
|
|
95
|
+
const agentWithAzure = MovieAgentFactory.create({
|
|
96
|
+
tmdbApiKey: process.env.TMDB_API_KEY!,
|
|
97
|
+
tmdbRegion: 'CA',
|
|
98
|
+
llmProvider: 'azure',
|
|
99
|
+
azureOpenAiApiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
100
|
+
azureOpenAiEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
101
|
+
azureOpenAiDeployment: process.env.AZURE_OPENAI_DEPLOYMENT,
|
|
102
|
+
debug: true,
|
|
43
103
|
});
|
|
44
104
|
|
|
45
|
-
|
|
105
|
+
// All three methods available: getRecommendations, invoke, stream
|
|
106
|
+
const structured = await agent.getRecommendations({ mood: 'happy' });
|
|
107
|
+
const formatted = await agent.invoke({ mood: 'happy' });
|
|
108
|
+
await agent.stream({ mood: 'happy' }, (chunk) => console.log(chunk));
|
|
46
109
|
```
|
|
47
110
|
|
|
48
|
-
|
|
111
|
+
## API Reference
|
|
112
|
+
|
|
113
|
+
### MovieAgent Methods
|
|
114
|
+
|
|
115
|
+
#### `getRecommendations(input: UserInput): Promise<AgentResponse | ErrorResponse>`
|
|
116
|
+
Returns structured movie recommendations with metadata.
|
|
49
117
|
|
|
50
118
|
```typescript
|
|
51
|
-
|
|
52
|
-
|
|
119
|
+
const response = await agent.getRecommendations({
|
|
120
|
+
mood: 'happy',
|
|
121
|
+
platforms: ['Netflix']
|
|
122
|
+
});
|
|
123
|
+
// Returns: { recommendations: [...], metadata: {...} }
|
|
124
|
+
```
|
|
53
125
|
|
|
54
|
-
|
|
55
|
-
|
|
126
|
+
#### `invoke(input: UserInput): Promise<string | ErrorResponse>`
|
|
127
|
+
Returns AI-formatted markdown output (non-streaming). Waits for complete response before returning.
|
|
56
128
|
|
|
57
|
-
|
|
58
|
-
const
|
|
129
|
+
```typescript
|
|
130
|
+
const output = await agent.invoke({
|
|
131
|
+
mood: 'excited',
|
|
132
|
+
platforms: ['Netflix']
|
|
133
|
+
});
|
|
134
|
+
// Returns: Formatted markdown string
|
|
135
|
+
```
|
|
59
136
|
|
|
60
|
-
|
|
61
|
-
|
|
137
|
+
#### `stream(input: UserInput, onChunk: (chunk: string) => void): Promise<void | ErrorResponse>`
|
|
138
|
+
Streams AI-formatted output in real-time. Best for interactive UIs.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
await agent.stream({
|
|
62
142
|
mood: 'relaxed',
|
|
63
|
-
|
|
64
|
-
|
|
143
|
+
platforms: ['Netflix']
|
|
144
|
+
}, (chunk) => {
|
|
145
|
+
process.stdout.write(chunk);
|
|
65
146
|
});
|
|
66
147
|
```
|
|
67
148
|
|
|
149
|
+
## Input Parameters
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
interface UserInput {
|
|
153
|
+
mood?: string; // e.g., 'excited', 'relaxed', 'thoughtful', 'happy', 'scared'
|
|
154
|
+
genre?: string | string[]; // e.g., 'Action' or ['Action', 'Thriller']
|
|
155
|
+
platforms?: string[]; // e.g., ['Netflix', 'Prime Video', 'Disney+']
|
|
156
|
+
runtime?: {
|
|
157
|
+
min?: number; // Minimum runtime in minutes
|
|
158
|
+
max?: number; // Maximum runtime in minutes
|
|
159
|
+
};
|
|
160
|
+
releaseYear?: number | { // Single year or range
|
|
161
|
+
from?: number;
|
|
162
|
+
to?: number;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Output Comparison
|
|
168
|
+
|
|
169
|
+
### `getRecommendations()` - Structured Data
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"recommendations": [
|
|
173
|
+
{
|
|
174
|
+
"tmdbId": 123,
|
|
175
|
+
"title": "Movie Title",
|
|
176
|
+
"releaseYear": "2024",
|
|
177
|
+
"runtime": 120,
|
|
178
|
+
"genres": ["Action", "Adventure"],
|
|
179
|
+
"description": "...",
|
|
180
|
+
"streamingPlatforms": [...],
|
|
181
|
+
"matchReason": "..."
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"metadata": {...}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `invoke()` / `stream()` - AI-Formatted Markdown
|
|
189
|
+
```markdown
|
|
190
|
+
Hey there! š Looking for some action-packed thrills? Here are your recommendations:
|
|
191
|
+
|
|
192
|
+
### **Movie Title (2024)** - 120 minutes
|
|
193
|
+
*Genres: Action, Adventure*
|
|
194
|
+
A compelling description...
|
|
195
|
+
šŗ Available on: Netflix
|
|
196
|
+
⨠Why: Perfect for your excited mood with thrilling action!
|
|
197
|
+
```
|
|
198
|
+
|
|
68
199
|
## API Examples
|
|
69
200
|
|
|
70
201
|
```typescript
|
|
71
202
|
// Simple mood-based search
|
|
72
|
-
await agent.getRecommendations({
|
|
73
|
-
|
|
74
|
-
|
|
203
|
+
await agent.getRecommendations({ mood: 'happy' });
|
|
204
|
+
|
|
205
|
+
// AI-formatted output
|
|
206
|
+
await agent.invoke({ mood: 'happy' });
|
|
207
|
+
|
|
208
|
+
// Streaming output
|
|
209
|
+
await agent.stream({ mood: 'happy' }, (chunk) => console.log(chunk));
|
|
75
210
|
|
|
76
211
|
// Genre-specific with platform filter
|
|
77
212
|
await agent.getRecommendations({
|
|
@@ -97,17 +232,14 @@ await agent.getRecommendations({
|
|
|
97
232
|
|
|
98
233
|
## Integration Examples
|
|
99
234
|
|
|
100
|
-
### Next.js API Route
|
|
235
|
+
### Next.js API Route (Structured Data)
|
|
101
236
|
|
|
102
237
|
```typescript
|
|
103
238
|
// pages/api/recommendations.ts
|
|
104
|
-
import {
|
|
239
|
+
import { MovieAgent } from 'movie-agent';
|
|
105
240
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
106
241
|
|
|
107
|
-
const agent =
|
|
108
|
-
tmdbApiKey: process.env.TMDB_API_KEY!,
|
|
109
|
-
tmdbRegion: 'CA',
|
|
110
|
-
});
|
|
242
|
+
const agent = new MovieAgent();
|
|
111
243
|
|
|
112
244
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
113
245
|
if (req.method !== 'POST') {
|
|
@@ -125,23 +257,50 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|
|
125
257
|
}
|
|
126
258
|
```
|
|
127
259
|
|
|
128
|
-
###
|
|
260
|
+
### Next.js API Route (AI-Formatted Streaming)
|
|
129
261
|
|
|
130
262
|
```typescript
|
|
131
|
-
|
|
132
|
-
import {
|
|
133
|
-
import
|
|
263
|
+
// pages/api/recommendations-stream.ts
|
|
264
|
+
import { MovieAgent } from 'movie-agent';
|
|
265
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
266
|
+
|
|
267
|
+
const agent = new MovieAgent();
|
|
134
268
|
|
|
135
|
-
|
|
269
|
+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
270
|
+
if (req.method !== 'POST') {
|
|
271
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
const { mood, genre, platforms } = req.body;
|
|
276
|
+
|
|
277
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
278
|
+
res.setHeader('Transfer-Encoding', 'chunked');
|
|
279
|
+
|
|
280
|
+
await agent.stream({ mood, genre, platforms }, (chunk) => {
|
|
281
|
+
res.write(chunk);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
res.end();
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error('Error streaming recommendations:', error);
|
|
287
|
+
res.status(500).json({ error: 'Failed to stream recommendations' });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Express Server (Streaming)
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import express from 'express';
|
|
296
|
+
import { MovieAgent } from 'movie-agent';
|
|
136
297
|
|
|
137
298
|
const app = express();
|
|
138
299
|
app.use(express.json());
|
|
139
300
|
|
|
140
|
-
const agent =
|
|
141
|
-
tmdbApiKey: process.env.TMDB_API_KEY!,
|
|
142
|
-
tmdbRegion: 'CA',
|
|
143
|
-
});
|
|
301
|
+
const agent = new MovieAgent();
|
|
144
302
|
|
|
303
|
+
// Structured data endpoint
|
|
145
304
|
app.post('/api/recommendations', async (req, res) => {
|
|
146
305
|
try {
|
|
147
306
|
const recommendations = await agent.getRecommendations(req.body);
|
|
@@ -152,11 +311,72 @@ app.post('/api/recommendations', async (req, res) => {
|
|
|
152
311
|
}
|
|
153
312
|
});
|
|
154
313
|
|
|
314
|
+
// Streaming endpoint
|
|
315
|
+
app.post('/api/recommendations/stream', async (req, res) => {
|
|
316
|
+
try {
|
|
317
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
318
|
+
res.setHeader('Transfer-Encoding', 'chunked');
|
|
319
|
+
|
|
320
|
+
await agent.stream(req.body, (chunk) => {
|
|
321
|
+
res.write(chunk);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
res.end();
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error(error);
|
|
327
|
+
res.status(500).json({ error: 'Failed to stream recommendations' });
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
155
331
|
app.listen(3000, () => {
|
|
156
332
|
console.log('Server running on http://localhost:3000');
|
|
157
333
|
});
|
|
158
334
|
```
|
|
159
335
|
|
|
336
|
+
### React Component with Streaming
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { useState } from 'react';
|
|
340
|
+
|
|
341
|
+
function MovieRecommendations() {
|
|
342
|
+
const [output, setOutput] = useState('');
|
|
343
|
+
const [loading, setLoading] = useState(false);
|
|
344
|
+
|
|
345
|
+
const getRecommendations = async () => {
|
|
346
|
+
setLoading(true);
|
|
347
|
+
setOutput('');
|
|
348
|
+
|
|
349
|
+
const response = await fetch('/api/recommendations/stream', {
|
|
350
|
+
method: 'POST',
|
|
351
|
+
headers: { 'Content-Type': 'application/json' },
|
|
352
|
+
body: JSON.stringify({ mood: 'happy', platforms: ['Netflix'] }),
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const reader = response.body?.getReader();
|
|
356
|
+
const decoder = new TextDecoder();
|
|
357
|
+
|
|
358
|
+
while (true) {
|
|
359
|
+
const { done, value } = await reader.read();
|
|
360
|
+
if (done) break;
|
|
361
|
+
|
|
362
|
+
const chunk = decoder.decode(value);
|
|
363
|
+
setOutput(prev => prev + chunk);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
setLoading(false);
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div>
|
|
371
|
+
<button onClick={getRecommendations} disabled={loading}>
|
|
372
|
+
Get Recommendations
|
|
373
|
+
</button>
|
|
374
|
+
<div style={{ whiteSpace: 'pre-wrap' }}>{output}</div>
|
|
375
|
+
</div>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
160
380
|
## Configuration
|
|
161
381
|
|
|
162
382
|
### Environment Variables
|
|
@@ -165,6 +385,17 @@ app.listen(3000, () => {
|
|
|
165
385
|
# Required
|
|
166
386
|
TMDB_API_KEY=your_tmdb_api_key_here
|
|
167
387
|
|
|
388
|
+
# LLM Provider Selection (optional)
|
|
389
|
+
LLM_PROVIDER=gemini # Options: gemini, azure
|
|
390
|
+
|
|
391
|
+
# Option 1: Google Gemini (for AI-formatted output)
|
|
392
|
+
GEMINI_API_KEY=your_gemini_api_key_here
|
|
393
|
+
|
|
394
|
+
# Option 2: Azure OpenAI (for AI-formatted output)
|
|
395
|
+
AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here
|
|
396
|
+
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/
|
|
397
|
+
AZURE_OPENAI_DEPLOYMENT=your_deployment_name
|
|
398
|
+
|
|
168
399
|
# Optional
|
|
169
400
|
TMDB_REGION=CA
|
|
170
401
|
CACHE_TTL=86400
|
|
@@ -172,6 +403,46 @@ MAX_RECOMMENDATIONS=5
|
|
|
172
403
|
MIN_RECOMMENDATIONS=3
|
|
173
404
|
```
|
|
174
405
|
|
|
406
|
+
**Note:** If no LLM API key is provided, the `invoke()` and `stream()` methods will use a fallback formatter.
|
|
407
|
+
|
|
408
|
+
### LLM Provider Configuration
|
|
409
|
+
|
|
410
|
+
The package supports multiple LLM providers for AI-formatted output:
|
|
411
|
+
|
|
412
|
+
#### Google Gemini (Default)
|
|
413
|
+
```typescript
|
|
414
|
+
const agent = MovieAgentFactory.create({
|
|
415
|
+
tmdbApiKey: 'your-tmdb-key',
|
|
416
|
+
llmProvider: 'gemini',
|
|
417
|
+
geminiApiKey: 'your-gemini-key',
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### Azure OpenAI
|
|
422
|
+
```typescript
|
|
423
|
+
const agent = MovieAgentFactory.create({
|
|
424
|
+
tmdbApiKey: 'your-tmdb-key',
|
|
425
|
+
llmProvider: 'azure',
|
|
426
|
+
azureOpenAiApiKey: 'your-azure-key',
|
|
427
|
+
azureOpenAiEndpoint: 'https://your-resource.openai.azure.com/',
|
|
428
|
+
azureOpenAiDeployment: 'your-deployment-name',
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
#### Using Environment Variables
|
|
433
|
+
```bash
|
|
434
|
+
# Set LLM_PROVIDER in .env
|
|
435
|
+
LLM_PROVIDER=azure
|
|
436
|
+
AZURE_OPENAI_API_KEY=your_key
|
|
437
|
+
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
|
|
438
|
+
AZURE_OPENAI_DEPLOYMENT=gpt-4
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
// Automatically uses Azure OpenAI from environment
|
|
443
|
+
const agent = MovieAgentFactory.fromEnv();
|
|
444
|
+
```
|
|
445
|
+
|
|
175
446
|
### Input Parameters
|
|
176
447
|
|
|
177
448
|
```typescript
|
|
@@ -461,4 +732,4 @@ MIT
|
|
|
461
732
|
|
|
462
733
|
- [The Movie Database (TMDb)](https://www.themoviedb.org/) for movie data and streaming availability
|
|
463
734
|
- [LangChain.js](https://js.langchain.com/) for agent framework
|
|
464
|
-
- [OpenAI](https://
|
|
735
|
+
- [Google Gemini](https://ai.google.dev/) and [Azure OpenAI](https://azure.microsoft.com/en-us/products/ai-services/openai-service) for LLM capabilities
|
package/bin/movie-agent
CHANGED
|
@@ -10,6 +10,7 @@ const fs = require('fs');
|
|
|
10
10
|
function parseArgs() {
|
|
11
11
|
const args = process.argv.slice(2);
|
|
12
12
|
const input = {};
|
|
13
|
+
let useStreaming = false;
|
|
13
14
|
|
|
14
15
|
for (let i = 0; i < args.length; i++) {
|
|
15
16
|
const arg = args[i];
|
|
@@ -75,13 +76,15 @@ function parseArgs() {
|
|
|
75
76
|
printUsage();
|
|
76
77
|
process.exit(1);
|
|
77
78
|
}
|
|
79
|
+
} else if (arg === '--stream') {
|
|
80
|
+
useStreaming = true;
|
|
78
81
|
} else if (arg === '--help' || arg === '-h') {
|
|
79
82
|
printUsage();
|
|
80
83
|
process.exit(0);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
return input;
|
|
87
|
+
return { input, useStreaming };
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
/**
|
|
@@ -100,11 +103,12 @@ Options:
|
|
|
100
103
|
--year <number> Specific release year
|
|
101
104
|
--yearFrom <number> Release year range start
|
|
102
105
|
--yearTo <number> Release year range end
|
|
106
|
+
--stream Enable streaming output (real-time generation)
|
|
103
107
|
--help, -h Show this help message
|
|
104
108
|
|
|
105
109
|
Examples:
|
|
106
110
|
movie-agent --mood excited --platforms Netflix
|
|
107
|
-
movie-agent --genre Action,Thriller --runtimeMax 120
|
|
111
|
+
movie-agent --genre Action,Thriller --runtimeMax 120 --stream
|
|
108
112
|
movie-agent --mood relaxed --yearFrom 2020 --yearTo 2023
|
|
109
113
|
`);
|
|
110
114
|
}
|
|
@@ -173,10 +177,15 @@ Or create a .env.development file with:
|
|
|
173
177
|
process.exit(1);
|
|
174
178
|
}
|
|
175
179
|
|
|
180
|
+
// Check for Gemini API key (optional, agent will work without it)
|
|
181
|
+
if (!process.env.GEMINI_API_KEY) {
|
|
182
|
+
console.warn(`\nā ļø Warning: Gemini API key not found. Using fallback formatting.\n`);
|
|
183
|
+
}
|
|
184
|
+
|
|
176
185
|
// Now it's safe to load the agent module
|
|
177
186
|
const { MovieAgent } = require('../dist/agent');
|
|
178
187
|
|
|
179
|
-
const input = parseArgs();
|
|
188
|
+
const { input, useStreaming } = parseArgs();
|
|
180
189
|
|
|
181
190
|
// Show help if no arguments provided
|
|
182
191
|
if (Object.keys(input).length === 0) {
|
|
@@ -184,19 +193,35 @@ Or create a .env.development file with:
|
|
|
184
193
|
process.exit(0);
|
|
185
194
|
}
|
|
186
195
|
|
|
187
|
-
console.log('
|
|
196
|
+
console.log('\\nš Finding movie recommendations...\\n');
|
|
188
197
|
|
|
189
198
|
const agent = new MovieAgent();
|
|
190
|
-
const response = await agent.getRecommendations(input);
|
|
191
199
|
|
|
192
|
-
|
|
193
|
-
|
|
200
|
+
if (useStreaming) {
|
|
201
|
+
// Use streaming output
|
|
202
|
+
const result = await agent.stream(input, (chunk) => {
|
|
203
|
+
process.stdout.write(chunk);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (result && 'error' in result) {
|
|
207
|
+
throw new Error(result.message);
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
// Use non-streaming output
|
|
211
|
+
const output = await agent.invoke(input);
|
|
212
|
+
|
|
213
|
+
if (typeof output === 'object' && 'error' in output) {
|
|
214
|
+
throw new Error(output.message);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
console.log(output);
|
|
218
|
+
}
|
|
194
219
|
|
|
195
220
|
} catch (error) {
|
|
196
221
|
console.error('\nā Error:', error.message);
|
|
197
222
|
|
|
198
223
|
if (error.message.includes('API') || error.message.includes('network')) {
|
|
199
|
-
console.error('\nPlease check your internet connection and
|
|
224
|
+
console.error('\nPlease check your internet connection and API keys.');
|
|
200
225
|
} else if (error.message.includes('Invalid') || error.message.includes('validation')) {
|
|
201
226
|
console.error('\nPlease check your input parameters and try again.');
|
|
202
227
|
console.error('Use --help for usage information.');
|
package/dist/agent.d.ts
CHANGED
|
@@ -6,12 +6,20 @@ import TmdbApiClient from './tmdbApi';
|
|
|
6
6
|
export declare class MovieAgent {
|
|
7
7
|
private tmdbClient;
|
|
8
8
|
private logger;
|
|
9
|
+
private llmService;
|
|
9
10
|
/**
|
|
10
11
|
* Creates a new MovieAgent instance
|
|
11
12
|
* @param tmdbClient - Optional TMDb API client for testing
|
|
12
13
|
* @param logger - Optional logger function for debugging
|
|
14
|
+
* @param enableLLM - Whether to enable LLM formatting (default: true if GEMINI_API_KEY is set)
|
|
15
|
+
* @param llmProvider - LLM provider to use ('gemini' or 'azure')
|
|
16
|
+
* @param llmApiKey - API key for the LLM provider
|
|
17
|
+
* @param azureConfig - Azure OpenAI configuration (endpoint and deployment)
|
|
13
18
|
*/
|
|
14
|
-
constructor(tmdbClient?: TmdbApiClient, logger?: (message: string) => void
|
|
19
|
+
constructor(tmdbClient?: TmdbApiClient, logger?: (message: string) => void, enableLLM?: boolean, llmProvider?: 'gemini' | 'azure', llmApiKey?: string, azureConfig?: {
|
|
20
|
+
endpoint?: string;
|
|
21
|
+
deployment?: string;
|
|
22
|
+
});
|
|
15
23
|
/**
|
|
16
24
|
* Gets movie recommendations based on user input
|
|
17
25
|
* @param input - User input with mood, platforms, genres, runtime, and year preferences
|
|
@@ -78,6 +86,23 @@ export declare class MovieAgent {
|
|
|
78
86
|
* @returns Array of formatted recommendations
|
|
79
87
|
*/
|
|
80
88
|
private formatRecommendations;
|
|
89
|
+
/**
|
|
90
|
+
* Get recommendations with AI-formatted output (invoke mode)
|
|
91
|
+
* @param input - User input with mood, platforms, genres, runtime, and year preferences
|
|
92
|
+
* @returns Promise resolving to AI-formatted string output or error response
|
|
93
|
+
*/
|
|
94
|
+
invoke(input: UserInput): Promise<string | ErrorResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* Get recommendations with AI-formatted streaming output
|
|
97
|
+
* @param input - User input with mood, platforms, genres, runtime, and year preferences
|
|
98
|
+
* @param onChunk - Callback function called for each chunk of streamed content
|
|
99
|
+
* @returns Promise resolving when streaming is complete, or error response
|
|
100
|
+
*/
|
|
101
|
+
stream(input: UserInput, onChunk: (chunk: string) => void): Promise<void | ErrorResponse>;
|
|
102
|
+
/**
|
|
103
|
+
* Fallback formatting when LLM is not available
|
|
104
|
+
*/
|
|
105
|
+
private fallbackFormat;
|
|
81
106
|
/**
|
|
82
107
|
* Generates a match reason for a movie
|
|
83
108
|
* @param movie - Movie to explain
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,aAAa,EAGb,aAAa,EACd,MAAM,SAAS,CAAC;AASjB,OAAO,aAA+B,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,aAAa,EAGb,aAAa,EACd,MAAM,SAAS,CAAC;AASjB,OAAO,aAA+B,MAAM,WAAW,CAAC;AAcxD;;GAEG;AACH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.js
CHANGED
|
@@ -12,6 +12,7 @@ const providers_1 = require("./providers");
|
|
|
12
12
|
const filters_1 = require("./filters");
|
|
13
13
|
const ranking_1 = require("./ranking");
|
|
14
14
|
const format_1 = require("./format");
|
|
15
|
+
const llm_1 = require("./llm");
|
|
15
16
|
/**
|
|
16
17
|
* MovieAgent orchestrates the full recommendation pipeline
|
|
17
18
|
*/
|
|
@@ -20,11 +21,20 @@ class MovieAgent {
|
|
|
20
21
|
* Creates a new MovieAgent instance
|
|
21
22
|
* @param tmdbClient - Optional TMDb API client for testing
|
|
22
23
|
* @param logger - Optional logger function for debugging
|
|
24
|
+
* @param enableLLM - Whether to enable LLM formatting (default: true if GEMINI_API_KEY is set)
|
|
25
|
+
* @param llmProvider - LLM provider to use ('gemini' or 'azure')
|
|
26
|
+
* @param llmApiKey - API key for the LLM provider
|
|
27
|
+
* @param azureConfig - Azure OpenAI configuration (endpoint and deployment)
|
|
23
28
|
*/
|
|
24
|
-
constructor(tmdbClient, logger) {
|
|
29
|
+
constructor(tmdbClient, logger, enableLLM, llmProvider, llmApiKey, azureConfig) {
|
|
25
30
|
this.tmdbClient = tmdbClient ?? new tmdbApi_1.default();
|
|
26
31
|
this.logger =
|
|
27
32
|
logger ?? ((message) => console.log(`[MovieAgent] ${message}`));
|
|
33
|
+
// Initialize LLM service if enabled and API key is available
|
|
34
|
+
const shouldEnableLLM = enableLLM ?? !!process.env.GEMINI_API_KEY;
|
|
35
|
+
this.llmService = shouldEnableLLM
|
|
36
|
+
? new llm_1.LLMService(llmApiKey, llmProvider, azureConfig)
|
|
37
|
+
: null;
|
|
28
38
|
}
|
|
29
39
|
/**
|
|
30
40
|
* Gets movie recommendations based on user input
|
|
@@ -328,6 +338,72 @@ class MovieAgent {
|
|
|
328
338
|
}, streamingPlatforms, reason);
|
|
329
339
|
});
|
|
330
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Get recommendations with AI-formatted output (invoke mode)
|
|
343
|
+
* @param input - User input with mood, platforms, genres, runtime, and year preferences
|
|
344
|
+
* @returns Promise resolving to AI-formatted string output or error response
|
|
345
|
+
*/
|
|
346
|
+
async invoke(input) {
|
|
347
|
+
const response = await this.getRecommendations(input);
|
|
348
|
+
if ('error' in response) {
|
|
349
|
+
return response;
|
|
350
|
+
}
|
|
351
|
+
// Use LLM if available, otherwise use fallback formatting
|
|
352
|
+
if (this.llmService) {
|
|
353
|
+
try {
|
|
354
|
+
return await this.llmService.formatRecommendations(response, input);
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
this.logger(`LLM formatting failed, using fallback: ${error}`);
|
|
358
|
+
return this.fallbackFormat(response);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return this.fallbackFormat(response);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get recommendations with AI-formatted streaming output
|
|
365
|
+
* @param input - User input with mood, platforms, genres, runtime, and year preferences
|
|
366
|
+
* @param onChunk - Callback function called for each chunk of streamed content
|
|
367
|
+
* @returns Promise resolving when streaming is complete, or error response
|
|
368
|
+
*/
|
|
369
|
+
async stream(input, onChunk) {
|
|
370
|
+
const response = await this.getRecommendations(input);
|
|
371
|
+
if ('error' in response) {
|
|
372
|
+
return response;
|
|
373
|
+
}
|
|
374
|
+
// Use LLM streaming if available, otherwise output fallback immediately
|
|
375
|
+
if (this.llmService) {
|
|
376
|
+
try {
|
|
377
|
+
await this.llmService.formatRecommendationsStream(response, input, onChunk);
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
this.logger(`LLM streaming failed, using fallback: ${error}`);
|
|
381
|
+
onChunk(this.fallbackFormat(response));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
onChunk(this.fallbackFormat(response));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Fallback formatting when LLM is not available
|
|
390
|
+
*/
|
|
391
|
+
fallbackFormat(response) {
|
|
392
|
+
let output = '\\nš¬ Movie Recommendations\\n\\n';
|
|
393
|
+
response.recommendations.forEach((movie, index) => {
|
|
394
|
+
output += `${index + 1}. **${movie.title}** (${movie.releaseYear}) ⢠${movie.runtime} min\\n`;
|
|
395
|
+
output += ` Genres: ${movie.genres.join(', ')}\\n\\n`;
|
|
396
|
+
output += ` ${movie.description}\\n\\n`;
|
|
397
|
+
const platforms = movie.streamingPlatforms
|
|
398
|
+
.filter(p => p.available)
|
|
399
|
+
.map(p => p.name);
|
|
400
|
+
if (platforms.length > 0) {
|
|
401
|
+
output += ` šŗ Available on: ${platforms.join(', ')}\\n`;
|
|
402
|
+
}
|
|
403
|
+
output += ` ⨠Why: ${movie.matchReason}\\n\\n`;
|
|
404
|
+
});
|
|
405
|
+
return output;
|
|
406
|
+
}
|
|
331
407
|
/**
|
|
332
408
|
* Generates a match reason for a movie
|
|
333
409
|
* @param movie - Movie to explain
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;AAQA,yCAKoB;AACpB,iCAAsC;AACtC,yCAA2D;AAC3D,wDAAwD;AACxD,2CAAmD;AACnD,uCAAwD;AACxD,uCAAoE;AACpE,qCAA4D;AAS5D;;GAEG;AACH,MAAa,UAAU;IAIrB;;;;OAIG;IACH,YAAY,UAA0B,EAAE,MAAkC;QACxE,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,iBAAa,EAAE,CAAC;QACpD,IAAI,CAAC,MAAM;YACT,MAAM,IAAI,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CACtB,KAAgB;QAEhB,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC;YAEhD,yBAAyB;YACz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AACH,qBAAa,iBAAiB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU;IAqDnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAQ,GAAG,UAAU;CAiC1C"}
|
package/dist/factory.js
CHANGED
|
@@ -49,8 +49,30 @@ class MovieAgentFactory {
|
|
|
49
49
|
const logger = config.debug
|
|
50
50
|
? (message) => console.log(`[MovieAgent] ${message}`)
|
|
51
51
|
: undefined;
|
|
52
|
+
// Determine LLM enablement and get the appropriate API key
|
|
53
|
+
const llmProvider = config.llmProvider;
|
|
54
|
+
let llmApiKey;
|
|
55
|
+
let enableLLM = false;
|
|
56
|
+
let azureConfig;
|
|
57
|
+
if (llmProvider === 'azure' && config.azureOpenAiApiKey) {
|
|
58
|
+
llmApiKey = config.azureOpenAiApiKey;
|
|
59
|
+
azureConfig = {
|
|
60
|
+
endpoint: config.azureOpenAiEndpoint,
|
|
61
|
+
deployment: config.azureOpenAiDeployment,
|
|
62
|
+
};
|
|
63
|
+
enableLLM = true;
|
|
64
|
+
}
|
|
65
|
+
else if (llmProvider === 'gemini' && config.geminiApiKey) {
|
|
66
|
+
llmApiKey = config.geminiApiKey;
|
|
67
|
+
enableLLM = true;
|
|
68
|
+
}
|
|
69
|
+
else if (config.geminiApiKey) {
|
|
70
|
+
// Default to Gemini if API key is provided but no provider specified
|
|
71
|
+
llmApiKey = config.geminiApiKey;
|
|
72
|
+
enableLLM = true;
|
|
73
|
+
}
|
|
52
74
|
// Create and return MovieAgent instance
|
|
53
|
-
return new agent_1.MovieAgent(tmdbClient, logger);
|
|
75
|
+
return new agent_1.MovieAgent(tmdbClient, logger, enableLLM, llmProvider, llmApiKey, azureConfig);
|
|
54
76
|
}
|
|
55
77
|
/**
|
|
56
78
|
* Creates a MovieAgent instance from environment variables
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;;;;AAAA,iBAAiB;AACjB,mCAAqC;AACrC,wDAAsC;AA4BtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,iBAAiB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,MAAwB;QACpC,kCAAkC;QAClC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;QACJ,CAAC;QAED,qDAAqD;QACrD,MAAM,UAAU,GAAG,IAAI,iBAAa,CAClC,MAAM,CAAC,WAAW,IAAI,8BAA8B,EACpD,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,IAAI,IAAI,CAC1B,CAAC;QAEF,6CAA6C;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK;YACzB,CAAC,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,OAAO,EAAE,CAAC;YAC7D,CAAC,CAAC,SAAS,CAAC;QAEd,
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;;;;AAAA,iBAAiB;AACjB,mCAAqC;AACrC,wDAAsC;AA4BtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,iBAAiB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,MAAwB;QACpC,kCAAkC;QAClC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;QACJ,CAAC;QAED,qDAAqD;QACrD,MAAM,UAAU,GAAG,IAAI,iBAAa,CAClC,MAAM,CAAC,WAAW,IAAI,8BAA8B,EACpD,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,IAAI,IAA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AAC;YAChB,MAAM,IAAI,KAAK,CACb,iDAAiD;gBAC/C,iDAAiD,CACpD,CAAC;QACJ,CAAC;QAED,OAAO,iBAAiB,CAAC,MAAM,CAAC;YAC9B,UAAU;YACV,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;YACtC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;YACnC,WAAW,EACR,OAAO,CAAC,GAAG,CAAC,YAAmC,IAAI,SAAS;YAC/D,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACxC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB;YACnD,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YACtD,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;YAC1D,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACxC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;gBAC7B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC;gBACrC,CAAC,CAAC,SAAS;YACb,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;gBACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;gBAC/C,CAAC,CAAC,SAAS;YACb,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;gBACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;gBAC/C,CAAC,CAAC,SAAS;YACb,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA/HD,8CA+HC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { MovieAgent } from './agent';
|
|
|
2
2
|
export { MovieAgentFactory, MovieAgentConfig } from './factory';
|
|
3
3
|
export { UserInput, AgentResponse, MovieRecommendation, StreamingPlatform, ErrorResponse, } from './types';
|
|
4
4
|
export { default as TmdbApiClient } from './tmdbApi';
|
|
5
|
+
export { LLMService, getLLMService } from './llm';
|
|
5
6
|
export { MovieAgentFactory as default } from './factory';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGhE,OAAO,EACL,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGhE,OAAO,EACL,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.default = exports.TmdbApiClient = exports.MovieAgentFactory = exports.MovieAgent = void 0;
|
|
7
|
+
exports.default = exports.getLLMService = exports.LLMService = exports.TmdbApiClient = exports.MovieAgentFactory = exports.MovieAgent = void 0;
|
|
8
8
|
// Export the main MovieAgent class
|
|
9
9
|
var agent_1 = require("./agent");
|
|
10
10
|
Object.defineProperty(exports, "MovieAgent", { enumerable: true, get: function () { return agent_1.MovieAgent; } });
|
|
@@ -14,6 +14,10 @@ Object.defineProperty(exports, "MovieAgentFactory", { enumerable: true, get: fun
|
|
|
14
14
|
// Export TMDb API client for advanced use cases
|
|
15
15
|
var tmdbApi_1 = require("./tmdbApi");
|
|
16
16
|
Object.defineProperty(exports, "TmdbApiClient", { enumerable: true, get: function () { return __importDefault(tmdbApi_1).default; } });
|
|
17
|
+
// Export LLM service for advanced use cases
|
|
18
|
+
var llm_1 = require("./llm");
|
|
19
|
+
Object.defineProperty(exports, "LLMService", { enumerable: true, get: function () { return llm_1.LLMService; } });
|
|
20
|
+
Object.defineProperty(exports, "getLLMService", { enumerable: true, get: function () { return llm_1.getLLMService; } });
|
|
17
21
|
// Default export is the factory for convenience
|
|
18
22
|
var factory_2 = require("./factory");
|
|
19
23
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return factory_2.MovieAgentFactory; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,8DAA8D;;;;;;AAE9D,mCAAmC;AACnC,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AAEnB,4CAA4C;AAC5C,qCAAgE;AAAvD,4GAAA,iBAAiB,OAAA;AAW1B,gDAAgD;AAChD,qCAAqD;AAA5C,yHAAA,OAAO,OAAiB;AAEjC,gDAAgD;AAChD,qCAAyD;AAAhD,kGAAA,iBAAiB,OAAW"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,8DAA8D;;;;;;AAE9D,mCAAmC;AACnC,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AAEnB,4CAA4C;AAC5C,qCAAgE;AAAvD,4GAAA,iBAAiB,OAAA;AAW1B,gDAAgD;AAChD,qCAAqD;AAA5C,yHAAA,OAAO,OAAiB;AAEjC,4CAA4C;AAC5C,6BAAkD;AAAzC,iGAAA,UAAU,OAAA;AAAE,oGAAA,aAAa,OAAA;AAElC,gDAAgD;AAChD,qCAAyD;AAAhD,kGAAA,iBAAiB,OAAW"}
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AgentResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* LLM service for generating formatted movie recommendation output
|
|
4
|
+
*/
|
|
5
|
+
export declare class LLMService {
|
|
6
|
+
private model;
|
|
7
|
+
private chain;
|
|
8
|
+
constructor(apiKey?: string, provider?: 'gemini' | 'azure', azureConfig?: {
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
deployment?: string;
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Format movie recommendations using LLM (non-streaming)
|
|
14
|
+
* @param response - Agent response with recommendations
|
|
15
|
+
* @param userInput - Original user input for context
|
|
16
|
+
* @returns Formatted markdown string
|
|
17
|
+
*/
|
|
18
|
+
formatRecommendations(response: AgentResponse, userInput: any): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Format movie recommendations using LLM with streaming
|
|
21
|
+
* @param response - Agent response with recommendations
|
|
22
|
+
* @param userInput - Original user input for context
|
|
23
|
+
* @param onChunk - Callback function called for each chunk of streamed content
|
|
24
|
+
* @returns Promise that resolves when streaming is complete
|
|
25
|
+
*/
|
|
26
|
+
formatRecommendationsStream(response: AgentResponse, userInput: any, onChunk: (chunk: string) => void): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Fallback formatting if LLM fails
|
|
29
|
+
*/
|
|
30
|
+
private fallbackFormat;
|
|
31
|
+
}
|
|
32
|
+
export declare function getLLMService(provider?: 'gemini' | 'azure'): LLMService;
|
|
33
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAA2C;IACxD,OAAO,CAAC,KAAK,CAAM;gBAGjB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,EAC7B,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IAuEH;;;;;OAKG;IACG,qBAAqB,CACzB,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,GAAG,GACb,OAAO,CAAC,MAAM,CAAC;IAiDlB;;;;;;OAMG;IACG,2BAA2B,CAC/B,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,GAAG,EACd,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAC/B,OAAO,CAAC,IAAI,CAAC;IA4DhB;;OAEG;IACH,OAAO,CAAC,cAAc;CAqBvB;AAOD,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAKvE"}
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
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.LLMService = void 0;
|
|
7
|
+
exports.getLLMService = getLLMService;
|
|
8
|
+
// src/llm.ts
|
|
9
|
+
const google_genai_1 = require("@langchain/google-genai");
|
|
10
|
+
const openai_1 = require("@langchain/openai");
|
|
11
|
+
const prompts_1 = require("@langchain/core/prompts");
|
|
12
|
+
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
13
|
+
const config_1 = __importDefault(require("./config"));
|
|
14
|
+
/**
|
|
15
|
+
* LLM service for generating formatted movie recommendation output
|
|
16
|
+
*/
|
|
17
|
+
class LLMService {
|
|
18
|
+
constructor(apiKey, provider, azureConfig) {
|
|
19
|
+
const llmProvider = provider || config_1.default.LLM_PROVIDER;
|
|
20
|
+
if (llmProvider === 'azure') {
|
|
21
|
+
// Azure OpenAI Configuration
|
|
22
|
+
const azureApiKey = apiKey || config_1.default.AZURE_OPENAI_API_KEY;
|
|
23
|
+
const azureEndpoint = azureConfig?.endpoint || config_1.default.AZURE_OPENAI_ENDPOINT;
|
|
24
|
+
const azureDeployment = azureConfig?.deployment || config_1.default.AZURE_OPENAI_DEPLOYMENT;
|
|
25
|
+
if (!azureApiKey || !azureEndpoint || !azureDeployment) {
|
|
26
|
+
throw new Error('AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT are required for Azure OpenAI');
|
|
27
|
+
}
|
|
28
|
+
this.model = new openai_1.AzureChatOpenAI({
|
|
29
|
+
azureOpenAIApiKey: azureApiKey,
|
|
30
|
+
azureOpenAIApiInstanceName: azureEndpoint
|
|
31
|
+
.replace(/^https?:\/\//, '')
|
|
32
|
+
.replace(/\.openai\.azure\.com\/?$/, ''),
|
|
33
|
+
azureOpenAIApiDeploymentName: azureDeployment,
|
|
34
|
+
azureOpenAIApiVersion: '2024-08-01-preview',
|
|
35
|
+
temperature: 0.7,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Gemini Configuration (default)
|
|
40
|
+
const geminiApiKey = apiKey || config_1.default.GEMINI_API_KEY;
|
|
41
|
+
if (!geminiApiKey) {
|
|
42
|
+
throw new Error('GEMINI_API_KEY is required for LLM service');
|
|
43
|
+
}
|
|
44
|
+
this.model = new google_genai_1.ChatGoogleGenerativeAI({
|
|
45
|
+
apiKey: geminiApiKey,
|
|
46
|
+
model: 'gemini-2.5-flash',
|
|
47
|
+
temperature: 0.7,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// Create the prompt template
|
|
51
|
+
const promptTemplate = prompts_1.PromptTemplate.fromTemplate(`
|
|
52
|
+
You are a friendly movie recommendation assistant. Format the following movie recommendations in an engaging, readable way.
|
|
53
|
+
|
|
54
|
+
User Input: {userInput}
|
|
55
|
+
|
|
56
|
+
Movie Recommendations:
|
|
57
|
+
{recommendations}
|
|
58
|
+
|
|
59
|
+
Instructions:
|
|
60
|
+
- Create a warm, conversational introduction
|
|
61
|
+
- For each movie, include:
|
|
62
|
+
* Title, year, and runtime
|
|
63
|
+
* Genres
|
|
64
|
+
* A compelling description
|
|
65
|
+
* Available streaming platforms with emoji šŗ
|
|
66
|
+
* A brief explanation of why it matches the user's preferences (⨠Why:)
|
|
67
|
+
- Use markdown formatting (bold, lists, etc.)
|
|
68
|
+
- Add visual separators between movies
|
|
69
|
+
- Keep it concise but engaging
|
|
70
|
+
- Use emojis to make it more visually appealing
|
|
71
|
+
|
|
72
|
+
Generate the formatted output:
|
|
73
|
+
`);
|
|
74
|
+
// Create the chain: prompt -> model -> output parser
|
|
75
|
+
this.chain = promptTemplate.pipe(this.model).pipe(new output_parsers_1.StringOutputParser());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Format movie recommendations using LLM (non-streaming)
|
|
79
|
+
* @param response - Agent response with recommendations
|
|
80
|
+
* @param userInput - Original user input for context
|
|
81
|
+
* @returns Formatted markdown string
|
|
82
|
+
*/
|
|
83
|
+
async formatRecommendations(response, userInput) {
|
|
84
|
+
// Prepare the recommendations data
|
|
85
|
+
const recommendationsText = response.recommendations
|
|
86
|
+
.map((movie, index) => {
|
|
87
|
+
const platforms = movie.streamingPlatforms
|
|
88
|
+
.filter(p => p.available)
|
|
89
|
+
.map(p => p.name)
|
|
90
|
+
.join(', ');
|
|
91
|
+
return `
|
|
92
|
+
${index + 1}. ${movie.title} (${movie.releaseYear})
|
|
93
|
+
- Runtime: ${movie.runtime} minutes
|
|
94
|
+
- Genres: ${movie.genres.join(', ')}
|
|
95
|
+
- Description: ${movie.description}
|
|
96
|
+
- Available on: ${platforms || 'No streaming availability'}
|
|
97
|
+
- Match reason: ${movie.matchReason}
|
|
98
|
+
`;
|
|
99
|
+
})
|
|
100
|
+
.join('\n');
|
|
101
|
+
// Format user input
|
|
102
|
+
const userInputText = JSON.stringify(userInput, null, 2);
|
|
103
|
+
// Generate formatted output using LLM with timeout
|
|
104
|
+
try {
|
|
105
|
+
const timeoutMs = 15000; // 15 second timeout
|
|
106
|
+
const startTime = Date.now();
|
|
107
|
+
const formattedOutput = await Promise.race([
|
|
108
|
+
this.chain.invoke({
|
|
109
|
+
userInput: userInputText,
|
|
110
|
+
recommendations: recommendationsText,
|
|
111
|
+
}),
|
|
112
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('LLM request timeout')), timeoutMs)),
|
|
113
|
+
]);
|
|
114
|
+
const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
115
|
+
console.log(`ā LLM formatting completed in ${elapsedTime}s\n`);
|
|
116
|
+
return formattedOutput;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error('LLM formatting error:', error);
|
|
120
|
+
// Fallback to basic formatting if LLM fails
|
|
121
|
+
return this.fallbackFormat(response);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Format movie recommendations using LLM with streaming
|
|
126
|
+
* @param response - Agent response with recommendations
|
|
127
|
+
* @param userInput - Original user input for context
|
|
128
|
+
* @param onChunk - Callback function called for each chunk of streamed content
|
|
129
|
+
* @returns Promise that resolves when streaming is complete
|
|
130
|
+
*/
|
|
131
|
+
async formatRecommendationsStream(response, userInput, onChunk) {
|
|
132
|
+
// Prepare the recommendations data
|
|
133
|
+
const recommendationsText = response.recommendations
|
|
134
|
+
.map((movie, index) => {
|
|
135
|
+
const platforms = movie.streamingPlatforms
|
|
136
|
+
.filter(p => p.available)
|
|
137
|
+
.map(p => p.name)
|
|
138
|
+
.join(', ');
|
|
139
|
+
return `
|
|
140
|
+
${index + 1}. ${movie.title} (${movie.releaseYear})
|
|
141
|
+
- Runtime: ${movie.runtime} minutes
|
|
142
|
+
- Genres: ${movie.genres.join(', ')}
|
|
143
|
+
- Description: ${movie.description}
|
|
144
|
+
- Available on: ${platforms || 'No streaming availability'}
|
|
145
|
+
- Match reason: ${movie.matchReason}
|
|
146
|
+
`;
|
|
147
|
+
})
|
|
148
|
+
.join('\n');
|
|
149
|
+
// Format user input
|
|
150
|
+
const userInputText = JSON.stringify(userInput, null, 2);
|
|
151
|
+
try {
|
|
152
|
+
const timeoutMs = 15000; // 15 second timeout
|
|
153
|
+
const startTime = Date.now();
|
|
154
|
+
// Create a promise that will handle the streaming
|
|
155
|
+
const streamPromise = (async () => {
|
|
156
|
+
const stream = await this.chain.stream({
|
|
157
|
+
userInput: userInputText,
|
|
158
|
+
recommendations: recommendationsText,
|
|
159
|
+
});
|
|
160
|
+
for await (const chunk of stream) {
|
|
161
|
+
onChunk(chunk);
|
|
162
|
+
}
|
|
163
|
+
})();
|
|
164
|
+
// Race between streaming and timeout
|
|
165
|
+
await Promise.race([
|
|
166
|
+
streamPromise,
|
|
167
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('LLM streaming timeout')), timeoutMs)),
|
|
168
|
+
]);
|
|
169
|
+
const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
170
|
+
console.log(`\nā LLM streaming completed in ${elapsedTime}s\n`);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error('\nLLM streaming error:', error);
|
|
174
|
+
// Fallback to basic formatting if LLM fails
|
|
175
|
+
const fallback = this.fallbackFormat(response);
|
|
176
|
+
onChunk(fallback);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Fallback formatting if LLM fails
|
|
181
|
+
*/
|
|
182
|
+
fallbackFormat(response) {
|
|
183
|
+
let output = '\nš¬ Movie Recommendations\n\n';
|
|
184
|
+
response.recommendations.forEach((movie, index) => {
|
|
185
|
+
output += `${index + 1}. **${movie.title}** (${movie.releaseYear}) ⢠${movie.runtime} min\n`;
|
|
186
|
+
output += ` Genres: ${movie.genres.join(', ')}\n\n`;
|
|
187
|
+
output += ` ${movie.description}\n\n`;
|
|
188
|
+
const platforms = movie.streamingPlatforms
|
|
189
|
+
.filter(p => p.available)
|
|
190
|
+
.map(p => p.name);
|
|
191
|
+
if (platforms.length > 0) {
|
|
192
|
+
output += ` šŗ Available on: ${platforms.join(', ')}\n`;
|
|
193
|
+
}
|
|
194
|
+
output += ` ⨠Why: ${movie.matchReason}\n\n`;
|
|
195
|
+
});
|
|
196
|
+
return output;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.LLMService = LLMService;
|
|
200
|
+
/**
|
|
201
|
+
* Create and export a singleton instance
|
|
202
|
+
*/
|
|
203
|
+
let llmServiceInstance = null;
|
|
204
|
+
function getLLMService(provider) {
|
|
205
|
+
if (!llmServiceInstance) {
|
|
206
|
+
llmServiceInstance = new LLMService(undefined, provider);
|
|
207
|
+
}
|
|
208
|
+
return llmServiceInstance;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=llm.js.map
|
package/dist/llm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":";;;;;;AA4PA,sCAKC;AAjQD,aAAa;AACb,0DAAiE;AACjE,8CAAoD;AACpD,qDAAyD;AACzD,mEAAoE;AAEpE,sDAA8B;AAE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,EAAE,CAAC;QACxB,kBAAkB,GAAG,IAAI,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "movie-agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Movie Agent - A TypeScript-based movie recommendation agent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -67,6 +67,9 @@
|
|
|
67
67
|
"typescript": "^5.3.3"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
+
"@langchain/core": "^1.1.7",
|
|
71
|
+
"@langchain/google-genai": "^2.1.2",
|
|
72
|
+
"@langchain/openai": "^1.2.0",
|
|
70
73
|
"dotenv": "^16.4.5"
|
|
71
74
|
}
|
|
72
75
|
}
|