Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/ax/dsp/input-object-array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { vi, describe, it, expect } from 'vitest';

import { ax } from '../index.js';
import { f } from './sig.js';

const sig = f()
.input(
'items',
f
.object(
{
id: f.number('Index'),
name: f.string('Name'),
},
'Item'
)
.array()
)
.output(
'classifiedItems',
f
.object(
{
id: f.number('Index'),
label: f.string('Label'),
},
'Classification'
)
.array()
)
.build();

const gen = ax(sig);

import type { AxAIService, AxChatResponse } from '../ai/types.js';

const llm: AxAIService = {
chat: vi.fn().mockResolvedValue({
results: [
{
index: 0,
content:
'Classified Items: [{"id": 0, "label": "A"}, {"id": 1, "label": "B"}]',
},
],
} as AxChatResponse),
embed: vi.fn(),
getOptions: vi.fn().mockReturnValue({}),
setOptions: vi.fn(),
getName: vi.fn(),
getFeatures: vi.fn(),
getModelList: vi.fn(),
getMetrics: vi.fn(),
getLogger: vi.fn(),
getLastUsedChatModel: vi.fn(),
getLastUsedEmbedModel: vi.fn(),
getLastUsedModelConfig: vi.fn(),
getId: vi.fn(),
};

describe('f.object().array() on inputs', () => {
it('should not throw a validation error for valid input', async () => {
const result = await gen.forward(llm, {
items: [
{ id: 0, name: 'Foo' },
{ id: 1, name: 'Bar' },
],
});
expect(result.classifiedItems).toEqual([
{ id: 0, label: 'A' },
{ id: 1, label: 'B' },
]);
});
});
2 changes: 2 additions & 0 deletions src/ax/dsp/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const validateValue = (
return val instanceof Date || typeof val === 'string';
case 'json':
return typeof val === 'object' || typeof val === 'string';
case 'object':
return typeof val === 'object';
default:
return false; // Unknown or unsupported type
}
Expand Down
62 changes: 0 additions & 62 deletions src/ax/package-exports.test.ts

This file was deleted.