This is an interactive notebook. You can run it locally or use the links below:
Import Traces from 3rd Party Systems
In ocassion, it is not possible to instrument your Python or Javascript code with Weave’s simple integration to obtain real-time traces of your GenAI application. It is often the case that these traces are later on available to you incsv
or json
format.
In this cookbook we explore the lower level Weave Python API to extract data from a CSV file and import it into Weave to drive insights and rigorous evaluations.
The sample dataset assumed in this cookbook has the following structure:
conversation_id
as the parent identifier, and the turn_index
as the child identifier to provide us complete conversation logging.
Ensure to modify the variables as needed.
Set up the environment
We install and import all needed packages. We setWANDB_API_KEY
in our env so that we may easily login with wandb.login()
(this should be given to the colab as a secret).
We set the name of the file we upload to colab in name_of_file
and set the project in W&B we want to log this into in name_of_wandb_project
.
NOTE: name_of_wandb_project
may also be in the format of {team_name}/{project_name}
to specify a team to log the traces into.
We then fetch a weave client by calling weave.init()
Data Loading
We load the data into a Pandas dataframe, and ensure we sort it by theconversation_id
and turn_index
to ensure the parents and childs are correctly ordered.
This will result in a two column pandas DF with our conversation turns as an array under conversation_data
.
Log the Traces to Weave
We now iterate through our pandas DF:- We create a parent call for every
conversation_id
- We iterate through the turn array to create child calls sorted by their
turn_index
- A Weave call is equivalent to a Weave trace, this call may have a parent or children associated with it
- A Weave call may have other things associated with it: Feedback, Metadata, etc. We only associate inputs and outputs to it here, but you may want to add these things in your import if the data provides it.
- A weave call is
created
andfinished
as these are meant to be tracked real time. Because this is an after-the-fact import, we create and finish once our objects are defined and tied to one another. - The
op
value of a call is how Weave categorizes calls of the same make up. In this example, all parent calls are ofConversation
type, and all children calls are ofTurn
type. You may modify this as you see fit. - A call may have
inputs
andoutput
.inputs
are defined at creation anoutput
is defined when the call is finished.
Result: Traces are Logged to Weave
Traces:

Bonus: Export your traces to run rigorous evaluations!
Once our traces are in Weave and we have an understanding on how the conversations are looking, we may want to later on export them to another process to run Weave Evaluations
Result
