\n",
+ "\"\"\""
+ ],
+ "metadata": {
+ "id": "055TCwJCreFc"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "prompt_template = PromptTemplate(\n",
+ " system_prompt=system_prompt,\n",
+ " human_prompt=human_prompt)"
+ ],
+ "metadata": {
+ "id": "_fU5h0GVMESp"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "weave.init(weave_project) # Colab specific"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "x9IOgy5apHAI",
+ "outputId": "47e51318-4726-4d18-bd44-ffe5a2d715fc"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Logged in as Weights & Biases user: a-sh0ts.\n",
+ "View Weave data at https://wandb.ai/a-sh0ts/azure-weave-cookbook/weave\n"
+ ]
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": []
+ },
+ "metadata": {},
+ "execution_count": 18
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "from pathlib import Path"
+ ],
+ "metadata": {
+ "id": "wd4wN7sqriAv"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "doc = Path('customer_inquiry.txt').read_text()\n",
+ "model = AzureEmailAssistant(model_id=model_id, prompt_template=prompt_template)\n",
+ "response = model.respond(doc)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "5ixTluHFbu0k",
+ "outputId": "7140d0b4-1531-4b86-df73-3ef6df480a8c"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "🍩 https://wandb.ai/a-sh0ts/azure-weave-cookbook/r/call/589a01db-901e-49a2-8749-3849856e569d\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "print(response[\"response\"])"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "qmEh7O2Bb2kr",
+ "outputId": "b16891b9-b429-4f7b-c890-3e65dcad2b70"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Subject: Update on Your Order #12345 - UltraGlow Skin Serum\n",
+ "\n",
+ "Dear Jane Doe,\n",
+ "\n",
+ "Thank you for reaching out to us regarding your recent order of the UltraGlow Skin Serum. We understand how important it is for you to receive your order promptly and apologize for any inconvenience the delay may have caused.\n",
+ "\n",
+ "Upon reviewing your order #12345, we have noticed that there has been an unexpected delay in the shipping process. We are actively working with our shipping partners to resolve this issue and ensure your order is dispatched as soon as possible.\n",
+ "\n",
+ "We anticipate that your order will be shipped within the next 2-3 business days, and you will receive a shipping confirmation email with a tracking number to monitor the delivery status.\n",
+ "\n",
+ "We appreciate your patience and understanding in this matter. If you have any further questions or concerns, please do not hesitate to contact us.\n",
+ "\n",
+ "Thank you for choosing our UltraGlow Skin Serum. We are confident you will be delighted with your purchase.\n",
+ "\n",
+ "Warm regards,\n",
+ "\n",
+ "[Your Name]\n",
+ "Customer Service Team\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## [Optional] Publish synthetically generated Evaluation data to Weave"
+ ],
+ "metadata": {
+ "id": "jZlihC0AisvA"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "if publish_eval_data:\n",
+ " from weave import Dataset\n",
+ " dataset = Dataset(name=eval_dataset_name, rows=[\n",
+ " {'id': '1', 'email_content': 'Subject: Inquiry about Order Delay\\n\\nHello,\\n\\nI placed an order last week for the new UltraGlow Skin Serum, but I have not received a shipping update yet. My order number is 12345. Could you please update me on the status of my shipment?\\n\\nThank you,\\nJane Doe'},\n",
+ " {'id': '2', 'email_content': 'Subject: Damaged Item Received\\n\\nHello,\\n\\nI received my order yesterday, but one of the items, a glass vase, was broken. My order number is 67890. How can I get a replacement or a refund?\\n\\nBest regards,\\nJohn Smith'},\n",
+ " {'id': '3', 'email_content': 'Subject: Wrong Item Delivered\\n\\nHi,\\n\\nI ordered a pair of blue sneakers, but I received a black pair instead. My order number is 54321. Could you please assist me with this issue?\\n\\nThank you,\\nEmily Johnson'},\n",
+ " {'id': '4', 'email_content': 'Subject: Request for Return Instructions\\n\\nDear Customer Service,\\n\\nI would like to return a dress I purchased last week as it does not fit well. My order number is 11223. Could you please provide the return instructions?\\n\\nSincerely,\\nLaura Davis'},\n",
+ " {'id': '5', 'email_content': 'Subject: Missing Items in Order\\n\\nHello,\\n\\nI just received my order, but two items are missing. My order number is 33445. Could you please help me resolve this?\\n\\nKind regards,\\nMichael Brown'},\n",
+ " {'id': '6', 'email_content': 'Subject: Delay in Order Confirmation\\n\\nDear Support Team,\\n\\nI placed an order two days ago but have not received a confirmation email yet. My order number is 99887. Can you confirm if my order was processed?\\n\\nThank you,\\nSarah Wilson'},\n",
+ " {'id': '7', 'email_content': 'Subject: Inquiry About Product Availability\\n\\nHi,\\n\\nI\\'m interested in purchasing the Professional Chef Knife Set, but it appears to be out of stock. Can you let me know when it will be available again?\\n\\nBest regards,\\nDavid Martinez'},\n",
+ " {'id': '8', 'email_content': 'Subject: Request for Invoice\\n\\nDear Customer Service,\\n\\nCould you please send me an invoice for my recent purchase? My order number is 55667. I need it for my records.\\n\\nThank you,\\nJessica Taylor'},\n",
+ " {'id': '9', 'email_content': 'Subject: Issue with Discount Code\\n\\nHello,\\n\\nI tried using the discount code SAVE20 during checkout, but it did not apply. My order number is 77654. Could you please assist me?\\n\\nSincerely,\\nRobert Anderson'},\n",
+ " {'id': '10', 'email_content': 'Subject: Request for Expedited Shipping\\n\\nHi,\\n\\nI need my order delivered urgently. Is it possible to upgrade to expedited shipping? My order number is 44556.\\n\\nThank you,\\nLinda Thompson'},\n",
+ " {'id': '11', 'email_content': 'Subject: Order Cancellation Request\\n\\nDear Support Team,\\n\\nI would like to cancel my recent order as I made a mistake while ordering. My order number is 33221. Can you please process the cancellation?\\n\\nBest regards,\\nWilliam Clark'}\n",
+ " ])\n",
+ " # Publish the dataset\n",
+ " weave.publish(dataset)"
+ ],
+ "metadata": {
+ "id": "JdVIiLnbi5Pb"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## Run Evaluation whilst logging results to Weave"
+ ],
+ "metadata": {
+ "id": "2i7jVn9fjGTt"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "dataset_uri = f\"weave:///{wandb_entity}/{weave_project}/object/{eval_dataset_name}:latest\"\n",
+ "dataset = weave.ref(dataset_uri).get()"
+ ],
+ "metadata": {
+ "id": "VZO7mbymlECL"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "# Scoring function checking length of summary\n",
+ "@weave.op()\n",
+ "def check_conciseness(model_output: str) -> dict:\n",
+ " result = len(model_output.split()) < 300\n",
+ " return {'conciseness': result}"
+ ],
+ "metadata": {
+ "id": "hVSUMnMXjIet"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "evaluation = weave.Evaluation(\n",
+ " dataset=dataset, scorers=[check_conciseness],\n",
+ ")"
+ ],
+ "metadata": {
+ "id": "TpqRzO0nmAqZ"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "await evaluation.evaluate(model)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 342
+ },
+ "id": "fvzDPo_ymDjj",
+ "outputId": "116f2bfd-1306-4966-eef1-59c81478969d"
+ },
+ "execution_count": null,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m1\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 1 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m2\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 2 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m3\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 3 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m4\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 4 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m5\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 5 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m6\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 6 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m7\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 7 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m8\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 8 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m9\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 9 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m10\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 10 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluated \u001b[1;36m11\u001b[0m of \u001b[1;36m11\u001b[0m examples\n"
+ ],
+ "text/html": [
+ "Evaluated 11 of 11 examples\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "Evaluation summary\n",
+ "\u001b[1m{\u001b[0m\n",
+ " \u001b[32m'check_conciseness'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'conciseness'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'true_count'\u001b[0m: \u001b[1;36m11\u001b[0m, \u001b[32m'true_fraction'\u001b[0m: \u001b[1;36m1.0\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m,\n",
+ " \u001b[32m'model_latency'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'mean'\u001b[0m: \u001b[1;36m59.57047505812211\u001b[0m\u001b[1m}\u001b[0m\n",
+ "\u001b[1m}\u001b[0m\n"
+ ],
+ "text/html": [
+ "Evaluation summary\n",
+ "{\n",
+ " 'check_conciseness': {'conciseness': {'true_count': 11, 'true_fraction': 1.0}},\n",
+ " 'model_latency': {'mean': 59.57047505812211}\n",
+ "}\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "🍩 https://wandb.ai/a-sh0ts/azure-weave-cookbook/r/call/26f22ec3-a719-4fc2-82f6-49210a53fc42\n"
+ ]
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "{'check_conciseness': {'conciseness': {'true_count': 11,\n",
+ " 'true_fraction': 1.0}},\n",
+ " 'model_latency': {'mean': 59.57047505812211}}"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 25
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file