fix(ci): redo agentfile upload util and tweak secret (#4033)
This commit is contained in:
@@ -3,7 +3,7 @@ import os
|
||||
import time
|
||||
from typing import Optional, Union
|
||||
|
||||
import requests
|
||||
from letta_client import AsyncLetta, Letta
|
||||
|
||||
from letta.functions.functions import parse_source_code
|
||||
from letta.functions.schema_generator import generate_schema
|
||||
@@ -254,7 +254,8 @@ def validate_context_window_overview(
|
||||
assert len(overview.functions_definitions) > 0
|
||||
|
||||
|
||||
def upload_test_agentfile_from_disk(server_url: str, filename: str) -> ImportedAgentsResponse:
|
||||
# Changed this from server_url to client since client may be authenticated or not
|
||||
def upload_test_agentfile_from_disk(client: Letta, filename: str) -> ImportedAgentsResponse:
|
||||
"""
|
||||
Upload a given .af file to live FastAPI server.
|
||||
"""
|
||||
@@ -263,18 +264,17 @@ def upload_test_agentfile_from_disk(server_url: str, filename: str) -> ImportedA
|
||||
file_path = os.path.join(path_to_test_agent_files, filename)
|
||||
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": (filename, f, "application/json")}
|
||||
return client.agents.import_file(file=f, append_copy_suffix=True, override_existing_tools=False)
|
||||
|
||||
# Send parameters as form data instead of query parameters
|
||||
form_data = {
|
||||
"append_copy_suffix": "true",
|
||||
"override_existing_tools": "false",
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{server_url}/v1/agents/import",
|
||||
headers={"user_id": ""},
|
||||
files=files,
|
||||
data=form_data, # Send as form data
|
||||
)
|
||||
return ImportedAgentsResponse(**response.json())
|
||||
async def upload_test_agentfile_from_disk_async(client: AsyncLetta, filename: str) -> ImportedAgentsResponse:
|
||||
"""
|
||||
Upload a given .af file to live FastAPI server.
|
||||
"""
|
||||
path_to_current_file = os.path.dirname(__file__)
|
||||
path_to_test_agent_files = path_to_current_file.removesuffix("/helpers") + "/test_agent_files"
|
||||
file_path = os.path.join(path_to_test_agent_files, filename)
|
||||
|
||||
with open(file_path, "rb") as f:
|
||||
uploaded = await client.agents.import_file(file=f, append_copy_suffix=True, override_existing_tools=False)
|
||||
return uploaded
|
||||
|
||||
@@ -10,7 +10,7 @@ from dotenv import load_dotenv
|
||||
from letta_client import AsyncLetta, MessageCreate, ReasoningMessage, ToolCallMessage
|
||||
from letta_client.core import RequestOptions
|
||||
|
||||
from tests.helpers.utils import upload_test_agentfile_from_disk
|
||||
from tests.helpers.utils import upload_test_agentfile_from_disk_async
|
||||
|
||||
REASONING_THROTTLE_MS = 100
|
||||
TEST_USER_MESSAGE = "What products or services does 11x AI sell?"
|
||||
@@ -66,7 +66,7 @@ async def test_pinecone_tool(client: AsyncLetta, server_url: str) -> None:
|
||||
"""
|
||||
Test the Pinecone tool integration with the Letta client.
|
||||
"""
|
||||
response = upload_test_agentfile_from_disk(server_url, "knowledge-base.af")
|
||||
response = await upload_test_agentfile_from_disk_async(client, "knowledge-base.af")
|
||||
|
||||
agent_id = response.agent_ids[0]
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ def server_url() -> str:
|
||||
|
||||
start_server(debug=True)
|
||||
|
||||
api_url = os.getenv("LETTA_API_URL")
|
||||
if api_url:
|
||||
return api_url
|
||||
|
||||
url: str = os.getenv("LETTA_SERVER_URL", "http://localhost:8283")
|
||||
|
||||
if not os.getenv("LETTA_SERVER_URL"):
|
||||
@@ -56,12 +60,18 @@ def client(server_url: str) -> Letta:
|
||||
"""
|
||||
Creates and returns a synchronous Letta REST client for testing.
|
||||
"""
|
||||
client_instance = Letta(base_url=server_url)
|
||||
api_url = os.getenv("LETTA_API_URL")
|
||||
api_key = os.getenv("LETTA_API_KEY")
|
||||
|
||||
if api_url and not api_key:
|
||||
raise ValueError("LETTA_API_KEY is required when passing LETTA_API_URL")
|
||||
|
||||
client_instance = Letta(token=api_key, base_url=api_url if api_url else server_url)
|
||||
return client_instance
|
||||
|
||||
|
||||
async def test_deep_research_agent(client, server_url, disable_e2b_api_key):
|
||||
imported_af = upload_test_agentfile_from_disk(server_url, "deep-thought.af")
|
||||
async def test_deep_research_agent(client: Letta, server_url, disable_e2b_api_key):
|
||||
imported_af = upload_test_agentfile_from_disk(client, "deep-thought.af")
|
||||
|
||||
agent_id = imported_af.agent_ids[0]
|
||||
|
||||
@@ -69,6 +79,7 @@ async def test_deep_research_agent(client, server_url, disable_e2b_api_key):
|
||||
response = client.agents.messages.create_stream(
|
||||
agent_id=agent_id,
|
||||
stream_tokens=True,
|
||||
include_pings=True,
|
||||
messages=[
|
||||
MessageCreate(
|
||||
role="user",
|
||||
@@ -90,8 +101,8 @@ async def test_deep_research_agent(client, server_url, disable_e2b_api_key):
|
||||
client.agents.delete(agent_id=agent_id)
|
||||
|
||||
|
||||
async def test_11x_agent(client, server_url, disable_e2b_api_key):
|
||||
imported_af = upload_test_agentfile_from_disk(server_url, "mock_alice.af")
|
||||
async def test_11x_agent(client: Letta, server_url, disable_e2b_api_key):
|
||||
imported_af = upload_test_agentfile_from_disk(client, "mock_alice.af")
|
||||
|
||||
agent_id = imported_af.agent_ids[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user