Skip to content

Conversation

@jjmachan
Copy link
Member

@jjmachan jjmachan commented Nov 5, 2024

No description provided.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 5, 2024
Comment on lines +496 to +528
def upload(self, base_url: str = RAGAS_API_URL, verbose: bool = True) -> str:
from datetime import datetime, timezone

import requests

timestamp = datetime.now(timezone.utc).isoformat()
root_trace = [
trace for trace in self.ragas_traces.values() if trace.parent_run_id is None
][0]
packet = json.dumps(
{
"run_id": str(root_trace.run_id),
"created_at": timestamp,
"evaluation_run": [t.model_dump() for t in self.ragas_traces.values()],
},
cls=ChainRunEncoder,
)

def __getitem__(self, key: str) -> t.List[float]:
return self._scores_dict[key]
response = requests.post(
f"{base_url}/alignment/evaluation",
data=packet,
headers={"Content-Type": "application/json"},
)

if response.status_code != 200:
raise Exception(f"Failed to upload results: {response.text}")

evaluation_endpoint = (
f"https://app.ragas.io/alignment/evaluation/{root_trace.run_id}"
)
if verbose:
print(f"Evaluation results uploaded! View at {evaluation_endpoint}")
return evaluation_endpoint
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code for uploading

@jjmachan jjmachan merged commit 3a6fab9 into explodinggradients:main Nov 6, 2024
15 checks passed
@jjmachan jjmachan deleted the feat/api branch November 6, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant