Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
nits
  • Loading branch information
kwanUm committed Oct 8, 2024
commit 0c3f648c97f638a39d0d7ef6e15b32e76789d87d
14 changes: 13 additions & 1 deletion ldp/graph/modules/llm_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ def __init__(
self, llm_model: dict[str, Any], parser: Callable[..., TParsedMessage]
):
self.config_op = ConfigOp[dict](config=llm_model)
self.llm_model = llm_model
self.llm_call_op = LLMCallOp()
self.parse_msg_op = FxnOp(parser)

@compute_graph()
async def __call__(
self, messages: Iterable[Message], *parse_args, **parse_kwargs
) -> tuple[OpResult[TParsedMessage], Message]:
raw_result = await self.llm_call_op(await self.config_op(), msgs=messages)
if "LocalLLMCallOp" in self.llm_call_op.__class__.__name__:
print(f"STARTING A CALL TO MODEL ======================= with {len(messages.value)} messages")
for i, message in enumerate(messages.value[1:], start=1):
print(f"message{i}: {message.content}")
print(f"END OF MESSAGES =======================")
raw_result = await self.llm_call_op(
xi=messages,
temperature=self.llm_model["temperature"],
max_new_tokens=self.llm_model["max_new_tokens"],
)
else:
raw_result = await self.llm_call_op(await self.config_op(), msgs=messages)
return await self.parse_msg_op(
raw_result, *parse_args, **parse_kwargs
), raw_result.value
4 changes: 4 additions & 0 deletions ldp/graph/modules/react.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def parse_message(m: Message, tools: list[Tool]) -> ToolRequestMessage: # noqa:
message_content = message_content[: loc if loc > 0 else None]
# we need to override the message too - don't want the model to hallucinate
m.content = message_content

print("Received back!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + m.content)

action_args: tuple[Any, ...] = ()
# https://regex101.com/r/qmqZ7Z/1
Expand Down Expand Up @@ -141,6 +143,8 @@ def is_number(s: str) -> bool:
action = re.search(r"Action:[ \t]*(\S*)", m.content)
if not action:
raise MalformedMessageError("Action not emitted.")
if "Observation:" in m.content:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the assumption here? That Act or ReAct messages won't contain observations?

raise MalformedMessageError("Observation found in message content and not expected.")
tool_name = action.group(1).strip()
# have to match up name to tool to line up args in order
try:
Expand Down
Loading