Skip to content

Commit

Permalink
Use the word :use instead of :include
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 11, 2024
1 parent 523fcd1 commit 310d264
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 68 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky)
- [ ] `[!assertion]`
- [x] `[:if ... :then ... :else ...]`
- [x] `[$ meta-prompt]`
- [x] `[:include module :param1=value1]`
- [x] `[:use module :param1=value1]`
- [ ] `[# comments]`
- [ ] Implement an evaluator
- [x] meta-prompting
Expand All @@ -64,7 +64,9 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky)
- [x] implement a 'manual' evaluator that asks the user to complete LLM inputs
- [ ] API provider wrapper classes
- [x] OpenAI
- [ ] dynamic model switching
- [ ] Anthropic
- [ ] llama
- [ ] dynamic model switching
- [ ] Runtime system
- [x] Support variable definition at runtime
- [ ] exceptions
Expand All @@ -76,7 +78,6 @@ This is an early work-in-progress. Follow [me on twitter](https://x.com/klntsky)
- [ ] enable function scopes
- [ ] Add a module system
- [ ] Add a package system
- [ ] Type system? TBD

## Notable sources of inspiration

Expand Down
4 changes: 2 additions & 2 deletions grammar/MetaPrompt.g4
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ expr1
meta_body
: IF_KW exprs THEN_KW exprs ELSE_KW exprs
| IF_KW exprs THEN_KW exprs
| INCLUDE parameters?
| USE parameters?
| META_KW exprs
| VAR_NAME EQ_KW exprs
| VAR_NAME
Expand All @@ -33,7 +33,7 @@ RB : ']';
EQ_KW : '=' ;
META_KW : '$' ;
CHAR : . ;
INCLUDE : ':include' WS+ [a-zA-Z0-9/_.-]+ WS*;
USE : ':use' WS+ [a-zA-Z0-9/_.-]+ WS*;
fragment WS : ' '|'\n';
IF_KW : ':if' ;
THEN_KW : ':then' ;
Expand Down
4 changes: 2 additions & 2 deletions python/src/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async def eval_ast(ast, runtime):
raise ValueError(f"Failed to look up: {ast['name']}")
else:
yield value
elif ast["type"] == "include":
elif ast["type"] == "use":
parameters = ast["parameters"]
module_name = ast["module_name"]
raise NotImplementedError("[:include ...] not implemented yet")
raise NotImplementedError("[:use ...] not implemented yet")
elif ast["type"] == "assign":
var_name = ast["name"]
value = await _collect_exprs(ast['exprs'], runtime)
Expand Down
6 changes: 3 additions & 3 deletions python/src/parse_metaprompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def visitMeta_body(self, ctx: MetaPromptParser.Meta_bodyContext):
"then": then_node,
"else": [],
}
elif ctx.INCLUDE() is not None:
module_name = ctx.INCLUDE().getText().removeprefix(':include').strip()
elif ctx.USE() is not None:
module_name = ctx.USE().getText().removeprefix(':use').strip()
parameters = {}
if ctx.parameters() is not None:
parameters = self.visit(ctx.parameters())
return {
"type": "include",
"type": "use",
"module_name": module_name,
"parameters": parameters
}
Expand Down
2 changes: 1 addition & 1 deletion python/src/parser/MetaPrompt.interp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RB
EQ_KW
META_KW
CHAR
INCLUDE
USE
IF_KW
THEN_KW
ELSE_KW
Expand Down
2 changes: 1 addition & 1 deletion python/src/parser/MetaPrompt.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RB=2
EQ_KW=3
META_KW=4
CHAR=5
INCLUDE=6
USE=6
IF_KW=7
THEN_KW=8
ELSE_KW=9
Expand Down
6 changes: 3 additions & 3 deletions python/src/parser/MetaPromptLexer.interp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RB
EQ_KW
META_KW
CHAR
INCLUDE
USE
IF_KW
THEN_KW
ELSE_KW
Expand All @@ -30,7 +30,7 @@ RB
EQ_KW
META_KW
CHAR
INCLUDE
USE
WS
IF_KW
THEN_KW
Expand All @@ -45,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1, 0, 0, 0, 13, 58, 1, 0, 0, 0, 15, 60, 1, 0, 0, 0, 17, 64, 1, 0, 0, 0, 19, 70, 1, 0, 0, 0, 21, 76, 1, 0, 0, 0, 23, 24, 5, 91, 0, 0, 24, 2, 1, 0, 0, 0, 25, 26, 5, 93, 0, 0, 26, 4, 1, 0, 0, 0, 27, 28, 5, 61, 0, 0, 28, 6, 1, 0, 0, 0, 29, 30, 5, 36, 0, 0, 30, 8, 1, 0, 0, 0, 31, 32, 9, 0, 0, 0, 32, 10, 1, 0, 0, 0, 33, 34, 5, 58, 0, 0, 34, 35, 5, 105, 0, 0, 35, 36, 5, 110, 0, 0, 36, 37, 5, 99, 0, 0, 37, 38, 5, 108, 0, 0, 38, 39, 5, 117, 0, 0, 39, 40, 5, 100, 0, 0, 40, 41, 5, 101, 0, 0, 41, 43, 1, 0, 0, 0, 42, 44, 3, 13, 6, 0, 43, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 48, 1, 0, 0, 0, 47, 49, 7, 0, 0, 0, 48, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 55, 1, 0, 0, 0, 52, 54, 3, 13, 6, 0, 53, 52, 1, 0, 0, 0, 54, 57, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 56, 1, 0, 0, 0, 56, 12, 1, 0, 0, 0, 57, 55, 1, 0, 0, 0, 58, 59, 7, 1, 0, 0, 59, 14, 1, 0, 0, 0, 60, 61, 5, 58, 0, 0, 61, 62, 5, 105, 0, 0, 62, 63, 5, 102, 0, 0, 63, 16, 1, 0, 0, 0, 64, 65, 5, 58, 0, 0, 65, 66, 5, 116, 0, 0, 66, 67, 5, 104, 0, 0, 67, 68, 5, 101, 0, 0, 68, 69, 5, 110, 0, 0, 69, 18, 1, 0, 0, 0, 70, 71, 5, 58, 0, 0, 71, 72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, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 1, 23, 1, 0, 0, 0, 3, 25, 1, 0, 0, 0, 5, 27, 1, 0, 0, 0, 7, 29, 1, 0, 0, 0, 9, 31, 1, 0, 0, 0, 11, 33, 1, 0, 0, 0, 13, 54, 1, 0, 0, 0, 15, 56, 1, 0, 0, 0, 17, 60, 1, 0, 0, 0, 19, 66, 1, 0, 0, 0, 21, 72, 1, 0, 0, 0, 23, 24, 5, 91, 0, 0, 24, 2, 1, 0, 0, 0, 25, 26, 5, 93, 0, 0, 26, 4, 1, 0, 0, 0, 27, 28, 5, 61, 0, 0, 28, 6, 1, 0, 0, 0, 29, 30, 5, 36, 0, 0, 30, 8, 1, 0, 0, 0, 31, 32, 9, 0, 0, 0, 32, 10, 1, 0, 0, 0, 33, 34, 5, 58, 0, 0, 34, 35, 5, 117, 0, 0, 35, 36, 5, 115, 0, 0, 36, 37, 5, 101, 0, 0, 37, 39, 1, 0, 0, 0, 38, 40, 3, 13, 6, 0, 39, 38, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 44, 1, 0, 0, 0, 43, 45, 7, 0, 0, 0, 44, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 51, 1, 0, 0, 0, 48, 50, 3, 13, 6, 0, 49, 48, 1, 0, 0, 0, 50, 53, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 12, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 55, 7, 1, 0, 0, 55, 14, 1, 0, 0, 0, 56, 57, 5, 58, 0, 0, 57, 58, 5, 105, 0, 0, 58, 59, 5, 102, 0, 0, 59, 16, 1, 0, 0, 0, 60, 61, 5, 58, 0, 0, 61, 62, 5, 116, 0, 0, 62, 63, 5, 104, 0, 0, 63, 64, 5, 101, 0, 0, 64, 65, 5, 110, 0, 0, 65, 18, 1, 0, 0, 0, 66, 67, 5, 58, 0, 0, 67, 68, 5, 101, 0, 0, 68, 69, 5, 108, 0, 0, 69, 70, 5, 115, 0, 0, 70, 71, 5, 101, 0, 0, 71, 20, 1, 0, 0, 0, 72, 73, 5, 58, 0, 0, 73, 77, 7, 2, 0, 0, 74, 76, 7, 3, 0, 0, 75, 74, 1, 0, 0, 0, 76, 79, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 22, 1, 0, 0, 0, 79, 77, 1, 0, 0, 0, 5, 0, 41, 46, 51, 77, 0]
63 changes: 31 additions & 32 deletions python/src/parser/MetaPromptLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@

def serializedATN():
return [
4,0,10,84,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,
4,0,10,80,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,
6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,1,0,1,0,1,1,1,1,1,2,1,2,
1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,4,5,44,8,
5,11,5,12,5,45,1,5,4,5,49,8,5,11,5,12,5,50,1,5,5,5,54,8,5,10,5,12,
5,57,9,5,1,6,1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,
1,9,1,9,1,9,1,9,1,10,1,10,1,10,5,10,80,8,10,10,10,12,10,83,9,10,
0,0,11,1,1,3,2,5,3,7,4,9,5,11,6,13,0,15,7,17,8,19,9,21,10,1,0,4,
4,0,45,57,65,90,95,95,97,122,2,0,10,10,32,32,2,0,65,90,97,122,3,
0,48,57,65,90,97,122,86,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,
1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,
1,0,0,0,0,21,1,0,0,0,1,23,1,0,0,0,3,25,1,0,0,0,5,27,1,0,0,0,7,29,
1,0,0,0,9,31,1,0,0,0,11,33,1,0,0,0,13,58,1,0,0,0,15,60,1,0,0,0,17,
64,1,0,0,0,19,70,1,0,0,0,21,76,1,0,0,0,23,24,5,91,0,0,24,2,1,0,0,
0,25,26,5,93,0,0,26,4,1,0,0,0,27,28,5,61,0,0,28,6,1,0,0,0,29,30,
5,36,0,0,30,8,1,0,0,0,31,32,9,0,0,0,32,10,1,0,0,0,33,34,5,58,0,0,
34,35,5,105,0,0,35,36,5,110,0,0,36,37,5,99,0,0,37,38,5,108,0,0,38,
39,5,117,0,0,39,40,5,100,0,0,40,41,5,101,0,0,41,43,1,0,0,0,42,44,
3,13,6,0,43,42,1,0,0,0,44,45,1,0,0,0,45,43,1,0,0,0,45,46,1,0,0,0,
46,48,1,0,0,0,47,49,7,0,0,0,48,47,1,0,0,0,49,50,1,0,0,0,50,48,1,
0,0,0,50,51,1,0,0,0,51,55,1,0,0,0,52,54,3,13,6,0,53,52,1,0,0,0,54,
57,1,0,0,0,55,53,1,0,0,0,55,56,1,0,0,0,56,12,1,0,0,0,57,55,1,0,0,
0,58,59,7,1,0,0,59,14,1,0,0,0,60,61,5,58,0,0,61,62,5,105,0,0,62,
63,5,102,0,0,63,16,1,0,0,0,64,65,5,58,0,0,65,66,5,116,0,0,66,67,
5,104,0,0,67,68,5,101,0,0,68,69,5,110,0,0,69,18,1,0,0,0,70,71,5,
58,0,0,71,72,5,101,0,0,72,73,5,108,0,0,73,74,5,115,0,0,74,75,5,101,
0,0,75,20,1,0,0,0,76,77,5,58,0,0,77,81,7,2,0,0,78,80,7,3,0,0,79,
78,1,0,0,0,80,83,1,0,0,0,81,79,1,0,0,0,81,82,1,0,0,0,82,22,1,0,0,
0,83,81,1,0,0,0,5,0,45,50,55,81,0
1,3,1,3,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,4,5,40,8,5,11,5,12,5,41,
1,5,4,5,45,8,5,11,5,12,5,46,1,5,5,5,50,8,5,10,5,12,5,53,9,5,1,6,
1,6,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,
1,9,1,10,1,10,1,10,5,10,76,8,10,10,10,12,10,79,9,10,0,0,11,1,1,3,
2,5,3,7,4,9,5,11,6,13,0,15,7,17,8,19,9,21,10,1,0,4,4,0,45,57,65,
90,95,95,97,122,2,0,10,10,32,32,2,0,65,90,97,122,3,0,48,57,65,90,
97,122,82,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,
0,0,0,0,11,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,
0,0,0,1,23,1,0,0,0,3,25,1,0,0,0,5,27,1,0,0,0,7,29,1,0,0,0,9,31,1,
0,0,0,11,33,1,0,0,0,13,54,1,0,0,0,15,56,1,0,0,0,17,60,1,0,0,0,19,
66,1,0,0,0,21,72,1,0,0,0,23,24,5,91,0,0,24,2,1,0,0,0,25,26,5,93,
0,0,26,4,1,0,0,0,27,28,5,61,0,0,28,6,1,0,0,0,29,30,5,36,0,0,30,8,
1,0,0,0,31,32,9,0,0,0,32,10,1,0,0,0,33,34,5,58,0,0,34,35,5,117,0,
0,35,36,5,115,0,0,36,37,5,101,0,0,37,39,1,0,0,0,38,40,3,13,6,0,39,
38,1,0,0,0,40,41,1,0,0,0,41,39,1,0,0,0,41,42,1,0,0,0,42,44,1,0,0,
0,43,45,7,0,0,0,44,43,1,0,0,0,45,46,1,0,0,0,46,44,1,0,0,0,46,47,
1,0,0,0,47,51,1,0,0,0,48,50,3,13,6,0,49,48,1,0,0,0,50,53,1,0,0,0,
51,49,1,0,0,0,51,52,1,0,0,0,52,12,1,0,0,0,53,51,1,0,0,0,54,55,7,
1,0,0,55,14,1,0,0,0,56,57,5,58,0,0,57,58,5,105,0,0,58,59,5,102,0,
0,59,16,1,0,0,0,60,61,5,58,0,0,61,62,5,116,0,0,62,63,5,104,0,0,63,
64,5,101,0,0,64,65,5,110,0,0,65,18,1,0,0,0,66,67,5,58,0,0,67,68,
5,101,0,0,68,69,5,108,0,0,69,70,5,115,0,0,70,71,5,101,0,0,71,20,
1,0,0,0,72,73,5,58,0,0,73,77,7,2,0,0,74,76,7,3,0,0,75,74,1,0,0,0,
76,79,1,0,0,0,77,75,1,0,0,0,77,78,1,0,0,0,78,22,1,0,0,0,79,77,1,
0,0,0,5,0,41,46,51,77,0
]

class MetaPromptLexer(Lexer):
Expand All @@ -51,7 +50,7 @@ class MetaPromptLexer(Lexer):
EQ_KW = 3
META_KW = 4
CHAR = 5
INCLUDE = 6
USE = 6
IF_KW = 7
THEN_KW = 8
ELSE_KW = 9
Expand All @@ -65,11 +64,11 @@ class MetaPromptLexer(Lexer):
"'['", "']'", "'='", "'$'", "':if'", "':then'", "':else'" ]

symbolicNames = [ "<INVALID>",
"LB", "RB", "EQ_KW", "META_KW", "CHAR", "INCLUDE", "IF_KW",
"THEN_KW", "ELSE_KW", "VAR_NAME" ]
"LB", "RB", "EQ_KW", "META_KW", "CHAR", "USE", "IF_KW", "THEN_KW",
"ELSE_KW", "VAR_NAME" ]

ruleNames = [ "LB", "RB", "EQ_KW", "META_KW", "CHAR", "INCLUDE", "WS",
"IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ]
ruleNames = [ "LB", "RB", "EQ_KW", "META_KW", "CHAR", "USE", "WS", "IF_KW",
"THEN_KW", "ELSE_KW", "VAR_NAME" ]

grammarFileName = "MetaPrompt.g4"

Expand Down
2 changes: 1 addition & 1 deletion python/src/parser/MetaPromptLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RB=2
EQ_KW=3
META_KW=4
CHAR=5
INCLUDE=6
USE=6
IF_KW=7
THEN_KW=8
ELSE_KW=9
Expand Down
10 changes: 5 additions & 5 deletions python/src/parser/MetaPromptParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MetaPromptParser ( Parser ):
"<INVALID>", "':if'", "':then'", "':else'" ]

symbolicNames = [ "<INVALID>", "LB", "RB", "EQ_KW", "META_KW", "CHAR",
"INCLUDE", "IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ]
"USE", "IF_KW", "THEN_KW", "ELSE_KW", "VAR_NAME" ]

RULE_prompt = 0
RULE_exprs = 1
Expand All @@ -68,7 +68,7 @@ class MetaPromptParser ( Parser ):
EQ_KW=3
META_KW=4
CHAR=5
INCLUDE=6
USE=6
IF_KW=7
THEN_KW=8
ELSE_KW=9
Expand Down Expand Up @@ -371,8 +371,8 @@ def THEN_KW(self):
def ELSE_KW(self):
return self.getToken(MetaPromptParser.ELSE_KW, 0)

def INCLUDE(self):
return self.getToken(MetaPromptParser.INCLUDE, 0)
def USE(self):
return self.getToken(MetaPromptParser.USE, 0)

def parameters(self):
return self.getTypedRuleContext(MetaPromptParser.ParametersContext,0)
Expand Down Expand Up @@ -447,7 +447,7 @@ def meta_body(self):
elif la_ == 3:
self.enterOuterAlt(localctx, 3)
self.state = 48
self.match(MetaPromptParser.INCLUDE)
self.match(MetaPromptParser.USE)
self.state = 50
self._errHandler.sync(self)
_la = self._input.LA(1)
Expand Down
30 changes: 15 additions & 15 deletions python/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def meta(exprs):
'exprs': exprs
}

def include(module_name, parameters):
def use(module_name, parameters):
return {
'type': 'include',
'type': 'use',
'module_name': module_name,
'parameters': parameters
}
Expand Down Expand Up @@ -156,22 +156,22 @@ def test_assign_trailing_bracket():
}
]

def test_include_1():
result = parse_metaprompt("[:include foo]")
def test_use_1():
result = parse_metaprompt("[:use foo]")
assert result["exprs"] == [
{
'type': 'include',
'type': 'use',
'module_name': 'foo',
'parameters': {}
}
]


def test_include_2():
result = parse_metaprompt("[:include foo :asd=hey :foo=bar]")
def test_use_2():
result = parse_metaprompt("[:use foo :asd=hey :foo=bar]")
assert result["exprs"] == [
{
'type': 'include',
'type': 'use',
'module_name': 'foo',
'parameters': {
'asd': [ { 'type': 'text', 'text': 'hey ' } ],
Expand All @@ -181,28 +181,28 @@ def test_include_2():
]


def test_include_3():
result = parse_metaprompt("[:include\nfoo\n]")
def test_use_3():
result = parse_metaprompt("[:use\nfoo\n]")
assert result["exprs"] == [
{
'type': 'include',
'type': 'use',
'module_name': 'foo',
'parameters': {}
}
]


def test_include_nested():
def test_use_nested():
result = parse_metaprompt(
"[:include foo :asd=[:include bar] hiii :foo=bar]"
"[:use foo :asd=[:use bar] hiii :foo=bar]"
)
assert result["exprs"] == [
{
'type': 'include',
'type': 'use',
'module_name': 'foo',
'parameters': {
'asd': [
include('bar', {}),
use('bar', {}),
{ 'type': 'text', 'text': ' hiii ' }
],
'foo': [ { 'type': 'text', 'text': 'bar' } ]
Expand Down

0 comments on commit 310d264

Please sign in to comment.