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

handle large chunks that get split by http lib #46

Closed

Conversation

oxaronick
Copy link
Contributor

@oxaronick oxaronick commented Jan 24, 2024

Closes #44 by looking for HTTP chunk delimiters in the HTTP stream coming back from Ollama.

Here's an example of a stream captured with tcpdump:

HTTP/1.1 200 OK
Content-Type: application/x-ndjson
Date: Wed, 24 Jan 2024 17:14:00 GMT
Connection: close
Transfer-Encoding: chunked

69
{"model":"codellama:13b-code","created_at":"2024-01-24T17:14:00.708054246Z","response":"(","done":false}

6e
{"model":"codellama:13b-code","created_at":"2024-01-24T17:14:00.719238491Z","response":"module","done":false}

69
{"model":"codellama:13b-code","created_at":"2024-01-24T17:14:00.730212903Z","response":".","done":false}

The server is sending two newlines at the end of each chunk. This PR updates streamResponse to concatenate all the data it receives from the HTTP stream until it gets a piece of data ending with \n, then it send all the data (the whole HTTP chunk) to the caller.

Tested with HTTP chunks that did get split coming back from the server as well as normal chunks.

@oxaronick
Copy link
Contributor Author

@rjmacarthy

@oxaronick oxaronick changed the title WIP: handle large chunks that get split by http lib handle large chunks that get split by http lib Jan 24, 2024
@rjmacarthy
Copy link
Collaborator

Thanks for the PR see comment #44 (comment) which includes a fix similar already to this. I did try to notify you before you submitted, thanks.

@oxaronick
Copy link
Contributor Author

Thanks for the PR see comment #44 (comment) which includes a fix similar already to this. I did try to notify you before you submitted, thanks.

Yeah, np, I just got into it and didn't see your message until after.

@oxaronick oxaronick closed this Jan 24, 2024
@rjmacarthy rjmacarthy reopened this Jan 24, 2024
@rjmacarthy
Copy link
Collaborator

Reopening as may be better solution

@rjmacarthy
Copy link
Collaborator

Thanks @rcgtnick I am cherry-picking your commit into #48 and will release it.

@rjmacarthy
Copy link
Collaborator

Closed in favour of #48

@rjmacarthy rjmacarthy closed this Jan 25, 2024
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

Successfully merging this pull request may close these issues.

JSON parse errors handling streamed responses
2 participants