Skip to content

fix: resolve windows tempfile locking, tool schema generation, and add client improvements - #778

Open
SiddardhaShayini wants to merge 1 commit into
ollama:mainfrom
SiddardhaShayini:fix/windows-tests-and-features
Open

SiddardhaShayini wants to merge 1 commit into
ollama:mainfrom
SiddardhaShayini:fix/windows-tests-and-features

Conversation

@SiddardhaShayini

Copy link
Copy Markdown

Summary of Changes

This pull request addresses cross-platform Windows test failures, fixes tool parameter schema generation bugs, and introduces quality-of-life client enhancements:

1. Bug Fixes

  • Windows NamedTemporaryFile file-locking (Fixes Tests fail on Windows due to NamedTemporaryFile locking behavior #676): Replaced tempfile.NamedTemporaryFile() in tests with pytest's standard tmp_path fixture (matching existing tests like test_client_chat_images) to avoid Windows PermissionError: [Errno 13] Permission denied. All 8 previously failing Windows tests now pass.
  • Crash on None tool functions (Fixes ChatRequest.model_dump() crashes when a tool has no parameters or no function #733): Guarded ChatRequest.serialize_model against tools where function or parameters is None.
  • Function tool variable arguments (Fixes convert_function_to_tool exposes *args and **kwargs as required string parameters #735): Filtered *args (VAR_POSITIONAL) and **kwargs (VAR_KEYWORD) in convert_function_to_tool so arbitrary arguments are not exposed as required parameters.
  • Tool parameter defaults: Inspected parameter default values so arguments with defaults are not erroneously included in required.
  • Array items & Enum schema preservation: Preserved items (e.g. list[str]) and enum / $ref on properties produced by convert_function_to_tool.
  • Preserve empty string content: Fixed _copy_messages in _client.py using if v is not None: so empty content (content='') is retained.
  • Bearer token check consistency: Added missing bearer authorization validation in AsyncClient.web_search and AsyncClient.web_fetch to match Client.
  • Dead code removal: Removed unused _as_path helper function and unused PathLike import from _client.py.

2. Improvements & Features

  • Direct api_key argument: Added first-class api_key: Optional[str] = None support directly to Client(..., api_key=...) and AsyncClient(..., api_key=...).
  • Message.ToolCall enhancements: Added id: Optional[str] = None and type: Optional[str] = 'function' fields to Message.ToolCall.
  • Expose public client methods in __all__: Added public functions (chat, generate, embed, etc.) to ollama.__all__ and added module-level create_blob = _client.create_blob.

3. Documentation & Examples

  • Added CONTRIBUTING.md with development setup, testing, formatting, and PR submission guidelines.
  • Added examples/web-fetch.py and examples/context-manager.py.
  • Updated README.md and examples/README.md.

Verification

  • Tested with uvx hatch test: 133 / 133 tests passing.
  • Validated formatting and linting: uv run ruff check . and uv run ruff format --check . (49 files clean).
  • Confirmed lockfile integrity: uv lock --check.

…d client improvements

- Fix ollama#676: replace tempfile.NamedTemporaryFile with tmp_path in tests to prevent Windows file locking PermissionError
- Fix ollama#733: guard ChatRequest.serialize_model against None tool functions and parameters
- Fix ollama#735: filter *args and **kwargs in convert_function_to_tool and correctly map default parameter values
- Preserve array items, enum, and  in tool property generation
- Preserve empty string content in _copy_messages
- Add bearer token validation in AsyncClient.web_search and web_fetch to match Client
- Add direct api_key support to BaseClient, Client, and AsyncClient
- Add id and type fields to Message.ToolCall
- Export public client methods in ollama.__all__ and add create_blob
- Remove unused _as_path dead code in _client.py
- Add CONTRIBUTING.md guide and new examples (web-fetch, context-manager)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant