You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/code/memory/9_exporting_data.py
+98-13
Original file line number
Diff line number
Diff line change
@@ -6,41 +6,126 @@
6
6
# format_name: percent
7
7
# format_version: '1.3'
8
8
# jupytext_version: 1.16.4
9
+
# kernelspec:
10
+
# display_name: pyrit-kernel
11
+
# language: python
12
+
# name: pyrit-kernel
9
13
# ---
10
14
11
15
# %% [markdown]
12
16
# # 9. Exporting Data Example
13
17
#
14
-
# This notebook shows all the different ways to export data from memory. This first example exports all conversations from Azure SQL memory with their respective score values in a JSON format. Without using the database query editor, these export functions allow for a quick approach to exporting data from memory.
18
+
# This notebook shows different ways to export data from memory. This first example exports all conversations from local DuckDB memory with their respective score values in a JSON format. The data can currently be exported both as JSON file or a CSV file that will be saved in your results folder within PyRIT. The CSV export is commented out below. In this example, all conversations are exported, but by using other export functions from `memory_interface`, we can export by specific labels and other methods.
# print(f"Exported conversation with scores to CSV: {csv_file_path}")
36
71
37
72
# %% [markdown]
38
-
# ## Importing Data as NumPy DataFrame
39
-
#
40
-
# You can use the exported JSON or CSV files to import the data as a NumPy DataFrame. This can be useful for various data manipulation and analysis tasks.
73
+
# You can also use the exported JSON or CSV files to import the data as a NumPy DataFrame. This can be useful for various data manipulation and analysis tasks.
41
74
42
75
# %%
43
76
importpandasaspd# type: ignore
44
77
45
78
df=pd.read_json(json_file_path)
46
-
df.head()
79
+
df.head(1)
80
+
81
+
# %% [markdown]
82
+
# Next, we can export data from our Azure SQL database. In this example, we export the data by `conversation_id` and to a CSV file.
83
+
84
+
# %%
85
+
frompyrit.memoryimportAzureSQLMemory
86
+
87
+
conversation_id=str(uuid4())
88
+
89
+
message_list= [
90
+
PromptRequestPiece(
91
+
role="user", original_value="Hi, chat bot! This is my initial prompt.", conversation_id=conversation_id
92
+
),
93
+
PromptRequestPiece(
94
+
role="assistant", original_value="Nice to meet you! This is my response.", conversation_id=conversation_id
95
+
),
96
+
PromptRequestPiece(
97
+
role="user",
98
+
original_value="Wonderful! This is my second prompt to the chat bot!",
0 commit comments