-
Notifications
You must be signed in to change notification settings - Fork 328
visit_by Implementation #2939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MalithaPrabhashana
wants to merge
21
commits into
main
Choose a base branch
from
visit_by_implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
visit_by Implementation #2939
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b0432fe
Initial commit
MalithaPrabhashana beae06a
clean up import statements and improve formatting in visit_by.py
MalithaPrabhashana 45ee784
support syntax for visit by
MalithaPrabhashana cfccc2a
refactor: enhance exit_visit_stmt logic for visitor handling
MalithaPrabhashana 9b42ba1
remove unused ThreeWheeler node and clean up visit logic
MalithaPrabhashana 03dd1b1
add VehicleShowroom and showroom_visitor nodes with vehicle display l…
MalithaPrabhashana ff11c40
Merge branch 'main' into visit_by_implementation
MalithaPrabhashana 6d346e1
Fix variable references in PyastGenPass to use constants
MalithaPrabhashana 09a3c4f
Refactor node description functions: move to JacUtils and simplify usage
MalithaPrabhashana 376f63b
Merge branch 'main' into visit_by_implementation
MalithaPrabhashana 3c37350
Implement code changes to enhance functionality and improve performance
MalithaPrabhashana d83642a
Add vehicle showroom example with vehicle types and visitor interaction
MalithaPrabhashana 812e777
Add blank lines for improved code readability in visit_by.py, pyast_g…
MalithaPrabhashana 9b4edef
Merge branch 'main' into visit_by_implementation
MalithaPrabhashana a427851
Implement code changes to enhance functionality and improve performance
MalithaPrabhashana 93c4fdd
Add static method decorators and update vehicle finder examples for i…
MalithaPrabhashana 24a7c3d
Merge branch 'main' into visit_by_implementation
MalithaPrabhashana 564288d
Implement code changes to enhance functionality and improve performance
MalithaPrabhashana 79e0f9c
Add vehicle finder examples and update test paths for showroom functi…
MalithaPrabhashana 3ff4125
used by decorator to visit_by
MalithaPrabhashana b5da61b
Add LLM-Powered Graph Traversal feature to release notes
MalithaPrabhashana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""This module contains functions for visiting and describing nodes in a graph-like structure.""" | ||
|
||
from __future__ import annotations | ||
|
||
# from jaclang.runtimelib.builtin import * | ||
from byllm import MTIR, Model | ||
|
||
from jaclang import JacMachineInterface as _ | ||
from jaclang.runtimelib.constructs import ( | ||
EdgeArchetype, | ||
NodeArchetype, | ||
WalkerArchetype, | ||
) | ||
|
||
|
||
def get_where_to_visit_next( | ||
model: Model, | ||
walker: WalkerArchetype, | ||
current_node: NodeArchetype, | ||
connected_nodes: list[NodeArchetype | EdgeArchetype], | ||
description: str = "", | ||
) -> list[int]: | ||
"""Determine the next nodes to visit by analyzing semantics using an LLM. | ||
|
||
Walker is a transitioning agent while the nodes are agents that can be visited. | ||
It returns the list of indexes of the next nodes to visit in order to complete the task of the walker. | ||
If no suitable node is found, it returns []. | ||
""" | ||
return _.call_llm( | ||
model=model(), | ||
mtir=MTIR.factory( | ||
caller=get_where_to_visit_next, | ||
args={ | ||
"walker": walker, | ||
"current_node": current_node, | ||
"connected_nodes": connected_nodes, | ||
"description": description, | ||
}, | ||
call_params=model.call_params, | ||
), | ||
) | ||
|
||
|
||
def _visit_by( | ||
model: Model, | ||
walker: WalkerArchetype, | ||
node: NodeArchetype, | ||
connected_nodes: list[NodeArchetype], | ||
) -> ( | ||
list[NodeArchetype | EdgeArchetype] | ||
| list[NodeArchetype] | ||
| list[EdgeArchetype] | ||
| NodeArchetype | ||
| EdgeArchetype | ||
): | ||
"""Go through the available nodes and decide which next nodes to visit based on their semantics using an llm.""" | ||
if not isinstance(model, Model): | ||
raise TypeError("Invalid llm object") | ||
if not connected_nodes: | ||
raise ValueError("No connected agents found for the walker") | ||
next_node_indexes = get_where_to_visit_next( | ||
model, | ||
walker, | ||
node, | ||
connected_nodes, | ||
description=_.describe_object_list(connected_nodes), | ||
) | ||
ordered_list = [] | ||
for index in next_node_indexes: | ||
if index < len(connected_nodes) and index >= 0: | ||
ordered_list.append(connected_nodes[index]) | ||
else: | ||
raise IndexError("Index out of range for connected nodes") | ||
|
||
_.visit(walker, ordered_list) | ||
return ordered_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import from byllm.llm { Model } | ||
|
||
glob llm = Model("gpt-4o"); | ||
|
||
node VehicleShowroom { | ||
can show_vehicles with showroom_visitor entry { | ||
print("Welcome to the Vehicle Showroom! Here are the vehicles available:\n"); | ||
visit [-->] by llm(); | ||
} | ||
} | ||
|
||
node Car { | ||
can act with showroom_visitor entry { | ||
print("🚙 Car: A sleek sedan with modern features."); | ||
} | ||
} | ||
|
||
node Bike { | ||
can act with showroom_visitor entry { | ||
print("🚲 Bike: A sporty mountain bike perfect for off-road adventures."); | ||
} | ||
} | ||
|
||
node Van { | ||
can act with showroom_visitor entry { | ||
print("🚚 Van: A spacious van ideal for family trips."); | ||
} | ||
} | ||
|
||
walker showroom_visitor { | ||
has vehicle_wheel_number: list[int]; | ||
|
||
can visit_showroom with `root entry { | ||
print("Visitor: Entering the showroom..."); | ||
visit [-->]; | ||
} | ||
} | ||
|
||
with entry { | ||
show_room = root ++> VehicleShowroom(); | ||
show_room ++> Car(); | ||
show_room ++> Bike(); | ||
show_room ++> Van(); | ||
|
||
showroom_visitor([2, 4]) spawn root; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import from byllm { Model } | ||
|
||
glob llm: Model = Model("gpt-4o"); | ||
|
||
node VehicleShowroom { | ||
can show_vehicles with showroom_visitor entry { | ||
print("Welcome to the Vehicle Showroom! Here are the vehicles available:\n"); | ||
visit [-->(`?Car)] by llm(); | ||
} | ||
} | ||
|
||
node Car { | ||
has color: str; | ||
can act with showroom_visitor entry { | ||
print("🚙 Car: A sleek sedan with modern features."); | ||
} | ||
} | ||
|
||
node Bike { | ||
has color: str; | ||
can act with showroom_visitor entry { | ||
print("🚲 Bike: A sporty mountain bike perfect for off-road adventures."); | ||
} | ||
} | ||
|
||
walker showroom_visitor { | ||
has expected_color: list[str]; | ||
|
||
can visit_showroom with `root entry { | ||
print("Visitor: Entering the showroom..."); | ||
visit [-->]; | ||
} | ||
} | ||
|
||
with entry { | ||
show_room = root ++> VehicleShowroom(); | ||
show_room ++> Car("Red"); | ||
show_room ++> Car("Blue"); | ||
show_room ++> Car("Black"); | ||
show_room ++> Bike("Green"); | ||
show_room ++> Bike("Blue"); | ||
|
||
showroom_visitor(["Blue"]) spawn root; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.