Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config llm.maxtokens is not taken into account #120

Open
cryptax opened this issue Feb 13, 2025 · 1 comment
Open

Config llm.maxtokens is not taken into account #120

cryptax opened this issue Feb 13, 2025 · 1 comment

Comments

@cryptax
Copy link
Contributor

cryptax commented Feb 13, 2025

To my understanding, the r2ai setting llm.maxtokens is the maximum number of tokens to be sent to the AI.
It looks like currently, r2ai does not care about this setting and sends whatever amount it likes.
This is an issue, especially for paid access models where the payment depends on the number of tokens...

In the following test, I voluntarily set maxtokens ridiculously low to 10.

$ R2AI_LOG=1 ~/git/r2ai/r2ai.sh /home/axelle/git/research/ai/subs_crack
WARN: Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
[R2AI] OpenAI API key loaded from ~/.r2ai.openai-key
[R2AI] Anthropic API key loaded from ~/.r2ai.anthropic-key
[r2ai:0x000010d0]> -e llm.maxtokens=10

Then, I ask r2ai to decompile in auto mode and the log show it is sending far more than 10 tokens.

[r2ai:0x000010d0]> ' decompile the main
[02/13/25 14:12:19] DEBUG    r2ai - DEBUG - decompile the main                                                                                        interpreter.py:297
[02/13/25 14:12:21] DEBUG    r2ai.anthropic - DEBUG - [{'role': 'user', 'content': 'decompile the main'}]                                             interpreter.py:388
 ⠋ 0.0s                    DEBUG    r2ai - DEBUG - [{'role': 'system', 'content': "\nYou are a reverse engineer and you are using radare2 to analyze a binary.\nThe auto.py:415
                             user will ask questions about the binary and you will respond with the answer to the best of your ability.\n\n# Guidelines\n-              
                             Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.\n- Reasoning Before                  
                             Conclusions**: Encourage reasoning steps before any conclusions are reached.\n- Assume the user is always asking you about the             
                             binary, unless they're specifically asking you for radare2 help.\n- The binary has already been loaded. You can interact with              
                             the binary using the r2cmd tool.\n- `this` or `here` might refer to the current address in the binary or the binary itself.\n-             
                             If you need more information, try to use the r2cmd tool to run commands before answering.\n- You can use the r2cmd tool                    
                             multiple times if you need or you can pass a command with pipes if you need to chain commands.\n- If you're asked to decompile             
                             a function, make sure to return the code in the language you think it was originally written and rewrite it to be as easy as               
                             possible to be understood. Make sure you use descriptive variable and function names and add comments.\n- Don't just                       
                             regurgitate the same code, figure out what it's doing and rewrite it to be more understandable.\n- If you need to run a command            
                             in r2 before answering, you can use the r2cmd tool\n- Do not repeat commands if you already know the answer.\n- Formulate a                
                             plan. Think step by step. Analyze the binary as much as possible before answering.\n- You must keep going until you have a                 
                             final answer.\n- Double check that final answer. Make sure you didn't miss anything.\n- Make sure you call tools and functions             
                             correctly.\n\nHere is some information about the binary to get you started:\n> aaa;iI;afl\narch     x86\nbaddr    0x0\nbinsz               
                             14459\nbintype  elf\nbits     64\ncanary   false\ninjprot  false\nclass    ELF64\ncompiler GCC: (Debian 12.2.0-14)                         
                             12.2.0\ncrypto   false\nendian   little\nhavecode true\nintrp    /lib64/ld-linux-x86-64.so.2\nladdr    0x0\nlang     c\nlinenum            
                             true\nlsyms    true\nmachine  AMD x86-64 architecture\nnx       true\nos       linux\npic      true\nrelocs   true\nrelro                  
                             partial\nrpath    NONE\nsanitize false\nstatic   false\nstripped false\nsubsys   linux\nva       true\n0x00001030    1      6              
                             sym.imp.puts\n0x00001040    1      6 sym.imp.strlen\n0x00001050    1      6 sym.imp.printf\n0x00001060    1      6                         
                             sym.imp.strcspn\n0x00001070    1      6 sym.imp.memcmp\n0x00001080    1      6 sym.imp.fgets\n0x00001090    1      6                       
                             sym.imp.tolower\n0x000010a0    1      6 sym.imp.exit\n0x000010b0    1      6 sym.imp.__ctype_b_loc\n0x000010c0    1      6                 
                             sym.imp.__cxa_finalize\n0x000010d0    1     33 entry0\n0x00001100    4     34 sym.deregister_tm_clones\n0x00001130    4     51             
                             sym.register_tm_clones\n0x00001170    5     54 entry.fini0\n0x000011b0    1      9 entry.init0\n0x000013f4    1      9                     
                             sym._fini\n0x000012f1    5    256 main\n0x000011b9   12    312 sym.substitute\n0x00001000    3     23 sym._init\n\n"}, {'role':            
                             'user', 'content': 'decompile the main'}]                                                                                                  
 ⠙ 1.1s[02/13/25 14:12:22] DEBUG    r2ai - DEBUG - chat completion <litellm.litellm_core_utils.streaming_handler.CustomStreamWrapper object at 0x7f8a35cea2f0>      auto.py:393
                    
assistant
I'll help you decompile the main function
anthropic/claude-3-5-sonnet-20241022 | total: $0.0027150000 | run: $0.0027150000 | 1 / 100 | 1s / 1s
@cryptax
Copy link
Contributor Author

cryptax commented Feb 13, 2025

Actually, llm.maxtokens might be limiting the output tokens of the AI... ?
If so, I'd love to have also a setting to limit input tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant