-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
126 additions
and
176 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,69 +1 @@ | ||
"""Entrypoint for the r2ai plugin and repl.""" | ||
# pylint: disable=import-outside-toplevel | ||
# pylint: disable=unused-import | ||
# pylint: disable=missing-function-docstring | ||
|
||
import sys | ||
import os | ||
import argparse | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(script_dir) | ||
pv = f"{sys.version_info.major}.{sys.version_info.minor}" # pylint: disable=invalid-name | ||
sys.path.append(script_dir + f"/venv/lib/python{pv}/site-packages/") | ||
|
||
from r2ai.main import main as r2ai_main # pylint: disable=wrong-import-position | ||
from r2ai.main import register_r2plugin # pylint: disable=wrong-import-position | ||
|
||
def is_valid_file(parser, arg): | ||
if not os.path.isfile(arg): | ||
parser.error(f"The file {arg} does not exist!") | ||
|
||
def massage_args(args): | ||
runrepl = True | ||
if args.command is None: | ||
args.command = [] | ||
if args.webserver: | ||
args.command.append("-w") | ||
if args.eval: | ||
if args.eval == "default": | ||
args.command.append("-e") | ||
runrepl = False | ||
else: | ||
args.command.append(f"-e {args.eval}") | ||
if args.port: | ||
if args.port == "default": | ||
runrepl = False | ||
args.command.append("-e http.port") | ||
else: | ||
args.command.append(f"-e http.port={args.port}") | ||
if args.model: | ||
if args.model == "default": | ||
args.command.append("-mm") | ||
runrepl = False | ||
else: | ||
args.command.append(f"-m {args.model}") | ||
return runrepl, args | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("bin", nargs="?", type=str) | ||
parser.add_argument("-w", "--webserver", action="store_true", | ||
help="Start the r2ai webserver. Same as r2ai -c=-w") | ||
parser.add_argument("-p", "--port", type=str, nargs="?", const="default", | ||
help="Change listen port number") | ||
parser.add_argument("-e", "--eval", type=str, nargs="?", const="default", | ||
help="Change configuration variable") | ||
parser.add_argument("-m", "--model", type=str, nargs="?", const="default", | ||
help="Select model name") | ||
parser.add_argument("-c", "--command", action="append", | ||
help="Command to be executed. Can be passed multiple times.") | ||
runrepl, args = massage_args(parser.parse_args()) | ||
r2ai_main(args, args.command, runrepl) | ||
|
||
if __name__ == "__main__": | ||
try: | ||
import r2lang # pylint: disable=import-error | ||
register_r2plugin() | ||
except ImportError: | ||
main() | ||
import r2ai.cli |
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
?ef [r2ai] Loaded via r2pipe accessible through "$r2ai" | ||
'$r2ai=#!pipe python main.py | ||
'$r2ai=#!python r2ai/plugin.py | ||
# $r2ai -h |
This file contains 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 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,3 @@ | ||
from .main import run # pylint: disable=wrong-import-position | ||
|
||
run() |
This file contains 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 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 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,32 @@ | ||
"""Entrypoint for the r2ai plugin and repl.""" | ||
|
||
import builtins | ||
import traceback | ||
|
||
import r2lang | ||
def r2ai_rlang_plugin(unused_but_required_argument): | ||
from r2ai.main import run, r2ai_singleton, run_rcfile_once, runline, help_message # pylint: disable=wrong-import-position | ||
ai = r2ai_singleton() | ||
def _call(s): | ||
if not s.startswith("r2ai"): | ||
return False | ||
try: | ||
run_rcfile_once(ai) | ||
if len(s) == 4: | ||
builtins.print(help_message) | ||
else: | ||
usertext = s[4:].strip() | ||
runline(ai, usertext) | ||
except Exception as e: | ||
builtins.print(e) | ||
traceback.print_exc() | ||
return True | ||
|
||
return { | ||
"name": "r2ai", | ||
"license": "MIT", | ||
"desc": "run llama language models inside r2", | ||
"call": _call, | ||
} | ||
|
||
r2lang.plugin("core", r2ai_rlang_plugin) |
Oops, something went wrong.