Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaPurtell committed Nov 15, 2024
2 parents 725c7db + 9f2e9b0 commit fc9a297
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "synth-sdk"
version = "0.2.61"
version = "0.2.70"
description = ""
authors = [{name = "Synth AI", email = "[email protected]"}]
license = {text = "MIT"}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="synth-sdk",
version="0.2.61",
version="0.2.70",
packages=find_packages(),
install_requires=[
"opentelemetry-api",
Expand Down
19 changes: 10 additions & 9 deletions synth_sdk/tracing/abstractions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from typing import Any, List, Dict, Optional, Union, Literal
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
Expand Down Expand Up @@ -30,10 +31,10 @@ class ArbitraryOutputs:
@dataclass
class ComputeStep:
event_order: int
compute_ended: Any # timestamp
compute_began: Any # timestamp
compute_input: List[Any]
compute_output: List[Any]
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}

def to_dict(self):
# Serialize compute_input
Expand All @@ -58,8 +59,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,
}
Expand Down Expand Up @@ -91,8 +92,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
Expand Down
28 changes: 13 additions & 15 deletions synth_sdk/tracing/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ 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}
)
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}/upload/"
api_url = f"{base_url}/v1/uploads/"

payload = createPayload(dataset, traces) # Create the payload

Expand Down Expand Up @@ -183,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."""
Expand All @@ -221,7 +217,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:
Expand Down Expand Up @@ -265,7 +263,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))
Expand Down
2 changes: 1 addition & 1 deletion testing/ai_agent_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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:
Expand Down
2 changes: 1 addition & 1 deletion testing/ai_agent_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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:
Expand Down
4 changes: 2 additions & 2 deletions testing/upload_payload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fc9a297

Please sign in to comment.