llm-fns 1.0.24 → 1.0.25

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.
@@ -1,59 +1,59 @@
1
1
  import { getPromptSummary } from "./util.js";
2
2
  import { LlmFatalError } from "./createLlmClient.js";
3
- import { vi } from "vitest";
4
3
  export function createMockOpenAI(responses) {
5
4
  let callCount = 0;
5
+ const createFn = async (params) => {
6
+ let response;
7
+ const currentCall = callCount + 1;
8
+ const summary = getPromptSummary(params.messages);
9
+ console.log(`\n--- [Mock OpenAI] Call #${currentCall} ---`);
10
+ console.log(`Prompt: ${summary}`);
11
+ if (typeof responses === 'function') {
12
+ response = responses(params.messages);
13
+ if (response === undefined || response === null) {
14
+ throw new LlmFatalError(`[Mock OpenAI] Resolver function returned null/undefined.\n` +
15
+ `Requested Call: #${currentCall}\n` +
16
+ `Prompt Summary: ${summary}\n\n` +
17
+ `Check your mock resolver logic to ensure it returns a valid response for this prompt.`, undefined, params.messages);
18
+ }
19
+ console.log(`Response (Resolver): ${typeof response === 'string' ? response : JSON.stringify(response, null, 2)}`);
20
+ callCount++;
21
+ }
22
+ else {
23
+ if (callCount >= responses.length) {
24
+ throw new LlmFatalError(`[Mock OpenAI] No more responses configured.\n` +
25
+ `Requested Call: #${currentCall}\n` +
26
+ `Configured Responses: ${responses.length}\n` +
27
+ `Prompt Summary: ${summary}\n\n` +
28
+ `Please check responses in your mock configuration array.`, undefined, params.messages);
29
+ }
30
+ response = responses[callCount];
31
+ console.log(`Response (Array[${callCount}]): ${typeof response === 'string' ? response : JSON.stringify(response, null, 2)}`);
32
+ callCount++;
33
+ }
34
+ console.log(`---------------------------------------\n`);
35
+ // If response is a string, wrap it in a standard text message
36
+ if (typeof response === 'string') {
37
+ return {
38
+ id: 'mock-id',
39
+ choices: [{
40
+ message: { content: response }
41
+ }]
42
+ };
43
+ }
44
+ // If response is an object, assume it's a full message object (e.g. for images/audio)
45
+ // or a partial choice object
46
+ return {
47
+ id: 'mock-id',
48
+ choices: [{
49
+ message: response
50
+ }]
51
+ };
52
+ };
6
53
  return {
7
54
  chat: {
8
55
  completions: {
9
- create: vi.fn(async (params) => {
10
- let response;
11
- const currentCall = callCount + 1;
12
- const summary = getPromptSummary(params.messages);
13
- console.log(`\n--- [Mock OpenAI] Call #${currentCall} ---`);
14
- console.log(`Prompt: ${summary}`);
15
- if (typeof responses === 'function') {
16
- response = responses(params.messages);
17
- if (response === undefined || response === null) {
18
- throw new LlmFatalError(`[Mock OpenAI] Resolver function returned null/undefined.\n` +
19
- `Requested Call: #${currentCall}\n` +
20
- `Prompt Summary: ${summary}\n\n` +
21
- `Check your mock resolver logic to ensure it returns a valid response for this prompt.`, undefined, params.messages);
22
- }
23
- console.log(`Response (Resolver): ${typeof response === 'string' ? response : JSON.stringify(response, null, 2)}`);
24
- callCount++;
25
- }
26
- else {
27
- if (callCount >= responses.length) {
28
- throw new LlmFatalError(`[Mock OpenAI] No more responses configured.\n` +
29
- `Requested Call: #${currentCall}\n` +
30
- `Configured Responses: ${responses.length}\n` +
31
- `Prompt Summary: ${summary}\n\n` +
32
- `Please check responses in your mock configuration array.`, undefined, params.messages);
33
- }
34
- response = responses[callCount];
35
- console.log(`Response (Array[${callCount}]): ${typeof response === 'string' ? response : JSON.stringify(response, null, 2)}`);
36
- callCount++;
37
- }
38
- console.log(`---------------------------------------\n`);
39
- // If response is a string, wrap it in a standard text message
40
- if (typeof response === 'string') {
41
- return {
42
- id: 'mock-id',
43
- choices: [{
44
- message: { content: response }
45
- }]
46
- };
47
- }
48
- // If response is an object, assume it's a full message object (e.g. for images/audio)
49
- // or a partial choice object
50
- return {
51
- id: 'mock-id',
52
- choices: [{
53
- message: response
54
- }]
55
- };
56
- })
56
+ create: createFn
57
57
  }
58
58
  }
59
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-fns",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",