-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from rgbkrk/test-ordering-in-notebook
include test notebook for message ordering
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div><style>.chatlab-chat-details summary > * { display: inline; color: #27374D; }</style><details style=\"background: #DDE6ED; border-radius: 5px; padding: .5rem 1rem\" className=\"chatlab-chat-details\"><summary style=\"color: #27374D; cursor: pointer\"><span style=\"color: #9DB2BF; padding-left: 5px; padding-right: 5px\">𝑓</span><span style=\"color: #27374D; padding-left: 5px; padding-right: 5px\">Ran</span><span style=\"font-family: monospace; unicode-bidi: embed; white-space: pre\">sql</span><span style=\"font-family: monospace; unicode-bidi: embed; white-space: pre\"></span></summary><div style=\"margin-left: 10px; margin-top: 10px\"><div><div style=\"color: #27374D; font-weight: 500; margin-bottom: 5px\">Input:</div><div style=\"background: #F7F9FA; color: #27374D; font-family: monospace; margin-bottom: 10px; overflow-x: auto; padding: 10px; unicode-bidi: embed; white-space: pre\">{\n", | ||
" "query": "SHOW TABLES"\n", | ||
"}</div></div><div><div style=\"color: #27374D; font-weight: 500; margin-bottom: 5px\">Output:</div><div style=\"background: #F7F9FA; color: #27374D; font-family: monospace; margin-bottom: 10px; overflow-x: auto; padding: 10px; unicode-bidi: embed; white-space: pre\">[]</div></div></div></details></div>" | ||
], | ||
"text/plain": [ | ||
"<chatlab.display.ChatFunctionCall at 0x10cb35490>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/markdown": [ | ||
"I'm sorry, but there are no tables available to show at the moment." | ||
], | ||
"text/plain": [ | ||
"I'm sorry, but there are no tables available to show at the moment." | ||
] | ||
}, | ||
"metadata": { | ||
"text/markdown": { | ||
"chatlab": { | ||
"default": true | ||
} | ||
} | ||
}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"from chatlab import Chat, system\n", | ||
"\n", | ||
"chat = Chat(system(\"You are a data engineer\"))\n", | ||
"\n", | ||
"\n", | ||
"def sql(query: str):\n", | ||
" \"\"\"Runs SQL query\"\"\"\n", | ||
" # Totally fake, returns an empty table\n", | ||
"\n", | ||
" return []\n", | ||
"\n", | ||
"\n", | ||
"chat.register(sql)\n", | ||
"\n", | ||
"await chat(\"Show them tables\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert chat.messages[0][\"content\"] == \"You are a data engineer\"\n", | ||
"assert chat.messages[1][\"content\"] == \"Show them tables\"\n", | ||
"\n", | ||
"function_message = chat.messages[2]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert function_message[\"content\"] == None\n", | ||
"\n", | ||
"assert function_message[\"function_call\"][\"name\"] == \"sql\"\n", | ||
"\n", | ||
"assert \"SHOW TABLES\" in function_message[\"function_call\"][\"arguments\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert chat.messages[3][\"content\"] == \"[]\"\n", | ||
"assert chat.messages[3][\"role\"] == \"function\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert chat.messages[4][\"role\"] == \"assistant\"" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "chatlab-3kMKfU-i-py3.11", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |