Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

fix: accept a path-like tool_index_path, as weights already does (#110)

kevin630176107034
diff --git a/needle/__init__.py b/needle/__init__.py
index 516130b..cd24b20 100644
--- a/needle/__init__.py
+++ b/needle/__init__.py
@@ -148,7 +148,8 @@ class Needle:
self._tool_schemas = [entry for entry in (parsed_tools or [])
if isinstance(entry, dict)]
self._seen_years = set()
- self._tool_index_path = tool_index_path.encode("utf-8") if tool_index_path else None
+ self._tool_index_path = (os.fspath(tool_index_path).encode("utf-8")
+ if tool_index_path else None)
self._buffer = ctypes.create_string_buffer(buffer_size)
if self._weights:
self._worker = FineTuneWorker(
diff --git a/tests/test_weights.py b/tests/test_weights.py
index 1805f23..d90ac89 100644
--- a/tests/test_weights.py
+++ b/tests/test_weights.py
@@ -1,4 +1,5 @@
import json
+import os
import warnings
import pytest
@@ -252,3 +253,27 @@ def test_extraction_rejects_fabricated_temporal_year():
assert needle._source_years("due September 5") == set()
assert needle._source_years("due 5th September 42") == {42}
assert needle._source_years("Invoice 42 is due tomorrow at 5") == set()
+
+
+def test_tool_index_path_takes_a_path_object(engine, tmp_path):
+ import needle
+
+ index = tmp_path / "tools.idx"
+ agent = needle.Needle(tools="[]", tool_index_path=index)
+
+ assert agent._tool_index_path == os.fspath(index).encode("utf-8")
+
+
+def test_tool_index_path_agrees_between_the_base_and_tuned_paths(engine, tuned, tmp_path):
+ import needle
+
+ index = tmp_path / "tools.idx"
+ base = needle.Needle(tools="[]", tool_index_path=index)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ needle.Needle(tools="[]", weights=tuned, tool_index_path=index)
+
+ started = [call for call in engine
+ if isinstance(call, tuple) and call[0] == "worker_start"]
+ assert started
+ assert base._tool_index_path.decode("utf-8") == os.fspath(index)