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
26 changes: 15 additions & 11 deletions python/llmplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from os import devnull
from pathlib import Path

from command_line import (
get_included_conents_from_args,
load_program_from_args,
make_rlc_argparse,
get_included_conents_from_args,
)
from rlc import State, Program, make_llm, run_game
from sys import stdout
from os import devnull
from rlc import make_llm, run_game


def main():
Expand All @@ -35,9 +36,7 @@ def main():
parser.add_argument("--trace-output", type=str, default="-", nargs="?")
parser.add_argument(
"--gemini-stateless",
type=bool,
default=True,
nargs="?",
action="store_true",
help="Use gemini but send only the current state, and do not keep track of past knowledge",
)
parser.add_argument(
Expand All @@ -48,23 +47,28 @@ def main():
parser.add_argument(
"--ollama-local", action="store_true", help="Use ollama locally"
)
parser.add_argument("--llamacpp", action="store_true", help="Use llama.cpp")
parser.add_argument("--no-reasoning", action="store_true", help="Do not ask the model to reason, just output the action")
parser.add_argument("--no-regex", action="store_true", help="Do not use regex to constrain the model output")

args = parser.parse_args()

output = open(args.output, "w+") if args.output != "-" else open(devnull, "w")
trace_output = open(args.trace_output, "w+") if args.trace_output != "-" else open(devnull, "w")
rules = get_included_conents_from_args(args)
with load_program_from_args(args, optimize=True) as program:
llm = make_llm(args, program)
game_name = Path(args.source_file).stem
with load_program_from_args(args, optimize=True, extra_source_files=["stdlib/regex.rl"]) as program:
llm = make_llm(args, program, game_name, should_reason=not args.no_reasoning, should_use_regex=not args.no_regex)
for action, thought in run_game(
llm=llm,
game_name=game_name,
program=program,
rules=rules,
output=output,
trace_output=trace_output,
):
print(thought)
print(program.to_string(action))
print(f"thought: {thought}")
print(f"action: {action}")


if __name__ == "__main__":
Expand Down
Loading