From d41e6cf4734f237f3291daa172614de1465084db Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Wed, 15 Nov 2023 15:31:44 -0800 Subject: [PATCH] include test notebook for message ordering --- tests/ordering.ipynb | 125 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 tests/ordering.ipynb diff --git a/tests/ordering.ipynb b/tests/ordering.ipynb new file mode 100644 index 0000000..5946221 --- /dev/null +++ b/tests/ordering.ipynb @@ -0,0 +1,125 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
𝑓Ransql
Input:
{\n", + " "query": "SHOW TABLES"\n", + "}
Output:
[]
" + ], + "text/plain": [ + "" + ] + }, + "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 +}