Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This commit addresses four separate bugs identified in the GitHub issues, improving the robustness and correctness of the library.

This commit provides fixes for four separate bugs that affected streaming, JSON handling, and the random model selection fallback.

The following issues have been addressed:

- **#132: `jq error` in `ollama_chat_stream`**
  The streaming functions (`ollama_chat_stream` and `ollama_chat_stream_json`) were incorrectly calling `ollama_chat`, which disables streaming. This caused them to parse a single pretty-printed JSON object as a stream, leading to `jq` errors. The fix ensures they call `ollama_chat_json` directly, which respects the streaming setting.

- **#131: `random awk` fallback is buggy**
  The `awk` command in `ollama_model_random` was missing `BEGIN{srand()}` to seed the random number generator and used a non-standard formula. The command has been replaced with a more robust version that correctly selects a random model.

- **#130: Incorrect `curl http_code` parsing**
  The `_call_curl` function used `tail` to extract the HTTP status code, which was unreliable if the response body ended in a newline. This has been fixed by using a unique delimiter to safely separate the body from the status code.

- **#114: Invalid JSON with slashes in model names**
  The `_ollama_chat_payload` function constructed the `messages` JSON array using fragile string concatenation. This has been refactored to build the payload safely within a single `jq` command, preventing errors with special characters.
@attogram attogram marked this pull request as ready for review August 23, 2025 13:30
@attogram attogram merged commit 613505b into main Aug 23, 2025
@attogram attogram deleted the fix-multiple-bugs branch August 23, 2025 14:29
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.

2 participants