Skip to content

Commit

Permalink
Merge pull request #731 from parea-ai/PAI-993-expose-trace-log-info-v…
Browse files Browse the repository at this point in the history
…ia-api

feat: expose trace log via api
  • Loading branch information
joschkabraun committed Apr 10, 2024
2 parents 83a67fe + 16c8d45 commit 07c817a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion parea/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from parea.cache.cache import Cache
from parea.constants import PAREA_OS_ENV_EXPERIMENT_UUID
from parea.experiment.datasets import create_test_cases, create_test_collection
from parea.helpers import gen_trace_id, serialize_metadata_values
from parea.helpers import gen_trace_id, serialize_metadata_values, structure_trace_log_from_api
from parea.parea_logger import parea_logger
from parea.schemas.models import (
Completion,
Expand All @@ -29,6 +29,7 @@
FinishExperimentRequestSchema,
ProjectSchema,
TestCaseCollection,
TraceLog,
UseDeployedPrompt,
UseDeployedPromptResponse,
)
Expand All @@ -48,6 +49,7 @@
GET_COLLECTION_ENDPOINT = "/collection/{test_collection_identifier}"
CREATE_COLLECTION_ENDPOINT = "/collection"
ADD_TEST_CASES_ENDPOINT = "/testcases"
GET_TRACE_LOG_ENDPOINT = "/trace_log/{trace_id}"


@define
Expand Down Expand Up @@ -336,6 +338,14 @@ def _update_data_and_trace(self, data: Completion) -> Completion:

return data

def get_trace_log(self, trace_id: str) -> TraceLog:
response = self._client.request("GET", GET_TRACE_LOG_ENDPOINT.format(trace_id=trace_id))
return structure_trace_log_from_api(response.json())

async def aget_trace_log(self, trace_id: str) -> TraceLog:
response = await self._client.request_async("GET", GET_TRACE_LOG_ENDPOINT.format(trace_id=trace_id))
return structure_trace_log_from_api(response.json())


_initialized_parea_wrapper = False

Expand Down
15 changes: 15 additions & 0 deletions parea/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytz
from attr import asdict, fields_dict
from cattrs import GenConverter

from parea.constants import ADJECTIVES, NOUNS
from parea.schemas.models import Completion, TraceLog, UpdateLog
Expand Down Expand Up @@ -78,3 +79,17 @@ def serialize_values(metadata: Dict[str, Any]) -> Dict[str, str]:

def timezone_aware_now() -> datetime:
return datetime.now(pytz.utc)


def structure_trace_log_from_api(d: dict) -> TraceLog:
def structure_union_type(obj: Any, cl: type) -> Any:
if isinstance(obj, str):
return obj
elif isinstance(obj, dict):
return obj
else:
return None

converter = GenConverter()
converter.register_structure_hook(Union[str, Dict[str, str], None], structure_union_type)
return converter.structure(d, TraceLog)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "parea-ai"
packages = [{ include = "parea" }]
version = "0.2.128"
version = "0.2.129"
description = "Parea python sdk"
readme = "README.md"
authors = ["joel-parea-ai <[email protected]>"]
Expand Down

0 comments on commit 07c817a

Please sign in to comment.