Last active
April 14, 2026 19:14
-
-
Save ninjudd/a6936ce00b6cfc37d5a75a958435c3aa to your computer and use it in GitHub Desktop.
Functor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const selectTopic = functor({ | |
| prompt: ({ query, topics }: { query: string; topics: string }) => ` | |
| User query: ${query} | |
| Existing topics: | |
| ${topics} | |
| Match an existing topic if one fits, otherwise create a new one. | |
| `, | |
| returns: [ | |
| { | |
| type: 'choose_existing', | |
| description: 'Pick an existing topic that matches', | |
| schema: z.object({ topicId: z.string() }), | |
| }, | |
| { | |
| type: 'create_new', | |
| description: 'Create a new topic when none match', | |
| schema: z.object({ | |
| name: z.string(), | |
| summary: z.string(), | |
| }), | |
| }, | |
| ], | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const extractPatient = functor({ | |
| prompt: ({ text }: { text: string }) => ` | |
| Extract patient info from the text below. | |
| Return whatever fields are present. | |
| ${text} | |
| `, | |
| returns: { | |
| description: 'Extract basic patient demographics if present', | |
| schema: z.object({ | |
| name: z.string().optional(), | |
| birthDate: z.string().optional(), | |
| gender: z.string().optional(), | |
| }), | |
| }, | |
| }); | |
| const patient = await extractPatient({ text: documentText }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://x.com/ninjudd/status/2044098508920369535