Skip to content

Commit

Permalink
feat: new classification type in dspy signature
Browse files Browse the repository at this point in the history
  • Loading branch information
dosco committed Oct 11, 2024
1 parent 01d10f3 commit 3816f80
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 1,842 deletions.
70 changes: 0 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"prettier": "^3.2.5",
"release-it": "^17.4.0",
"standard-version": "^9.5.0",
"ts-pegjs": "^4.2.1",
"tsx": "^4.7.1",
"typedoc": "^0.26.3",
"typedoc-plugin-frontmatter": "^1.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/ax/dsp/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ function _parseLLMFriendlyDateTime(dateTimeStr: string) {
// Convert to UTC
return date.utc().toDate();
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const formatDateWithTimezone = (date: Readonly<Date>) => {
const momentDate = moment(date).utc();
return momentDate.format(`YYYY-MM-DD HH:mm:ss UTC`);
};
14 changes: 9 additions & 5 deletions src/ax/dsp/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ const convertValueToType = (field: Readonly<AxField>, val: string) => {
return parseLLMFriendlyDate(field, val as string);
case 'datetime':
return parseLLMFriendlyDateTime(field, val as string);
case 'class':
if (field.type.classes && !field.type.classes.includes(val)) {
throw new Error(
`Invalid class '${val}', expected one of the following: ${field.type.classes.join(', ')}`
);
}
return val as string;
default:
return val as string; // Unknown type
}
Expand All @@ -122,11 +129,8 @@ function validateAndParseFieldValue(
field: Readonly<AxField>,
fieldValue: string | undefined
): unknown {
if (
!fieldValue ||
fieldValue === '' ||
fieldValue.toLocaleLowerCase() === 'null'
) {
const fv = fieldValue?.toLocaleLowerCase();
if (!fieldValue || !fv || fv === '' || fv === 'null' || fv === 'undefined') {
if (field.isOptional) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/ax/dsp/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test('extractValues with no prefix and single output', (t) => {

test('extractValues with json', (t) => {
const sig = new AxSignature(`question -> answer : json`);

const v1 = {};
extractValues(sig, v1, 'Answer: ```json\n{"hello": "world"}\n```');

Expand Down
7 changes: 6 additions & 1 deletion src/ax/dsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export type { AxAssertion, AxStreamingAssertion } from './asserts.js';
export type { AxPromptTemplate, AxFieldTemplateFn } from './prompt.js';
export type { AxInstanceRegistry } from './registry.js';
export type { AxResponseHandlerArgs } from './generate.js';
export type { ParsedField, ParsedIdentifier } from './parser.js';
export type {
ParsedSignature,
InputParsedFieldList,
OutputParsedFieldList,
ParsedIdentifier
} from './parser.js';
46 changes: 0 additions & 46 deletions src/ax/dsp/parser.peggy

This file was deleted.

Loading

0 comments on commit 3816f80

Please sign in to comment.