-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Basic agents, function tools and models checks
- Loading branch information
1 parent
52d0d2a
commit 067637a
Showing
9 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from tests.fixtures.fixtures_tools import * # noqa: F401, F403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def basic_function_for_tool() -> Callable: | ||
def get_current_temperature(location: str, unit: str) -> float: | ||
""" | ||
Get the current temperature at a location. | ||
Args: | ||
location: The location to get the temperature for, in the format "City, Country" | ||
unit: The unit to return the temperature in. (choices: ["celsius", "fahrenheit"]) | ||
Returns: | ||
The current temperature at the specified location in the specified units, as a float. | ||
""" | ||
return 22.0 # A real function should probably actually get the temperature! | ||
|
||
return get_current_temperature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from fastapi import FastAPI | ||
|
||
from libertai_agents.agents import ChatAgent | ||
from libertai_agents.interfaces.tools import Tool | ||
from libertai_agents.models import get_model | ||
from libertai_agents.models.base import ModelId | ||
from libertai_agents.models.models import ModelConfiguration | ||
|
||
MODEL_ID: ModelId = "NousResearch/Hermes-3-Llama-3.1-8B" | ||
|
||
|
||
def test_create_chat_agent_minimal(): | ||
agent = ChatAgent(model=get_model(MODEL_ID)) | ||
|
||
assert len(agent.tools) == 0 | ||
assert agent.model.model_id == MODEL_ID | ||
assert isinstance(agent.app, FastAPI) | ||
|
||
|
||
def test_create_chat_agent_with_config(basic_function_for_tool): | ||
context_length = 42 | ||
|
||
agent = ChatAgent( | ||
model=get_model( | ||
MODEL_ID, | ||
custom_configuration=ModelConfiguration( | ||
vm_url="https://example.org", context_length=context_length | ||
), | ||
), | ||
tools=[Tool.from_function(basic_function_for_tool)], | ||
expose_api=False, | ||
) | ||
assert agent.model.context_length == context_length | ||
assert not hasattr(agent, "app") | ||
assert len(agent.tools) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
from libertai_agents.models import Model, get_model | ||
|
||
|
||
def test_get_model_basic(): | ||
model = get_model("NousResearch/Hermes-3-Llama-3.1-8B") | ||
|
||
assert isinstance(model, Model) | ||
|
||
|
||
def test_get_model_invalid_id(): | ||
with pytest.raises(ValueError): | ||
_model = get_model(model_id="random-string") # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from libertai_agents.interfaces.tools import Tool | ||
|
||
|
||
def test_function_example_tool(basic_function_for_tool): | ||
libertai_tool = Tool.from_function(basic_function_for_tool) | ||
assert libertai_tool.name == basic_function_for_tool.__name__ | ||
|
||
|
||
# TODO: add test with Python 3.10+ union style when https://github.com/huggingface/transformers/pull/35103 merged + new release |