Skip to content

Commit 3b4f596

Browse files
authored
Guaranteed Message type in APEOpt (#191)
1 parent 420203b commit 3b4f596

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ldp/alg/optimizer/ape.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ def aggregate_trajectory(self, trajectory: Trajectory) -> None:
194194
continue
195195
# (x: first prompt's user message's content, y: AI response's content)
196196
x = next(
197-
cast(str, m.content) for m in result.prompt if m.role == "user"
197+
# m is a Message with a result of the LLM. Which completes only strings.
198+
# and we checked the result exists above.
199+
cast(str, m.content)
200+
for m in result.prompt
201+
if (isinstance(m, Message) and m.role == "user")
198202
)
199203
y = cast(str, result.messages[0].content)
200204

0 commit comments

Comments
 (0)