OpenInterpreter / open-interpreter

A natural language interface for computers
http://openinterpreter.com/
GNU Affero General Public License v3.0
52.22k stars 4.61k forks source link

If you have not run with GPT-4, interpreter will crash when using local models without internet access. #827

Open Notnaton opened 9 months ago

Notnaton commented 9 months ago

Describe the bug

def count_tokens(text="", model="gpt-4"):
    """
    Count the number of tokens in a string
    """

    # Fix bug where models starting with openai/ for example can't find tokenizer
    if '/' in model:
        model = model.split('/')[-1]

    # At least give an estimate if we can't find the tokenizer
    try:
        encoder = tiktoken.encoding_for_model(model)
    except KeyError:
        print(f"Could not find tokenizer for {model}. Defaulting to gpt-4 tokenizer.")
        encoder = tiktoken.encoding_for_model("gpt-4")

    return len(encoder.encode(text))

This code in count_tokens.py cause interpreter to crash when using interpreter offline with local models without ever running using gpt-4.

Reproduce

Delete cache install interpreter disconnect internet run using local model

Expected behavior

Interpreter should work offline

Screenshots

No response

Open Interpreter version

0.1.17

Python version

3.11.6

Operating System name and version

Windows 11

Additional context

No response

MikeBirdTech commented 6 months ago

Hey @Notnaton Is this still an issue? Thanks!

Notnaton commented 5 months ago

I have a fix for this I think. Will work on it when I'm home today