Skip to content

Commit

Permalink
Package updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dnakov committed Jun 7, 2024
1 parent 2e906ae commit cda2e48
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
venv
32 changes: 16 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Entrypoint for the r2ai plugin and repl."""

import runpy
import sys
import os

if "R2AI" in os.environ:
print("Cant load r2ai r2 plugin from inside r2ai")
sys.exit(0)
r2aihome = os.path.dirname(__file__)
try:
r2aihome = os.path.dirname(os.readlink(__file__))
except (OSError, FileNotFoundError):
pass
sys.path.insert(0, r2aihome)
os.environ["R2AI"] = "1"
if "VIRTUAL_ENV" in os.environ or "R2CORE" in os.environ:
runpy.run_path(os.path.join(r2aihome, 'r2ai', 'main.py'))
else:
ARGS = " ".join(sys.argv[1:])
os.system(f"cd {r2aihome}; ./r2ai.sh {ARGS}")
def main():
print('os', os.environ.get('R2AI'))
if os.environ.get('R2AI'):
print("Cant load r2ai r2 plugin from inside r2ai")
sys.exit(0)
r2aihome = os.path.dirname(__file__)
try:
r2aihome = os.path.dirname(os.readlink(__file__))
except (OSError, FileNotFoundError):
pass
sys.path.insert(0, r2aihome)
os.environ["R2AI"] = "1"
from r2ai import main

if(__name__ == "__main__"):
main()
52 changes: 52 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[project]
name = "r2ai"
dynamic = ["readme"]
version = "0.7.0"
description = "Applying language models on radare2 for reverse engineering and fun purposes"

license = {text = "MIT License"}
authors = [
{name = "pancake", email = "[email protected]"}
]

[project.urls]
homepage = "https://www.radare.org/"
repository = "https://github.com/radareorg/r2ai"

[project.scripts]
r2ai = "r2ai:main"

[tool.setuptools.packages.find]
where = [".", "r2ai"]
include = ["main", "r2ai"]
namespaces = true

[tool.setuptools.dynamic]
readme = {file = "README.md", content-type = "text/markdown"}

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

dependencies = [
"rich",
"r2pipe",
"inquirer",
"llama-cpp-python",
"huggingface_hub==0.22.0",
"appdirs",
"unidecode",
"jsonref",
"transformers",
"pydantic",
"torch"
]

[project.optional-dependencies]
extras = [
"openai",
"anthropic",
"groq",
"google-generativeai",
"google-cloud-aiplatform"
]
5 changes: 0 additions & 5 deletions r2ai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
import sys
from .models import models, mainmodels
sys.modules["r2ai"].models = models
sys.modules["r2ai"].mainmodels = mainmodels
VERSION = "0.7.0"
17 changes: 9 additions & 8 deletions r2ai/repl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import builtins
from r2ai.models import set_default_model
from .models import set_default_model, models, mainmodels
from .utils import slurp
import traceback
from .const import R2AI_HISTFILE, R2AI_HOMEDIR, R2AI_RCFILE, R2AI_USERDIR
Expand All @@ -22,7 +22,7 @@
def r2ai_singleton():
global ais
if len(ais) == 0:
from r2ai.interpreter import Interpreter
from .interpreter import Interpreter
ai = Interpreter()
ais.append(R2AI(ai))
return ais[0].ai
Expand Down Expand Up @@ -182,9 +182,9 @@ def runline(ai, usertext):
elif usertext.startswith("clear") or usertext.startswith("-k"):
print("\x1b[2J\x1b[0;0H\r")
elif usertext.startswith("-MM"):
print(r2ai.mainmodels().strip())
print(mainmodels().strip())
elif usertext.startswith("-M"):
print(r2ai.models().strip())
print(models().strip())
elif usertext.startswith("-m"):
words = usertext.split(" ")
if len(words) > 1:
Expand All @@ -201,7 +201,7 @@ def runline(ai, usertext):
else:
ai.env["llm.temperature"] = usertext[2:].strip()
elif usertext == "-A":
from r2ai.voice import stt
from .voice import stt
ai.env["chat.voice"] = "true"
old_live = ai.env["chat.live"]
ai.env["chat.live"] = "false"
Expand All @@ -213,7 +213,7 @@ def runline(ai, usertext):
ai.env["chat.live"] = old_live
ai.env["chat.voice"] = "false"
elif usertext == "-a":
from r2ai.voice import stt
from .voice import stt
ai.env["chat.voice"] = "true"
old_live = ai.env["chat.live"]
ai.env["chat.live"] = "true"
Expand Down Expand Up @@ -352,7 +352,7 @@ def runline(ai, usertext):
if index < len(ais):
ai = ais[index].ai
else:
from r2ai.interpreter import Interpreter
from .interpreter import Interpreter
ai0 = Interpreter()
ai0.model = ai.model
ais.append(R2AI(ai0))
Expand Down Expand Up @@ -389,7 +389,8 @@ def runline(ai, usertext):
pass
elif usertext.startswith("' "):
if not autoai:
autoai = r2ai.interpreter.Interpreter()
from .interpreter import Interpreter
autoai = Interpreter()
autoai.auto_run = True
autoai.chat(usertext[2:])
elif usertext[0] == ":":
Expand Down
39 changes: 0 additions & 39 deletions setup.py

This file was deleted.

0 comments on commit cda2e48

Please sign in to comment.