Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion needle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def __init__(self, tools=None, system=None, weights=None, tool_index_path=None,
self._n_tools = len(json.loads(tools_json))
except (json.JSONDecodeError, TypeError):
self._n_tools = None
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(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_weights.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import warnings

import pytest
Expand Down Expand Up @@ -202,3 +203,27 @@ class Invoice(pydantic.BaseModel):
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)