|
1 | 1 | import type { LanguageModelUsage } from 'ai';
|
2 |
| -import { expect, test } from 'vitest'; |
| 2 | +import { expect, test, vi } from 'vitest'; |
| 3 | +import * as run from '../engine/runPrompt'; |
3 | 4 | import {
|
4 | 5 | LitLytics,
|
5 | 6 | OUTPUT_ID,
|
6 | 7 | type Doc,
|
| 8 | + type LLMArgs, |
7 | 9 | type Pipeline,
|
8 | 10 | type StepInput,
|
9 | 11 | } from '../litlytics';
|
@@ -229,3 +231,54 @@ test('should generate suggested tasks for current pipeline', async () => {
|
229 | 231 | const newNonTestDoc = litlytics.docs.find((d) => d.id === docNonTest.id);
|
230 | 232 | expect(newNonTestDoc?.summary).toBeUndefined();
|
231 | 233 | });
|
| 234 | + |
| 235 | +test('should pass llm args when running prompt', async () => { |
| 236 | + const testArgs: LLMArgs = { |
| 237 | + temperature: 0.5, |
| 238 | + maxTokens: 1000, |
| 239 | + }; |
| 240 | + const litlytics = new LitLytics({ |
| 241 | + provider: 'openai', |
| 242 | + model: 'test', |
| 243 | + key: 'test', |
| 244 | + llmArgs: testArgs, |
| 245 | + }); |
| 246 | + litlytics.pipeline.pipelineDescription = 'test description'; |
| 247 | + |
| 248 | + const testResult = `Step name: Generate Title and Description |
| 249 | +Step type: llm |
| 250 | +Step input: doc |
| 251 | +Step description: Generate an Etsy product title and description based on the provided document describing the product. |
| 252 | +
|
| 253 | +--- |
| 254 | +
|
| 255 | +Step name: Check for Copyrighted Terms |
| 256 | +Step type: llm |
| 257 | +Step input: result |
| 258 | +Step description: Analyze the generated title and description for possible copyrighted terms and suggest edits. |
| 259 | +`; |
| 260 | + |
| 261 | + // mock prompt replies |
| 262 | + const spy = vi |
| 263 | + .spyOn(run, 'runPrompt') |
| 264 | + .mockImplementation( |
| 265 | + async ({ |
| 266 | + user, |
| 267 | + args, |
| 268 | + }: { |
| 269 | + system: string; |
| 270 | + user: string; |
| 271 | + args?: LLMArgs; |
| 272 | + }) => { |
| 273 | + expect(args).toEqual(testArgs); |
| 274 | + expect(user).toEqual('test description'); |
| 275 | + return { result: testResult, usage: {} as LanguageModelUsage }; |
| 276 | + } |
| 277 | + ); |
| 278 | + // run generation |
| 279 | + await litlytics.generatePipeline(); |
| 280 | + // check that spy was called |
| 281 | + expect(spy).toHaveBeenCalled(); |
| 282 | + // cleanup |
| 283 | + spy.mockClear(); |
| 284 | +}); |
0 commit comments