[GH-ISSUE #1574] Sending several requests to the server in quick succession appears to cause some responses to fail #26624

Closed
opened 2026-04-22 03:00:26 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @charstorm on GitHub (Dec 17, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1574

Hi,

First, I want to thank everyone working on this project. I appreciate your efforts.

I was testing ollama server and I noticed that it sometimes gave empty responses. I found out that it happens when a request is made right after the previous one. Adding a sleep seems to solve the issue. Here is some code to demonstrate the issue:


import time
import json
import requests

DEFAULT_URL = "http://localhost:11434/api/generate"
DEFAULT_MODEL = "mistral"

def generate(prompt, model=DEFAULT_MODEL, url=DEFAULT_URL):
    post_data = {
        "prompt": prompt, "model": model, "stream": True
    }
    response = requests.post(url, json=post_data)
    response.raise_for_status()
    parts = []
    for line in response.iter_lines():
        body = json.loads(line)
        if "error" in body:
            raise Exception(body["error"])

        content = body.get("response", "")
        parts.append(content)

        if body.get("done"):
            break

    return "".join(parts).strip()


def test():
    prompts = [
        "What is radian?", "What is meridian?",
        "What is steradian?", "What is circadian?"
    ]
    for prompt in prompts:
        print("Prompt:", prompt)
        response = generate(prompt)
        if not response:
            print("ERROR: got empty response!")
        else:
            print("Response:", response)
        print("----"*20)
        # time.sleep(0.3)  # <-- this is needed to avoid empty responses


if __name__ == "__main__":
    test()

Originally created by @charstorm on GitHub (Dec 17, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1574 Hi, First, I want to thank everyone working on this project. I appreciate your efforts. I was testing ollama server and I noticed that it sometimes gave empty responses. I found out that it happens when a request is made right after the previous one. Adding a sleep seems to solve the issue. Here is some code to demonstrate the issue: ```python import time import json import requests DEFAULT_URL = "http://localhost:11434/api/generate" DEFAULT_MODEL = "mistral" def generate(prompt, model=DEFAULT_MODEL, url=DEFAULT_URL): post_data = { "prompt": prompt, "model": model, "stream": True } response = requests.post(url, json=post_data) response.raise_for_status() parts = [] for line in response.iter_lines(): body = json.loads(line) if "error" in body: raise Exception(body["error"]) content = body.get("response", "") parts.append(content) if body.get("done"): break return "".join(parts).strip() def test(): prompts = [ "What is radian?", "What is meridian?", "What is steradian?", "What is circadian?" ] for prompt in prompts: print("Prompt:", prompt) response = generate(prompt) if not response: print("ERROR: got empty response!") else: print("Response:", response) print("----"*20) # time.sleep(0.3) # <-- this is needed to avoid empty responses if __name__ == "__main__": test() ```
Author
Owner

@jmorganca commented on GitHub (Dec 17, 2023):

Hi @charstorm, thanks for creating an issue (and including some code to reproduce it!)

This issue should have been fixed as of 0.1.14: https://github.com/jmorganca/ollama/releases/tag/v0.1.14

Do you know which version of Ollama you might be running (you can check with ollama -v)? If it's below 0.1.14, try upgrading and let me know if that fixes it!

<!-- gh-comment-id:1859264252 --> @jmorganca commented on GitHub (Dec 17, 2023): Hi @charstorm, thanks for creating an issue (and including some code to reproduce it!) This issue should have been fixed as of 0.1.14: https://github.com/jmorganca/ollama/releases/tag/v0.1.14 Do you know which version of Ollama you might be running (you can check with `ollama -v`)? If it's below 0.1.14, try upgrading and let me know if that fixes it!
Author
Owner

@charstorm commented on GitHub (Dec 17, 2023):

You are right. I was on 0.1.13. Just downloaded and tested 0.1.14 and it works without having to add sleep.
Thank you!

<!-- gh-comment-id:1859268000 --> @charstorm commented on GitHub (Dec 17, 2023): You are right. I was on 0.1.13. Just downloaded and tested 0.1.14 and it works without having to add sleep. Thank you!
Author
Owner

@igorschlum commented on GitHub (Dec 17, 2023):

@charstorm Great. Thank you for the script. Could you please mark the issue as Closed ?

<!-- gh-comment-id:1859271109 --> @igorschlum commented on GitHub (Dec 17, 2023): @charstorm Great. Thank you for the script. Could you please mark the issue as Closed ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#26624