Skip to content

Instantly share code, notes, and snippets.

@organisciak
Last active January 7, 2024 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save organisciak/8452b315c6b24c3196020ff990a61d46 to your computer and use it in GitHub Desktop.
Save organisciak/8452b315c6b24c3196020ff990a61d46 to your computer and use it in GitHub Desktop.
langscript
LangScript is a TypeScript-subset language for communicating clearly with language models. LangScript supports types, variables, JSDoc-style comments, and functions. Tests are used to demonstrate few-shot examples. I want you to read the spec, and then interpret the ENV and COMMANDS below.
*You* respond to the functions with your own reasoning, inferred from context, inference, and instructions. This includes explicit calls to `llm_magic()` command, which signals for you to come up with an answer yourself. LangScript is designed to communicate a clear request to you.
Comments are part of your LangScript interpreter, and you use them as hints to the functionality and intentions of types, variables, or functions. All typed variables and primitive methods can be stringified with JSON.
These are reserved functions in LangScript.
- `llm_magic` is an explicit call to come up with the answer yourself: it will always return the appropriate type.
- `print` prints a JSON representation of any variable, cast to a string and surrounded by triple backticks.
- For tests and examples of outputs, LangScript uses `expect(...).toBe(..)`, where A is a function call and B is an output. This communicates how you should be understanding input to output.
Any function declaration without a body can be presumed to run `llm_magic` and return the declared type for the function.
Write each command in COMMANDS when it runs, using the format: `> command()`.
The output of all functions is printed unless set to a variable. Don't truncate or abridge outputs. You can include initial thoughts thinking through the challenge, but note when the program runs with '# RUN'
// # ENV
// ## Types
type Person = {
'context': string | null, // context in which the person was discussed
'name': string
}
// Extract all person entities from a text
declare function extractPersons(text:string): Person[]
// ## Variables
const text: string = 'Alexei Fyodorovich Karamazov was the third son of a landowner from our district, Fyodor Pavlovich Karamazov, well known in his own day (and still remembered among us) because of his dark and tragic death, which happened exactly thirteen years ago and which I shall speak of in its proper place.';
// # COMMANDS
extractPersons(text)
// # ENV
// ## LangScript Global Variables
// no default settings changed
// ## TYPES
type Idea = {
'category': 'outdoors' | 'home' | 'food' | 'crafts',
'name': String,
'description': String
}
// ## FUNCTIONS
/**
* Generate a set of ideas for entertaining a child of a certain age.
*
* @param {number} n - The number of examples to generate.
* @param {number} age - The age of the target child.
* @returns {Idea[]} - The resulting list of ideas.
*/
function generateKidsIdeas(n:number, age:number): Idea[] {
return llm_magic() as Idea[]
}
// # TESTS AND EXAMPLES
// .expect().toBe() syntax
// # VARIABLES
const age: number = 3;
// # COMMANDS
print('test')
generateKidsIdeas(10, age);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment