ollama-api icon indicating copy to clipboard operation
ollama-api copied to clipboard

SyntaxError: Unexpected token '<', "

Open KokinSok opened this issue 1 year ago • 2 comments

Great product, I like it! Thank You! I am getting: SyntaxError: Unexpected token '<', "

Models loaded, and not getting any other errors. Any ideas? Thank You!

KokinSok avatar Mar 31 '24 02:03 KokinSok

Found the problem, was my error:

def run_model_question(question, model):
    # Define the curl command    
    curl_command = f"curl http://localhost:11434/api/generate -d \"{{\\\"model\\\":\\\"{model}\\\", \\\"prompt\\\":\\\"{question}\\\"}}\""
    print("Command: " + curl_command)
    # Run the command and capture the output
    output = subprocess.check_output(curl_command, shell=True, encoding='utf-8')

    # Process the output as JSON and extract "response" values
    responses = [json.loads(response)["response"] for response in output.strip().split('\n')]

    # Create a JSON containing only "response" values
    response_json = {'responses': responses}

    return response_json

I had to change the strings, running on windows. In changing them, I did not realise it would get so complicated.

KokinSok avatar Mar 31 '24 05:03 KokinSok

Hi Kokin. We fixed this in a updated test version. Thank you for the feedback and will commit the new code once testing is completed.

Jiffy-JM avatar Apr 08 '24 19:04 Jiffy-JM