Move test files (#128)
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
# type: ignore
|
||||
|
||||
"""Test that @llm_rollout and @rollout decorators preserve function executability."""
|
||||
|
||||
import inspect
|
||||
from typing import Any, cast
|
||||
|
||||
import pytest
|
||||
|
||||
from agentlightning.litagent import LitAgentLLM, llm_rollout, rollout
|
||||
from agentlightning.types import LLM
|
||||
|
||||
|
||||
@llm_rollout
|
||||
def sample_llm_rollout_func(task, llm):
|
||||
def sample_llm_rollout_func(task: Any, llm: LLM) -> float:
|
||||
"""A test function with llm_rollout decorator."""
|
||||
return f"Processed task: {task} with LLM: {llm}"
|
||||
# Fake a float to bypass the type checker
|
||||
return cast(float, f"Processed task: {task} with LLM: {llm}")
|
||||
|
||||
|
||||
@rollout
|
||||
def sample_rollout_func(task, llm):
|
||||
def sample_rollout_func(task: Any, llm: LLM) -> float:
|
||||
"""A test function with rollout decorator."""
|
||||
return f"Processed task: {task} with LLM: {llm}"
|
||||
return cast(float, f"Processed task: {task} with LLM: {llm}")
|
||||
|
||||
|
||||
def test_llm_rollout_preserves_executability():
|
||||
@@ -40,7 +41,7 @@ def test_llm_rollout_preserves_executability():
|
||||
def test_llm_rollout_preserves_metadata():
|
||||
"""Test that @llm_rollout preserves function metadata."""
|
||||
# Function name should be preserved
|
||||
assert sample_llm_rollout_func.__name__ == "sample_llm_rollout_func"
|
||||
assert sample_llm_rollout_func.__name__ == "sample_llm_rollout_func" # type: ignore
|
||||
|
||||
# Docstring should be preserved
|
||||
assert sample_llm_rollout_func.__doc__ == "A test function with llm_rollout decorator."
|
||||
@@ -74,7 +75,7 @@ def test_rollout_preserves_executability():
|
||||
assert callable(sample_rollout_func)
|
||||
|
||||
# Function should execute and return expected result
|
||||
result = sample_rollout_func(test_task, test_llm)
|
||||
result = sample_rollout_func(test_task, test_llm) # type: ignore
|
||||
expected = f"Processed task: {test_task} with LLM: {test_llm}"
|
||||
assert result == expected
|
||||
|
||||
@@ -82,7 +83,7 @@ def test_rollout_preserves_executability():
|
||||
def test_rollout_preserves_metadata():
|
||||
"""Test that @rollout preserves function metadata."""
|
||||
# Function name should be preserved
|
||||
assert sample_rollout_func.__name__ == "sample_rollout_func"
|
||||
assert sample_rollout_func.__name__ == "sample_rollout_func" # type: ignore
|
||||
|
||||
# Docstring should be preserved
|
||||
assert sample_rollout_func.__doc__ == "A test function with rollout decorator."
|
||||
@@ -100,7 +101,7 @@ def test_rollout_returns_litagent_instance():
|
||||
|
||||
def test_rollout_preserves_signature():
|
||||
"""Test that @rollout preserves function signature."""
|
||||
sig = inspect.signature(sample_rollout_func)
|
||||
sig = inspect.signature(sample_rollout_func) # type: ignore
|
||||
params = list(sig.parameters.keys())
|
||||
|
||||
# Should have the expected parameters
|
||||
@@ -112,9 +113,9 @@ async def test_async_function_with_llm_rollout():
|
||||
"""Test that async functions work with @llm_rollout decorator."""
|
||||
|
||||
@llm_rollout
|
||||
async def async_agent(task, llm):
|
||||
async def async_agent(task: Any, llm: LLM) -> float:
|
||||
"""An async test function."""
|
||||
return f"Async processed: {task} with {llm}"
|
||||
return cast(float, f"Async processed: {task} with {llm}")
|
||||
|
||||
# Should be callable
|
||||
assert callable(async_agent)
|
||||
@@ -132,15 +133,15 @@ async def test_async_function_with_rollout():
|
||||
"""Test that async functions work with @rollout decorator."""
|
||||
|
||||
@rollout
|
||||
async def async_agent(task, llm):
|
||||
async def async_agent(task: Any, llm: LLM) -> float:
|
||||
"""An async test function."""
|
||||
return f"Async processed: {task} with {llm}"
|
||||
return cast(float, f"Async processed: {task} with {llm}")
|
||||
|
||||
# Should be callable
|
||||
assert callable(async_agent)
|
||||
|
||||
# Should preserve async nature when called directly
|
||||
result = await async_agent("test", "llm")
|
||||
result = await async_agent("test", "llm") # type: ignore
|
||||
assert result == "Async processed: test with llm"
|
||||
|
||||
# Should be marked as async
|
||||
@@ -69,7 +69,7 @@ from agentlightning.tracer.agentops import AgentOpsTracer, LightningSpanProcesso
|
||||
from agentlightning.tracer.http import HttpTracer
|
||||
from agentlightning.types import Triplet
|
||||
|
||||
from .common.tracer import clear_agentops_init, clear_tracer_provider
|
||||
from ..common.tracer import clear_agentops_init, clear_tracer_provider
|
||||
|
||||
USE_OPENAI = os.environ.get("USE_OPENAI", "false").lower() == "true"
|
||||
if USE_OPENAI:
|
||||
@@ -110,7 +110,7 @@ class MockOpenAICompatibleServer:
|
||||
self._setup_routes()
|
||||
|
||||
def _load_prompt_caches(self):
|
||||
cache_path = os.path.join(os.path.dirname(__file__), "assets/prompt_caches.jsonl")
|
||||
cache_path = os.path.join(os.path.dirname(__file__), "../assets/prompt_caches.jsonl")
|
||||
caches = []
|
||||
if os.path.exists(cache_path):
|
||||
with open(cache_path, "r") as f:
|
||||
@@ -280,7 +280,7 @@ def agent_langchain_tooluse() -> None:
|
||||
def agent_langgraph() -> None:
|
||||
"""An agent built with LangGraph for stateful, cyclical workflows."""
|
||||
llm = init_chat_model("openai:" + OPENAI_MODEL, openai_api_base=OPENAI_BASE_URL, openai_api_key=OPENAI_API_KEY)
|
||||
db = SQLDatabase.from_uri("sqlite:///" + os.path.join(os.path.dirname(__file__), "assets/chinook.db"))
|
||||
db = SQLDatabase.from_uri("sqlite:///" + os.path.join(os.path.dirname(__file__), "../assets/chinook.db"))
|
||||
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
|
||||
tools = toolkit.get_tools()
|
||||
|
||||
@@ -769,7 +769,7 @@ def create_prompt_caches() -> None:
|
||||
with tracer.trace_context():
|
||||
run_all()
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), "assets/prompt_caches.jsonl"), "w") as f:
|
||||
with open(os.path.join(os.path.dirname(__file__), "../assets/prompt_caches.jsonl"), "w") as f:
|
||||
for span in tracer._last_records.requests.values():
|
||||
if span.url.startswith(OPENAI_BASE_URL) and span.status_code < 400 and span.response.content:
|
||||
f.write(
|
||||
Reference in New Issue
Block a user