Skip to content

Commit

Permalink
docs: Add example code snippet to how-to
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinKallenbornAA committed Aug 6, 2024
1 parent c3ae141 commit a71719f
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/documentation/how_tos/how_to_run_the_trace_viewer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,45 @@
"1. Initialize a `StudioClient` with a project.\n",
" - Use an existing project or create a new one with the `StudioClient.create_project` function.\n",
"2. Submit your traces with the client\n",
" - submit a single trace via `Tracer.export_for_viewing` and `StudioClient.submit_trace`\n",
" - [Recommended] submit multiple traces via `StudioClient.submit_from_tracer`. \n",
"3. Click the link \n",
" 1. Submit a single trace via `Tracer.export_for_viewing` and `StudioClient.submit_trace`\n",
" 2. [Recommended] submit multiple traces via `StudioClient.submit_from_tracer`. \n",
"\n",
"### Example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"metadata": {},
"outputs": [],
"source": []
"source": [
"from intelligence_layer.connectors.studio.studio import StudioClient\n",
"from intelligence_layer.core.task import Task\n",
"from intelligence_layer.core.tracer.in_memory_tracer import InMemoryTracer\n",
"from intelligence_layer.core.tracer.tracer import TaskSpan\n",
"\n",
"# Step 0\n",
"class DummyTask(Task[str, str]):\n",
" def do_run(self, input: str, task_span: TaskSpan) -> str:\n",
" return f\"{input} -> output\"\n",
"\n",
"tracer = InMemoryTracer()\n",
"DummyTask().run('My Dummy Run', tracer=tracer)\n",
"\n",
"# Step 1\n",
"studio_client = StudioClient(project='my_project')\n",
"my_project = studio_client.create_project(project='my_project')\n",
"\n",
"# Step 2.1\n",
"trace_to_submit = tracer.export_for_viewing()\n",
"studio_client.submit_trace(trace_to_submit) # only works for single traces\n",
"\n",
"# Step 2.2\n",
"DummyTask().run('My Dummy Run2', tracer=tracer)\n",
"multiple_traces_to_submit = studio_client.submit_from_tracer(tracer)\n",
"\n",
"\n"
]
}
],
"metadata": {
Expand Down

0 comments on commit a71719f

Please sign in to comment.