From c3ec740823a6e7b88bc182844b17d4503eeccba2 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Tue, 12 Nov 2024 14:59:34 -0800 Subject: [PATCH 1/9] add support for manual uploads --- synth_sdk/tracing/upload.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synth_sdk/tracing/upload.py b/synth_sdk/tracing/upload.py index b8caea1..66f9189 100644 --- a/synth_sdk/tracing/upload.py +++ b/synth_sdk/tracing/upload.py @@ -221,7 +221,9 @@ async def upload_helper(dataset: Dataset, traces: List[SystemTrace]=[], verbose: _local.active_events.clear() # Also close any unclosed events in existing traces - traces = event_store.get_system_traces() if len(traces) == 0 else traces + logged_traces = event_store.get_system_traces() + traces = logged_traces+ traces + #traces = event_store.get_system_traces() if len(traces) == 0 else traces current_time = time.time() for trace in traces: for partition in trace.partition: From 0bc5383c3c5dbb35c27bfc8740814dc3f6e4af67 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Tue, 12 Nov 2024 20:36:46 -0800 Subject: [PATCH 2/9] new api --- pyproject.toml | 2 +- setup.py | 2 +- synth_sdk/tracing/upload.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d7e3631..e6c7a75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.61" +version = "0.2.64" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index fb277c7..68ce501 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.61", + version="0.2.64", packages=find_packages(), install_requires=[ "opentelemetry-api", diff --git a/synth_sdk/tracing/upload.py b/synth_sdk/tracing/upload.py index 66f9189..a42b1b2 100644 --- a/synth_sdk/tracing/upload.py +++ b/synth_sdk/tracing/upload.py @@ -41,7 +41,7 @@ def send_system_traces( ): """Send all system traces and dataset metadata to the server.""" # Get the token using the API key - token_url = f"{base_url}/token" + token_url = f"{base_url}/v1/auth/token" token_response = requests.get( token_url, headers={"customer_specific_api_key": api_key} ) @@ -50,7 +50,7 @@ def send_system_traces( # print("Traces: ", traces) # Send the traces with the token - api_url = f"{base_url}/upload/" + api_url = f"{base_url}/v1/uploads/" payload = createPayload(dataset, traces) # Create the payload @@ -267,7 +267,7 @@ async def upload_helper(dataset: Dataset, traces: List[SystemTrace]=[], verbose: if show_payload: print("Payload sent to server: ") pprint(payload) - return response, payload + return response, payload, dataset, traces except ValueError as e: if verbose: print("Validation error:", str(e)) From 7d651a2cf9def1b60354e85c6c331765991e3b48 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Wed, 13 Nov 2024 00:49:23 -0800 Subject: [PATCH 3/9] save sdk --- synth_sdk/tracing/upload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synth_sdk/tracing/upload.py b/synth_sdk/tracing/upload.py index a42b1b2..e2a7f11 100644 --- a/synth_sdk/tracing/upload.py +++ b/synth_sdk/tracing/upload.py @@ -48,7 +48,6 @@ def send_system_traces( token_response.raise_for_status() access_token = token_response.json()["access_token"] - # print("Traces: ", traces) # Send the traces with the token api_url = f"{base_url}/v1/uploads/" From d2495da541d4b0c5fbb5d6f3f5bf2d3aadaf5c43 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Wed, 13 Nov 2024 21:40:53 -0800 Subject: [PATCH 4/9] save progress --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e6c7a75..fdf3683 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.64" +version = "0.2.65" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index 68ce501..755339a 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.64", + version="0.2.65", packages=find_packages(), install_requires=[ "opentelemetry-api", From c40c1f74882221a382f6b40f84f2b17eed974d37 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Wed, 13 Nov 2024 21:56:19 -0800 Subject: [PATCH 5/9] datetime --- pyproject.toml | 2 +- setup.py | 2 +- synth_sdk/tracing/abstractions.py | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fdf3683..c274597 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.65" +version = "0.2.66" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index 755339a..b024132 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.65", + version="0.2.66", packages=find_packages(), install_requires=[ "opentelemetry-api", diff --git a/synth_sdk/tracing/abstractions.py b/synth_sdk/tracing/abstractions.py index 369f502..e307360 100644 --- a/synth_sdk/tracing/abstractions.py +++ b/synth_sdk/tracing/abstractions.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from typing import Any, List, Dict, Optional, Union +from datetime import datetime from pydantic import BaseModel import logging from synth_sdk.tracing.config import VALID_TYPES @@ -10,8 +11,8 @@ @dataclass class ComputeStep: event_order: int - compute_ended: Any # time step - compute_began: Any # time step + compute_ended: datetime # time step + compute_began: datetime # time step compute_input: Dict[str, Any] # {variable_name: value} compute_output: Dict[str, Any] # {variable_name: value} @@ -37,8 +38,8 @@ def to_dict(self): return { "event_order": self.event_order, - "compute_ended": self.compute_ended, - "compute_began": self.compute_began, + "compute_ended": self.compute_ended.isoformat() if isinstance(self.compute_ended, datetime) else self.compute_ended, + "compute_began": self.compute_began.isoformat() if isinstance(self.compute_began, datetime) else self.compute_began, "compute_input": serializable_input, "compute_output": serializable_output, } From c5c3dbf4a08627efadfc95bf70063dae3108e2fe Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Wed, 13 Nov 2024 21:59:05 -0800 Subject: [PATCH 6/9] save progress --- pyproject.toml | 2 +- setup.py | 2 +- synth_sdk/tracing/abstractions.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c274597..464cc51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.66" +version = "0.2.67" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index b024132..776bd57 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.66", + version="0.2.67", packages=find_packages(), install_requires=[ "opentelemetry-api", diff --git a/synth_sdk/tracing/abstractions.py b/synth_sdk/tracing/abstractions.py index e307360..e9f9664 100644 --- a/synth_sdk/tracing/abstractions.py +++ b/synth_sdk/tracing/abstractions.py @@ -65,8 +65,8 @@ class Event: def to_dict(self): return { "event_type": self.event_type, - "opened": self.opened, - "closed": self.closed, + "opened": self.opened.isoformat() if isinstance(self.opened, datetime) else self.opened, + "closed": self.closed.isoformat() if isinstance(self.closed, datetime) else self.closed, "partition_index": self.partition_index, "agent_compute_steps": [ step.to_dict() for step in self.agent_compute_steps From 03167c8d6c713e4539e08062ba6d27cda0a57c58 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Thu, 14 Nov 2024 21:41:11 -0800 Subject: [PATCH 7/9] increment --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 464cc51..273ead1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.67" +version = "0.2.68" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index 776bd57..b7a9e43 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.67", + version="0.2.68", packages=find_packages(), install_requires=[ "opentelemetry-api", From f1700209296115ade6d681e8051c24cb8abe5d81 Mon Sep 17 00:00:00 2001 From: doku88 Date: Fri, 15 Nov 2024 02:15:58 -0800 Subject: [PATCH 8/9] bug fix for upload() just run as upload() no asyncio --- pyproject.toml | 2 +- setup.py | 2 +- synth_sdk/tracing/upload.py | 17 +++++++---------- testing/ai_agent_async.py | 2 +- testing/ai_agent_sync.py | 2 +- testing/upload_payload_test.py | 4 ++-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 273ead1..e58a094 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.68" +version = "0.2.69" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index b7a9e43..4e52437 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.68", + version="0.2.69", packages=find_packages(), install_requires=[ "opentelemetry-api", diff --git a/synth_sdk/tracing/upload.py b/synth_sdk/tracing/upload.py index e2a7f11..d020453 100644 --- a/synth_sdk/tracing/upload.py +++ b/synth_sdk/tracing/upload.py @@ -182,20 +182,17 @@ def upload(dataset: Dataset, traces: List[SystemTrace]=[], verbose: bool = False async def upload_wrapper(dataset, traces, verbose, show_payload): result = await upload_helper(dataset, traces, verbose, show_payload) return result - + + # If we're in an async context (event loop is running) if is_event_loop_running(): logging.info("Event loop is already running") - task = asyncio.create_task(upload_wrapper(dataset, traces, verbose, show_payload)) - # Wait for the task if called from an async function - if asyncio.current_task(): - return task # Returning the task to be awaited if in async context - else: - # Run task synchronously by waiting for it to finish if in sync context - return asyncio.get_event_loop().run_until_complete(task) - + # Return the coroutine directly for async contexts + return upload_helper(dataset, traces, verbose, show_payload) else: + # In sync context, run the coroutine and return the result logging.info("Event loop is not running") - return asyncio.run(upload_wrapper(dataset, traces, verbose, show_payload)) + return asyncio.run(upload_helper(dataset, traces, verbose, show_payload)) + async def upload_helper(dataset: Dataset, traces: List[SystemTrace]=[], verbose: bool = False, show_payload: bool = False): """Upload all system traces and dataset to the server.""" diff --git a/testing/ai_agent_async.py b/testing/ai_agent_async.py index 3dfa624..e213eb7 100644 --- a/testing/ai_agent_async.py +++ b/testing/ai_agent_async.py @@ -128,7 +128,7 @@ async def run_test(): # Upload traces try: logger.info("Attempting to upload traces") - response, _ = await upload(dataset=dataset, verbose=True) + response, payload, dataset, traces = await upload(dataset=dataset, verbose=True) logger.info("Upload successful!") print("Upload successful!") except Exception as e: diff --git a/testing/ai_agent_sync.py b/testing/ai_agent_sync.py index 0f2f082..19f0000 100644 --- a/testing/ai_agent_sync.py +++ b/testing/ai_agent_sync.py @@ -128,7 +128,7 @@ async def run_test(): # Upload traces try: logger.info("Attempting to upload traces") - response, _ = await upload(dataset=dataset, verbose=True) + response, payload, dataset, traces= await upload(dataset=dataset, verbose=True) logger.info("Upload successful!") print("Upload successful!") except Exception as e: diff --git a/testing/upload_payload_test.py b/testing/upload_payload_test.py index 3655486..1165f9a 100644 --- a/testing/upload_payload_test.py +++ b/testing/upload_payload_test.py @@ -153,7 +153,7 @@ async def test_upload_async(mock_send_system_traces): # Upload traces logger.info("Attempting to upload traces, async version") # TODO: uploads traces directly from list of traces (override the event_store) - response, payload = await upload(dataset=dataset, verbose=True, show_payload=True) + response, payload, dataset, traces = await upload(dataset=dataset, verbose=True, show_payload=True) logger.info("Upload successful!") # Pytest assertion @@ -174,7 +174,7 @@ def test_upload_sync(mock_send_system_traces): # Upload traces logger.info("Attempting to upload traces, non-async version") # TODO: uploads traces directly from list of traces (override the event_store) - response, payload = upload(dataset=dataset, verbose=True, show_payload=True) + response, payload, dataset, traces = upload(dataset=dataset, verbose=True, show_payload=True) logger.info("Upload successful!") # Pytest assertion From 9f2e9b0afa40b5f85655bc30b7ca9736c474a308 Mon Sep 17 00:00:00 2001 From: Josh Purtell Date: Fri, 15 Nov 2024 08:25:13 -0800 Subject: [PATCH 9/9] increment --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e58a094..296244c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "synth-sdk" -version = "0.2.69" +version = "0.2.70" description = "" authors = [{name = "Synth AI", email = "josh@usesynth.ai"}] license = {text = "MIT"} diff --git a/setup.py b/setup.py index 4e52437..0900160 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="synth-sdk", - version="0.2.69", + version="0.2.70", packages=find_packages(), install_requires=[ "opentelemetry-api",