Skip to content

Commit 762531c

Browse files
fix actions impl
1 parent cc5c6a3 commit 762531c

10 files changed

Lines changed: 1494 additions & 60 deletions

File tree

src/lmql/lib/actions.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def wiki(q: str, lookup = None):
2121
extract = list(pages.values())[0]["extract"][:280]
2222
return extract
2323
except:
24-
return "No results"
24+
return "No results (try differently)"
2525

2626
async def calc(expr: str):
2727
"""
@@ -117,8 +117,8 @@ async def inline_segment(fcts):
117117
return SEGMENT
118118
else:
119119
"[CALL]"
120-
result = CALL.rsplit("|", 1)[-1].strip()
121-
return SEGMENT[:-len(DELIMITER)] + CALL + DELIMITER_END + " " + result
120+
result = CALL.split("|", 1)[1]
121+
return SEGMENT[:-len(DELIMITER)] + CALL + DELIMITER_END
122122
where
123123
STOPS_AT(SEGMENT, DELIMITER) and fct_call(CALL, fcts)
124124
'''
@@ -147,11 +147,10 @@ async def inline_use(fcts):
147147
truncated = ""
148148
while True:
149149
"[SEGMENT]"
150-
if not SEGMENT.endswith(DELIMITER):
150+
if not SEGMENT.endswith(DELIMITER_END):
151151
" " # seems to be needed for now
152-
return truncated + SEGMENT[:-len("END")]
153-
truncated += SEGMENT[:-len("END")]
154-
print("truncated", [truncated])
152+
return truncated + SEGMENT
153+
truncated += SEGMENT
155154
return truncated
156155
where
157156
inline_segment(SEGMENT, fcts)

src/lmql/runtime/interpreter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ def subinterpreter(self, identifier, prompt, fct, captures):
10631063
if key in self.subinterpreters.keys():
10641064
return self.subinterpreters[key]
10651065
else:
1066-
subinterpreter = SubInterpreter(fct, self, captures)
1066+
subinterpreter = SubInterpreter(fct, self, captures, model=self.model, model_identifier=self.model_identifier)
10671067

10681068
# inherits interpreter attributes from parent
10691069
subinterpreter.tokenizer = self.tokenizer
@@ -1165,7 +1165,7 @@ def __exit__(self, type, value, traceback):
11651165
PromptInterpreter.main = None
11661166

11671167
class SubInterpreter(PromptInterpreter):
1168-
def __init__(self, fct, parent_interpreter: PromptInterpreter, captures: Dict[str, Any]):
1168+
def __init__(self, fct, parent_interpreter: PromptInterpreter, captures: Dict[str, Any], model: str = None, model_identifier: str = None):
11691169
super().__init__(context=parent_interpreter)
11701170
self.query_fct = fct
11711171
self.fct = fct.fct
@@ -1177,6 +1177,13 @@ def __init__(self, fct, parent_interpreter: PromptInterpreter, captures: Dict[st
11771177
self.user_data_key = "head[sub-" + str(id(self)) + "]"
11781178

11791179
self.initial_subprompt_ids = None
1180+
1181+
self.model = model
1182+
self.model_identifier = model_identifier
1183+
1184+
def set_model(self, model):
1185+
# ignore set_model for subinterpreters
1186+
pass
11801187

11811188
def user_data_layer(self, *sqs):
11821189
return UserDataLayer(sqs, self.user_data_mappings)

src/lmql/ui/playground/src/Explore.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const Dialog = styled.div`
8585

8686
const ExploreDialog = styled(Dialog)`
8787
width: 800pt;
88-
height: 550pt;
88+
height: 700pt;
8989
max-height: 100vh;
9090
max-width: 100vh;
9191
overflow-y: auto;
@@ -142,12 +142,10 @@ const ExploreDialog = styled(Dialog)`
142142
top: 15pt;
143143
right: 15pt;
144144
font-size: 8pt;
145-
/* italic */
146-
font-style: italic;
147145
}
148146
149147
div.highlight {
150-
background-color: #d4d3d3;
148+
background-color: #dedef8;
151149
}
152150
153151
>div>div {
@@ -175,7 +173,6 @@ const ExploreDialog = styled(Dialog)`
175173
176174
h2 {
177175
font-size: 12pt;
178-
color: #373737;
179176
}
180177
181178
h3 {
@@ -387,7 +384,7 @@ function BasicHighlighted(props) {
387384
}
388385

389386
const Description = styled.p`
390-
font-size: 12pt;
387+
font-size: 14pt;
391388
color: #696969;
392389
padding: 0pt 20pt;
393390
`
@@ -486,7 +483,7 @@ export function Explore() {
486483
if (!visible) return null;
487484

488485
let description = <>
489-
LMQL is a programming language for interacting with large language models. This playground allows you to explore LMQL's capabilities. To get started, choose one of the example queries below, demonstrating <i>constrained model use</i>, <i>control-flow guided generation</i>, and tool-augmented LLMs.
486+
This playground allows you to explore LMQL's capabilities. To get started, choose one of the example queries below.
490487
</>
491488

492489
if (configuration.NEXT_MODE) {
@@ -508,7 +505,7 @@ export function Explore() {
508505
<div className={c.highlight ? "highlight" : ""} key={c.category + "-container"}>
509506
<h2 key={c.category}>{c.category}</h2>
510507
{c.highlight && <span class="sidenote">
511-
<a href="https://github.com/eth-sri/lmql/issues" target="_blank" rel="noreferrer"> Please report any issues you find.</a>
508+
<a href="https://github.com/eth-sri/lmql/issues" target="_blank" rel="noreferrer"> Report Issues</a>
512509
</span>}
513510
<div key={c.category + "-div"}>
514511
{c.queries.map((q,i) => <Tile key={c.category + "-" + i} onClick={() => onClickTile(q)}>

src/lmql/ui/playground/src/queries.js

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,37 @@ where
136136
// hello world
137137
name: "❤️ Sentiment Constraints",
138138
description: "Affect sentiment with in-context prompting.",
139-
code: `@lmql.query
139+
code: `@lmql.query(cache="mood.tokens", model="chatgpt")
140140
async def mood_description(m: str):
141-
'''lmql
142-
argmax(cache="mood.tokens")
143-
print("Generating mood for", m)
144-
"""Provide a one sentence instruction that prompts a model to write text that
145-
is written in a {m} tone, addressing some previously provided question.\\n"""
146-
"[SUMMARY]\\n"
147-
return SUMMARY.strip();
148-
from
149-
"chatgpt"
150-
'''
141+
'''lmql
142+
print("Generating mood for", m)
143+
"""Provide a one sentence instruction that prompts a model to write text that
144+
is written in a {m} tone, addressing some previously provided question.\\n"""
145+
"[SUMMARY]\\n"
146+
return SUMMARY.strip();
147+
'''
151148
152149
@lmql.query
153150
async def mood(m: str):
154-
'''lmql
155-
incontext
156-
"""
157-
Instruction: {mood_description(m)}
158-
Answer: [RESPONSE]
159-
"""
160-
return RESPONSE.strip();
161-
where
162-
stops_at(RESPONSE, ".") and stops_at(RESPONSE, "\\n")
163-
'''
151+
'''lmql
152+
"""
153+
Instruction: {await mood_description(m)}
154+
Answer: [RESPONSE]
155+
""" where stops_at(RESPONSE, ".") and stops_at(RESPONSE, "\\n")
156+
157+
return RESPONSE.strip();
158+
'''
164159
160+
# main query
165161
argmax
166-
for q in ["Hi", "Who are you", "How is your day going?"]:
167-
"Q: {q}\\n"
168-
"A: [RESPONSE]\\n"
162+
for q in ["Hi", "Who are you", "How is your day going?"]:
163+
"Q: {q}\\n"
164+
"A: [RESPONSE]\\n"
169165
from
170-
"chatgpt"
166+
"chatgpt"
171167
where
172-
mood(RESPONSE, "loving like a partner")
168+
mood(RESPONSE, "loving like a partner")
169+
173170
`,
174171
state: ''
175172
},
@@ -179,38 +176,32 @@ where
179176
description: "Insert dynamic instructions with incontext.",
180177
code: `@lmql.query
181178
async def rhyme():
182-
'''
183-
incontext
179+
'''
184180
"""
185181
Above is the beginning of the poem. Generate the next verse that rhymes with the last line and has the same number of syllables.
186182
[VERSE]
187-
"""
183+
""" where stops_before(VERSE, "\\n")
188184
return VERSE
189-
where
190-
stops_before(VERSE, "\\n")
191-
'''
185+
'''
192186
193187
@lmql.query
194188
async def first_verse():
195-
'''
196-
incontext
189+
'''
197190
"""
198191
Generate a verse that would be perfect for the start of a beautiful rhyme.
199192
[VERSE]
200-
"""
193+
""" where stops_before(VERSE, "\\n")
201194
return VERSE
202-
where
203-
stops_before(VERSE, "\\n")
204-
'''
195+
'''
205196
206197
argmax
207-
"[FIRST_VERSE]\\n"
208-
for i in range(5):
209-
"[VERSE]\\n"
198+
"[FIRST_VERSE]\\n"
199+
for i in range(5):
200+
"[VERSE]\\n"
210201
from
211-
"chatgpt"
202+
"chatgpt"
212203
where
213-
rhyme(VERSE) and first_verse(FIRST_VERSE)
204+
rhyme(VERSE) and first_verse(FIRST_VERSE)
214205
`,
215206
state: ''
216207
}

web/chat/chat.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.side-by-side .query {
2+
background-color: white;
3+
color: black;
4+
}
5+
6+
.side-by-side .query h3 {
7+
color: black;
8+
}
9+
10+
.side-by-side .query h3 a {
11+
display: none;
12+
}
13+
14+
.lmql-str {
15+
color: #7ea464;
16+
}
17+
18+
.lmql-kw {
19+
color: #a866bd;
20+
}
21+
22+
.side-by-side .query pre {
23+
font-size: 8pt;
24+
color: rgb(88, 87, 87);
25+
}
26+
27+
.query anchor {
28+
border-bottom-color: rgb(62, 57, 57);
29+
}

0 commit comments

Comments
 (0)