GithubHelp home page GithubHelp logo

xplo8e / r2ai Goto Github PK

View Code? Open in Web Editor NEW

This project forked from radareorg/r2ai

0.0 0.0 0.0 2.31 MB

local language model for radare2

Home Page: https://www.radare.org

Shell 0.36% JavaScript 1.30% C++ 42.77% Python 52.69% C 1.41% TypeScript 0.41% Makefile 1.07%

r2ai's Introduction

,______  .______ .______  ,___
: __   \ \____  |:      \ : __|
|  \____|/  ____||  _,_  || : |
|   :  \ \   .  ||   :   ||   |
|   |___\ \__:__||___|   ||   |
|___|        :       |___||___|
             *       --pancake

Run a language model in local, without internet, to entertain you or help answering questions about radare2 or reverse engineering in general. Note that models used by r2ai are pulled from external sources which may behave different or respond unrealible information. That's why there's an ongoing effort into improving the post-finetuning using memgpt-like techniques which can't get better without your help!

Features

  • Prompt the language model without internet requirements
  • Index large codebases or markdown books using a vector database
  • Slurp file contents and make actions on that
  • Embed the output of an r2 command and resolve questions on the given data
  • Define different system-level assistant role
  • Set environment variables to provide context to the language model
  • Live with repl and batch mode from cli or r2 prompt
  • Accessible as an r2lang-python plugin, keeps session state inside radare2
  • Scriptable from python, bash, r2pipe, and javascript (r2papi)
  • Use different models, dynamically adjust query template
    • Load multiple models and make them talk between them

Installation

This is optional ans system dependant. but on recent Debian/Ubuntu systems the pip tool is no longer working, because it conflicts with the system packages. The best way to do this is with venv:

python -m venv venv
. venv/bin/activate
pip install -r requirements.txt

Optionally if you want better indexer for the data install vectordb.

# on Linux
pip install vectordb2

# on macOS
pip install vectordb2 spacy
python -m spacy download en_core_web_sm
brew install llvm
export PATH=/opt/homebrew/Cellar/llvm/17.0.5/bin/:$PATH
CC=clang CXX=clang++ pip install git+https://github.com/teemupitkanen/mrpt/

r2pm installation

When running installed via r2pm you can execute it like this:

r2pm -r r2ai

Additionally you can get the r2ai command inside r2 to run as an rlang plugin by installing the bindings:

r2pm -i rlang-python
make user-install

Windows

On native Windows follow these instructions (no need to install radare2 or use r2pm), note that you need Python 3.8 or higher:

git clone https://github.com/radareorg/r2ai
cd r2ai
set PATH=C:\Users\YOURUSERNAME\Local\Programs\Python\Python39\;%PATH%
python -m pip -r requirements.txt
python -m pip install pyreadline3
python main.py

Usage

There are 4 different ways to run r2ai:

  • Standalone and interactive: r2pm -r r2ai or python main.py
  • Batch mode: r2ai '-r act as a calculator' '3+3=?'
  • From radare2 (requires r2pm -ci rlang-python): r2 -c 'r2ai -h'
  • Using r2pipe: #!pipe python main.py
    • Define a macro command: '$r2ai=#!pipe python main.py

Auto mode

When using OpenAI, Claude or any of the Functionary local models you can use the auto mode which permits the language model to execute r2 commands, analyze the output in loop and in a loop until it is resolved. Here's a sample session to achieve that:

$ . env/bin/activate
(env)$ r2 /bin/ls
[0x00000000]> '$r2ai=#!pipe python main.py
[0x00000000]> $r2ai '-m openai:gpt-4'
[0x00000000]> $r2ai "' list the imports for this program"
[0x00000000]> $r2ai "' draw me a donut"
[0x00000000]> $r2ai "' decompile current function and explain it"

Examples

You can interact with r2ai from standalone python, from r2pipe via r2 keeping a global state or using the javascript intrepreter embedded inside radare2.

Development/Testing

Just run make .. or well python main.py

TODO

  • add "undo" command to drop the last message
  • dump / restore conversational states (see -L command)

Kudos

The original code of r2ai is based on OpenInterpreter. I want to thanks all the contributors to this project as they made it possible to build r2ai taking their code as source for this. Kudos to Killian and all the contributors.

r2ai's People

Contributors

radare avatar dnakov avatar xplo8e avatar trufae avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.