Skip to content

Commit f158202

Browse files
authored
Enable recursive LLM calls (#2)
1 parent e607cd2 commit f158202

19 files changed

Lines changed: 3266 additions & 575 deletions

File tree

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "rlm"]
2+
path = rlm
3+
url = https://github.com/psg-mit/rlm.git

‎examples/nested.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import nightjarpy as nj
2+
from nightjarpy.configs import INTERPRETER_PYTHON_NESTED_JSON_CONFIG
3+
4+
5+
class Item:
6+
def __init__(self, name: str, item_type: str, strength: int = 0):
7+
self.name = name
8+
self.item_type = item_type
9+
self.strength = strength
10+
11+
12+
class Player:
13+
def __init__(self, name: str, health: int, inventory: list[Item]):
14+
self.name = name
15+
self.health = health
16+
self.inventory = inventory
17+
18+
19+
# Create items and player using Python
20+
items = [Item("sword", "weapon", 15), Item("potion", "healing", 25), Item("key", "tool", 0), Item("bread", "food", 10)]
21+
player = Player("Hero", 50, items)
22+
23+
24+
@nj.fn(config=INTERPRETER_PYTHON_NESTED_JSON_CONFIG)
25+
def speak_factory(player: Player):
26+
"""natural
27+
Give <player> a `speak` method that takes no arguments that uses an LLM to generate a unique response each time it is called. The method should check which lines have been used.
28+
"""
29+
30+
31+
speak_factory(player)
32+
33+
for _ in range(3):
34+
print(player.speak()) # type:ignore

0 commit comments

Comments
 (0)