updating misc folder

This commit is contained in:
Elie Schoppik
2024-10-23 15:27:19 -07:00
parent cfeb7f3367
commit 9e8fea21c5
4 changed files with 265 additions and 233 deletions

View File

@@ -48,7 +48,7 @@
"import time\n",
"\n",
"client = anthropic.Anthropic()\n",
"MODEL_NAME = \"claude-3-5-sonnet-20240620\""
"MODEL_NAME = \"claude-3-5-sonnet-20241022\""
]
},
{
@@ -438,7 +438,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv-anthropic-batches",
"display_name": "py311",
"language": "python",
"name": "python3"
},

View File

@@ -54,7 +54,7 @@
"# Enter your API key here\n",
"api_key = \"\"\n",
"CLIENT = anthropic.Anthropic(api_key=api_key)\n",
"MODEL_NAME = \"claude-3-5-sonnet-20240620\""
"MODEL_NAME = \"claude-3-5-sonnet-20241022\""
]
},
{
@@ -355,7 +355,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"id": "0606eaa2",
"metadata": {
"scrolled": true
@@ -382,7 +382,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"id": "6da69c33",
"metadata": {},
"outputs": [],
@@ -412,52 +412,52 @@
"Generated test case:\n",
"~~~~~~~~~~~\n",
"DOCUMENTS:\n",
"Q: What is Acme's return policy?\n",
"A: Acme offers a 30-day return policy for all unused items in their original packaging. Customers are responsible for return shipping costs unless the item is defective or was sent in error.\n",
"Return Policy\n",
"- Items may be returned within 30 days of purchase with original receipt\n",
"- Items must be unused and in original packaging\n",
"- Shipping costs are non-refundable\n",
"- Gift cards are non-returnable\n",
"\n",
"Q: How long does shipping typically take?\n",
"A: Standard shipping within the continental US takes 3-5 business days. Express shipping is available for an additional fee and typically arrives within 1-2 business days.\n",
"Shipping Information\n",
"- Standard shipping (5-7 business days): Free on orders over $50\n",
"- Express shipping (2-3 business days): $12.99\n",
"- Overnight shipping (next business day): $24.99\n",
"- We ship to continental US only\n",
"- Alaska and Hawaii orders incur additional $15 fee\n",
"\n",
"Q: Does Acme offer international shipping?\n",
"A: Yes, Acme ships to select international destinations. International shipping times vary by location and typically take 7-14 business days. Additional customs fees may apply.\n",
"\n",
"Q: What warranty does Acme provide on its products?\n",
"A: Acme provides a 1-year limited warranty on all electronic products and a 6-month warranty on accessories. This warranty covers defects in materials and workmanship under normal use.\n",
"\n",
"Q: How can I track my order?\n",
"A: Once your order has been shipped, you will receive a tracking number via email. You can use this number to track your package on our website or the carrier's website.\n",
"\n",
"Q: What forms of payment does Acme accept?\n",
"A: Acme accepts all major credit cards (Visa, MasterCard, American Express, Discover), PayPal, and Acme gift cards for online purchases.\n",
"\n",
"Q: How do I cancel an order?\n",
"A: If your order hasn't shipped yet, you can cancel it by logging into your account and selecting \"Cancel Order\" next to the relevant order. If the order has already shipped, you'll need to follow our return process once you receive the item.\n",
"Payment Methods\n",
"- We accept Visa, Mastercard, American Express, and PayPal\n",
"- Payment is processed at time of order\n",
"- Gift cards cannot be used for partial payment\n",
"\n",
"QUESTION:\n",
"Hi, I ordered a product last week but changed my mind. Can I still return it? And who pays for the shipping?\n",
"Hi, I ordered a sweater last week but it doesn't fit right. Can I return it? And will I get refunded for the shipping I paid? Thanks!\n",
"\n",
"~~~~~~~~~~~\n",
"Planning:\n",
"~~~~~~~~~~~\n",
"<planning>\n",
"1. Summary of prompt template:\n",
"The goal of the user who created this template is to build a customer support chatbot for Acme Corporation. The bot is designed to answer customer questions based on the company's policies, which are provided in an FAQ format.\n",
"1. Prompt Template Summary:\n",
"This template creates a customer service chatbot for Acme Corporation that answers customer questions based on official company policies/FAQ documents. The goal is to ensure consistent, policy-compliant responses to customer inquiries.\n",
"\n",
"2. Considerations for variables:\n",
"2. Variable Analysis:\n",
"\n",
"DOCUMENTS:\n",
"- This variable will likely be populated from Acme Corporation's internal knowledge base or policy documents.\n",
"- It should contain multiple FAQ entries, each with a question and answer format.\n",
"- The content should cover various aspects of company policies, such as returns, shipping, warranties, etc.\n",
"- The language should be formal and clear, as it represents official company policies.\n",
"- Length could vary but might typically include 5-10 FAQ entries.\n",
"- Would likely be maintained by Acme's policy/legal team\n",
"- Stored in a knowledge base or content management system\n",
"- Formatted as structured FAQ entries or policy statements\n",
"- Professional, formal tone\n",
"- Multiple paragraphs covering different topics\n",
"- Clear headers and categories\n",
"- Length: Several paragraphs (300-500 words)\n",
"\n",
"QUESTION:\n",
"- This will be supplied by the end user (customer) interacting with the chatbot.\n",
"- It should be a typical customer support question related to Acme's products or services.\n",
"- The language might be informal or colloquial, as it's coming from a customer.\n",
"- It will likely be a single sentence or short paragraph.\n",
"- The question should ideally relate to one of the policy areas covered in the DOCUMENTS.\n",
"- Written by end users/customers\n",
"- Informal, conversational tone\n",
"- Usually 1-2 sentences\n",
"- Often includes context about their specific situation\n",
"- May contain typos or casual language\n",
"- Length: 20-50 words\n",
"</planning>\n"
]
}
@@ -546,52 +546,53 @@
"Generated test case:\n",
"~~~~~~~~~~~\n",
"DOCUMENTS:\n",
"1. What is Acme's return policy?\n",
"Answer: Acme offers a 30-day money-back guarantee on all products. Items must be returned in their original packaging and in resalable condition. Customers are responsible for return shipping costs unless the item is defective.\n",
"Return Policy\n",
"- Items may be returned within 30 days of purchase with original receipt\n",
"- Items must be unused and in original packaging\n",
"- Shipping costs are non-refundable\n",
"- Store credit will be issued for items returned without receipt\n",
"\n",
"2. How long does shipping take?\n",
"Answer: Standard shipping within the continental US takes 3-5 business days. Express shipping is available for an additional fee and typically arrives within 1-2 business days. International shipping times vary by destination.\n",
"Shipping Information\n",
"- Standard shipping (5-7 business days): $5.99\n",
"- Express shipping (2-3 business days): $12.99\n",
"- Free standard shipping on orders over $50\n",
"- We currently ship only within the continental United States\n",
"- Alaska and Hawaii orders subject to additional fees\n",
"\n",
"3. Does Acme offer a warranty on its products?\n",
"Answer: Yes, all Acme products come with a 1-year limited warranty against defects in materials and workmanship. This warranty does not cover damage from misuse or normal wear and tear.\n",
"\n",
"4. Can I cancel my order?\n",
"Answer: Orders can be canceled within 24 hours of placement. After this time, the order will have entered our fulfillment process and cannot be canceled. You may return the item once received for a refund as per our return policy.\n",
"\n",
"5. How do I contact customer support?\n",
"Answer: Customer support is available via email at support@acme.com, by phone at 1-800-ACME-HELP (Monday-Friday, 9am-5pm EST), or through our website's live chat feature during business hours.\n",
"\n",
"6. What forms of payment does Acme accept?\n",
"Answer: We accept all major credit cards (Visa, MasterCard, American Express, Discover), PayPal, and Acme gift cards. We do not accept personal checks or cash payments.\n",
"\n",
"7. Are Acme products environmentally friendly?\n",
"Answer: Acme is committed to sustainability. Many of our products are made from recycled materials, and we use eco-friendly packaging wherever possible. We also have a product recycling program for select items.\n",
"Payment Methods\n",
"- We accept Visa, Mastercard, American Express, and PayPal\n",
"- Gift cards cannot be used for online purchases\n",
"- Payment is processed at time of order\n",
"- All prices are in USD\n",
"\n",
"QUESTION:\n",
"Hi there, I received my Acme Super Gadget yesterday, but it's not working properly. Can I return it and get my money back?\n",
"Hi, I ordered a sweater last week but it doesn't fit right. Can I return it? I still have the tags on it but I threw away the receipt. Thanks!\n",
"\n",
"~~~~~~~~~~~\n",
"Planning:\n",
"~~~~~~~~~~~\n",
"<planning>\n",
"1. Summary of prompt template:\n",
"The goal of the user who created this template is to build a customer support chatbot for Acme Corporation. The bot is designed to answer customer questions based on the company's policies, which are provided in an FAQ format.\n",
"1. Prompt Template Summary:\n",
"This template creates a customer service chatbot for Acme Corporation that answers customer questions based on official company policies/FAQ documents. The goal is to ensure consistent, policy-compliant responses to customer inquiries.\n",
"\n",
"2. Considerations for variables:\n",
"2. Variable Analysis:\n",
"\n",
"DOCUMENTS:\n",
"- This variable will likely be populated from Acme Corporation's internal knowledge base or policy documents.\n",
"- It should contain multiple FAQ entries, each with a question and answer format and associated number..\n",
"- The content should cover various aspects of company policies, such as returns, shipping, warranties, etc.\n",
"- The language should be formal and clear, as it represents official company policies.\n",
"- Length could vary but might typically include 5-10 FAQ entries.\n",
"- Would likely be maintained by Acme's policy/legal team\n",
"- Stored in a knowledge base or content management system\n",
"- Formatted as structured FAQ entries or policy statements\n",
"- Professional, formal tone\n",
"- Multiple paragraphs covering different topics\n",
"- Clear headers and categories\n",
"- Length: Several paragraphs (300-500 words)\n",
"\n",
"QUESTION:\n",
"- This will be supplied by the end user (customer) interacting with the chatbot.\n",
"- It should be a typical customer support question related to Acme's products or services.\n",
"- The language might be informal or colloquial, as it's coming from a customer.\n",
"- It will likely be a single sentence or short paragraph.\n",
"- The question should ideally relate to one of the policy areas covered in the DOCUMENTS.\n",
"- Written by end users/customers\n",
"- Informal, conversational tone\n",
"- Usually 1-2 sentences\n",
"- Often includes context about their specific situation\n",
"- May contain typos or casual language\n",
"- Length: 20-50 words\n",
"</planning>\n"
]
}
@@ -652,49 +653,54 @@
"Generated test case:\n",
"~~~~~~~~~~~\n",
"DOCUMENTS:\n",
"1. What is Acme's price matching policy?\n",
"Answer: Acme offers price matching on identical items sold by authorized retailers. We will match the price within 14 days of purchase. Customers must provide proof of the lower price, and the item must be in stock at the competitor. This policy does not apply to clearance, open-box, or refurbished items.\n",
"Product Warranty\n",
"- All electronics come with a 1-year limited manufacturer warranty\n",
"- Warranty covers defects in materials and workmanship\n",
"- Warranty does not cover accidental damage or misuse\n",
"- Extended warranty available for purchase within 30 days\n",
"\n",
"2. Does Acme offer international shipping?\n",
"Answer: Yes, Acme ships to most countries worldwide. International shipping rates and delivery times vary depending on the destination. Customers are responsible for any import duties or taxes imposed by their country. Please note that some products may not be available for international shipping due to regulations or licensing restrictions.\n",
"Price Match Policy\n",
"- We match prices from authorized retailers\n",
"- Item must be identical model/color/specification\n",
"- Must be in stock at competitor's store\n",
"- Online retailers excluded from price matching\n",
"- Price match requests must be made at time of purchase\n",
"\n",
"3. How can I track my order?\n",
"Answer: Once your order has been shipped, you will receive a confirmation email with a tracking number. You can use this number to track your package on our website or the carrier's site. If you have an account with us, you can also view your order status and tracking information in your account dashboard.\n",
"\n",
"4. What is Acme's policy on damaged items?\n",
"Answer: If you receive a damaged item, please contact our customer support within 48 hours of delivery. We will arrange for a replacement or refund, depending on your preference and product availability. Please keep the original packaging and take photos of the damage, as these may be required for our claims process.\n",
"\n",
"5. Does Acme offer bulk discounts?\n",
"Answer: Yes, we offer discounts for bulk purchases on select items. The discount percentage varies based on the product and quantity ordered. For specific bulk pricing information, please contact our sales team at bulk@acme.com or call 1-800-ACME-BULK during business hours.\n",
"\n",
"6. What is Acme's privacy policy regarding customer data?\n",
"Answer: Acme takes customer privacy seriously. We collect only necessary information for order processing and do not share personal data with third parties for marketing purposes. Customer information is securely stored and encrypted. For full details, please review our comprehensive privacy policy on our website.\n",
"Order Cancellation\n",
"- Orders can be cancelled within 2 hours of placement\n",
"- Once order is shipped, cancellation not possible\n",
"- Cancelled orders refunded to original payment method\n",
"- Processing time for refunds: 3-5 business days\n",
"- Contact customer service for cancellation requests\n",
"\n",
"QUESTION:\n",
"Hello, I just saw that the Acme Deluxe Widget I bought last week is now on sale at SuperStore for $20 less. Can you match that price and refund me the difference?\n",
"Hello, I bought a laptop from your store 3 weeks ago and it keeps shutting down randomly. It's still under warranty, right? What do I need to do to get it fixed? Thanks in advance!\n",
"\n",
"~~~~~~~~~~~\n",
"Planning:\n",
"~~~~~~~~~~~\n",
"<planning>\n",
"1. Summary of prompt template:\n",
"The goal of the user who created this template is to build a customer support chatbot for Acme Corporation. The bot is designed to answer customer questions based on the company's policies, which are provided in an FAQ format.\n",
"1. Prompt Template Summary:\n",
"This template creates a customer service chatbot for Acme Corporation that answers customer questions based on official company policies/FAQ documents. The goal is to ensure consistent, policy-compliant responses to customer inquiries.\n",
"\n",
"2. Considerations for variables:\n",
"2. Variable Analysis:\n",
"\n",
"DOCUMENTS:\n",
"- This variable will likely be populated from Acme Corporation's internal knowledge base or policy documents.\n",
"- It should contain multiple FAQ entries, each with a question and answer format and associated number..\n",
"- The content should cover various aspects of company policies, such as returns, shipping, warranties, etc.\n",
"- The language should be formal and clear, as it represents official company policies.\n",
"- Length could vary but might typically include 5-10 FAQ entries.\n",
"- Would likely be maintained by Acme's policy/legal team\n",
"- Stored in a knowledge base or content management system\n",
"- Formatted as structured FAQ entries or policy statements\n",
"- Professional, formal tone\n",
"- Multiple paragraphs covering different topics\n",
"- Clear headers and categories\n",
"- Length: Several paragraphs (300-500 words)\n",
"\n",
"QUESTION:\n",
"- This will be supplied by the end user (customer) interacting with the chatbot.\n",
"- It should be a typical customer support question related to Acme's products or services.\n",
"- The language might be informal or colloquial, as it's coming from a customer.\n",
"- It will likely be a single sentence or short paragraph.\n",
"- The question should ideally relate to one of the policy areas covered in the DOCUMENTS.\n",
"- Written by end users/customers\n",
"- Informal, conversational tone\n",
"- Usually 1-2 sentences\n",
"- Often includes context about their specific situation\n",
"- May contain typos or casual language\n",
"- Length: 20-50 words\n",
"</planning>\n"
]
}
@@ -738,19 +744,11 @@
"\n",
"To get golden answers, you can either write them yourself from scratch, or have Claude write an answer and then edit it to taste. With the advent of prompt caching, there's never been a better time to add tons of examples to your prompt to improve performance."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10d3daa6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
@@ -764,7 +762,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.14"
}
},
"nbformat": 4,

View File

@@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {
"id": "Rj3kLi4ALGKf"
},
@@ -49,7 +49,7 @@
"source": [
"import anthropic, re\n",
"ANTHROPIC_API_KEY = \"\" # Put your API key here!\n",
"MODEL_NAME = \"claude-3-5-sonnet-20240620\"\n",
"MODEL_NAME = \"claude-3-5-sonnet-20241022\"\n",
"CLIENT = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)"
]
},
@@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {
"cellView": "form",
"id": "NTOiFKNxqoq2"
@@ -577,7 +577,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 3,
"metadata": {
"id": "XPySubcpKiwg"
},
@@ -596,7 +596,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -633,7 +633,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 5,
"metadata": {
"id": "ihxetJAns9fo"
},
@@ -672,7 +672,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 6,
"metadata": {
"id": "WlaPmC6QCcYO"
},
@@ -694,7 +694,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 7,
"metadata": {
"id": "fIBhAFs4BFIA"
},
@@ -730,7 +730,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 8,
"metadata": {
"id": "GPCY1eanBFpX"
},
@@ -741,42 +741,75 @@
"text": [
"Variables:\n",
"\n",
"{'COMPANY_NAME', 'CUSTOMER_EMAIL'}\n",
"{'$CUSTOMER_EMAIL', '$COMPANY_NAME'}\n",
"\n",
"************************\n",
"\n",
"Prompt:\n",
"You will be drafting an email response to a customer complaint on behalf of a company. Here is the\n",
"full text of the email the customer sent to the company:\n",
"You will be drafting a professional email response to a customer complaint for {$COMPANY_NAME}. Here\n",
"is the customer's email:\n",
"\n",
"<customer_email>\n",
"{CUSTOMER_EMAIL}\n",
"{$CUSTOMER_EMAIL}\n",
"</customer_email>\n",
"\n",
"You are responding as a representative of the following company: {COMPANY_NAME}\n",
"Follow these guidelines when drafting your response:\n",
"\n",
"First, carefully read through the customer's email. Identify the key issues, complaints, and\n",
"problems the customer is writing about. Consider the situation from their perspective.\n",
"1. Tone and Style:\n",
"- Begin with a courteous greeting\n",
"- Maintain a professional, empathetic tone throughout\n",
"- Avoid defensive language\n",
"- Be concise but thorough\n",
"- End with a constructive closing\n",
"\n",
"Next, take a moment to brainstorm potential solutions, remedies and responses you could offer to\n",
"address each of the customer's concerns. Think about what could be done to make the situation right.\n",
"2. Content Structure:\n",
"- Acknowledge the customer's concerns specifically\n",
"- Apologize sincerely for any inconvenience\n",
"- Explain what actions will be taken (if applicable)\n",
"- Provide a clear next step or resolution\n",
"- Include contact information for follow-up\n",
"\n",
"Now draft a response email to the customer that does the following:\n",
"3. Important Rules:\n",
"- Never make promises that aren't explicitly authorized\n",
"- Don't assign blame to any parties\n",
"- Focus on solutions rather than problems\n",
"- Maintain brand professionalism\n",
"\n",
"- Acknowledges each of their complaints and expresses understanding of why they are upset\n",
"- Sincerely apologizes for any issues, problems or negative experiences they had\n",
"- Addresses each of their concerns in turn, offering a specific solution or course of action for\n",
"each one\n",
"- If some kind of compensation, refund or make-good is warranted based on the situation, offer that\n",
"- Thank them for taking the time to provide their feedback and for their valued patronage\n",
"- Invite them to reply back or contact you if they have any other issues\n",
"Here are examples of good and bad responses:\n",
"\n",
"Throughout your email, maintain a professional, understanding and non-defensive tone. The goal is to\n",
"turn a negative customer experience into a positive one through thoughtful customer service.\n",
"Empathize with their concerns and frustrations. Take responsibility where appropriate rather than\n",
"making excuses.\n",
"<good_example>\n",
"Dear Mr. Smith,\n",
"\n",
"Please output your draft response email inside <email> tags.\n"
"Thank you for bringing this matter to our attention. I sincerely apologize for the inconvenience you\n",
"experienced with your recent order. I understand how frustrating this situation must be.\n",
"\n",
"I have looked into this issue and am taking immediate steps to resolve it. Here's what we will do:\n",
"[specific action].\n",
"\n",
"Please let me know if you have any questions. You can reach me directly at [contact information].\n",
"\n",
"Best regards,\n",
"[Name]\n",
"</good_example>\n",
"\n",
"<bad_example>\n",
"Hi,\n",
"\n",
"Sorry about what happened. The shipping department made a mistake. This usually doesn't happen.\n",
"\n",
"We'll try to fix it.\n",
"\n",
"Thanks\n",
"</bad_example>\n",
"\n",
"Write your response inside <email_response> tags. Before drafting the response, analyze the\n",
"customer's concerns and plan your approach in <scratchpad> tags.\n",
"\n",
"Remember to:\n",
"- Address all specific points raised in the complaint\n",
"- Keep the tone professional but warm\n",
"- Provide specific, actionable solutions\n",
"- End with a clear path forward\n"
]
}
],
@@ -810,7 +843,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 9,
"metadata": {
"id": "rxIptUr5aZ6J"
},
@@ -819,44 +852,49 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Enter value for variable: COMPANY_NAME\n",
"AnthropiCouch Inc.\n",
"Enter value for variable: CUSTOMER_EMAIL\n",
"Your couch, while splendidly comfortable, was quite appealing to my cat as a chew toy.\n",
"Enter value for variable: $CUSTOMER_EMAIL\n",
"Enter value for variable: $COMPANY_NAME\n",
"Claude's output on your prompt:\n",
"\n",
"\n",
"Here is my draft response email:\n",
"<scratchpad>\n",
"The customer's email indicates that they encountered an issue with their recent order from\n",
"TestCompany. They express frustration with the delivery delay and lack of communication.\n",
"\n",
"<email>\n",
"Dear [Customer's Name],\n",
"To address this, the response should:\n",
"- Acknowledge the customer's concerns and apologize sincerely for the inconvenience\n",
"- Explain the steps being taken to resolve the issue\n",
"- Provide a clear next step or resolution\n",
"- Offer a direct point of contact for any follow-up\n",
"</scratchpad>\n",
"\n",
"Thank you for reaching out to us about your recent experience with one of our AnthropiCouch\n",
"products. I'm very sorry to hear that your cat has been treating our couch as a chew toy. I can\n",
"certainly understand your frustration with this situation.\n",
"<email_response>\n",
"Dear [Customer],\n",
"\n",
"As the manufacturer, we take great pride in crafting high-quality, durable furniture that is meant\n",
"to withstand the rigors of everyday life, including the occasional playful pet. However, it seems we\n",
"may have fallen short in this case, and for that I sincerely apologize.\n",
"Thank you for reaching out to us regarding your recent order with TestCompany. I sincerely apologize\n",
"for the frustration and inconvenience you have experienced.\n",
"\n",
"To make this right, I would be happy to send you a complimentary pet-safe furniture spray that can\n",
"help deter cats from chewing on the couch. This spray contains natural citrus oils that cats find\n",
"unpleasant, without harming the couch material or your pet. I'm confident this will resolve the\n",
"issue and allow your cat to enjoy the couch in a more appropriate way.\n",
"I have thoroughly reviewed the details of your order and can understand your concern about the\n",
"delayed delivery. As our valued customer, you deserve the best possible service, and we regret that\n",
"we have fallen short in this instance.\n",
"\n",
"In addition, I would like to offer you a 20% discount on your next AnthropiCouch purchase. Our\n",
"couches are designed with comfort and durability in mind, and I hope you'll give us another try.\n",
"Your satisfaction is extremely important to us.\n",
"Please be assured that I am taking immediate action to expedite the delivery of your order. I have\n",
"coordinated with our shipping team, and they have confirmed that your package will be delivered to\n",
"you by [date]. Additionally, to make up for the delay, we will be providing you with a [10%]\n",
"discount on your next purchase.\n",
"\n",
"Please let me know if there is anything else I can do to address your concerns. We value your\n",
"business and appreciate you taking the time to provide this feedback. It will help us continue\n",
"improving our products and customer service.\n",
"If you have any further questions or concerns, please do not hesitate to contact me directly at\n",
"[email] or [phone number]. I am here to ensure that your experience with TestCompany is a positive\n",
"one.\n",
"\n",
"Thank you for your patience and understanding. We value your business and look forward to serving\n",
"you better in the future.\n",
"\n",
"Best regards,\n",
"[Your Name]\n",
"Customer Service Representative\n",
"AnthropiCouch Inc.\n",
"</email>\n"
"[Your Title]\n",
"TestCompany\n",
"</email_response>\n"
]
}
],
@@ -884,15 +922,6 @@
"print(\"Claude's output on your prompt:\\n\\n\")\n",
"pretty_print(message)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e179Irl2HwSm"
},
"outputs": [],
"source": []
}
],
"metadata": {
@@ -900,7 +929,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
@@ -914,7 +943,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.14"
}
},
"nbformat": 4,

View File

@@ -28,16 +28,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install anthropic bs4"
"%pip install anthropic bs4 --quiet"
]
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -47,7 +55,7 @@
"from bs4 import BeautifulSoup\n",
"\n",
"client = anthropic.Anthropic()\n",
"MODEL_NAME = \"claude-3-5-sonnet-20240620\""
"MODEL_NAME = \"claude-3-5-sonnet-20241022\""
]
},
{
@@ -59,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -132,14 +140,14 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Non-cached API call time: 21.44 seconds\n",
"Non-cached API call time: 20.37 seconds\n",
"Non-cached API call input tokens: 17\n",
"Non-cached API call output tokens: 8\n",
"\n",
@@ -202,19 +210,19 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cached API call time: 3.64 seconds\n",
"Cached API call time: 2.92 seconds\n",
"Cached API call input tokens: 17\n",
"Cached API call output tokens: 16\n",
"Cached API call output tokens: 8\n",
"\n",
"Summary (cached):\n",
"[TextBlock(text='The title of this book is \"Pride and Prejudice\".', type='text')]\n"
"[TextBlock(text='Pride and Prejudice', type='text')]\n"
]
}
],
@@ -276,7 +284,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -292,73 +300,70 @@
"Input tokens (cache read): 0\n",
"Input tokens (cache write): 187354\n",
"0.0% of input prompt cached (4 tokens)\n",
"Time taken: 23.98 seconds\n",
"Time taken: 22.04 seconds\n",
"\n",
"Turn 2:\n",
"User: Who are Mr. and Mrs. Bennet?\n",
"Assistant: Mr. and Mrs. Bennet are the parents of the five Bennet daughters in the novel. They are key characters in the story:\n",
"Assistant: Mr. and Mrs. Bennet are the parents of five daughters (Jane, Elizabeth, Mary, Kitty, and Lydia) in Pride and Prejudice. Their personalities are quite different from each other:\n",
"\n",
"1. Mr. Bennet is the father of the family. He is described as an intelligent but sarcastic man who is often amused by the folly of others, including his wife. He tends to be detached from family matters and retreats to his library for peace.\n",
"Mr. Bennet is an intelligent but rather detached and sarcastic man who often retreats to his library to avoid his wife's dramatic behavior. He is fond of his daughter Elizabeth (Lizzy) in particular due to her wit and good sense. While he can be amusing, he is also somewhat negligent in his duties as a father and head of the household.\n",
"\n",
"2. Mrs. Bennet is the mother. She is described as a woman \"of mean understanding, little information, and uncertain temper.\" Her main goal in life is to see her daughters married to wealthy men. She is often portrayed as silly, nervous, and prone to hyperbole.\n",
"Mrs. Bennet is a rather foolish, nervous, and obsessive woman whose main goal in life is to see her daughters married to wealthy men. This preoccupation stems partly from the fact that their estate is entailed to a male heir (Mr. Collins), meaning her daughters will be left with little after Mr. Bennet's death. She often embarrasses her more sensible daughters (particularly Elizabeth and Jane) with her lack of social graces and her obvious attempts at matchmaking.\n",
"\n",
"The Bennets have five daughters: Jane, Elizabeth (the protagonist), Mary, Kitty, and Lydia. The family lives at Longbourn estate, which is entailed to Mr. Collins (a male cousin) because Mr. and Mrs. Bennet have no sons.\n",
"Their marriage is portrayed as an unfortunate example of a match based on superficial attraction (Mr. Bennet was attracted to Mrs. Bennet's youth and beauty) rather than compatibility of character and intellect, serving as a contrast to the more meaningful relationships that develop later in the novel.\n",
"User input tokens: 4\n",
"Output tokens: 218\n",
"Output tokens: 295\n",
"Input tokens (cache read): 187354\n",
"Input tokens (cache write): 36\n",
"100.0% of input prompt cached (187358 tokens)\n",
"Time taken: 8.11 seconds\n",
"Time taken: 8.32 seconds\n",
"\n",
"Turn 3:\n",
"User: What is Netherfield Park?\n",
"Assistant: Netherfield Park is an estate near the Bennet family's home of Longbourn in the novel. It plays a significant role in the story for several reasons:\n",
"Assistant: Netherfield Park is a large estate near the Bennets' home of Longbourn that is rented by Mr. Bingley at the beginning of the novel. It becomes a central location in the story as Mr. Bingley's arrival there sets many of the novel's key events in motion.\n",
"\n",
"1. It is rented by Mr. Bingley, a wealthy young man who becomes a central character in the novel.\n",
"The arrival of Mr. Bingley at Netherfield creates much excitement in the neighborhood, particularly for Mrs. Bennet, who sees him as a potential husband for one of her daughters due to his wealth (he has an income of around 4-5 thousand pounds a year). Indeed, it is at Netherfield where the romance between Jane Bennet and Mr. Bingley begins to develop.\n",
"\n",
"2. The arrival of Mr. Bingley at Netherfield sets much of the plot in motion, as he becomes a potential suitor for Jane Bennet.\n",
"Netherfield is also significant because it is where Jane falls ill while visiting Mr. Bingley's sisters, leading to Elizabeth coming to nurse her. This extended stay at Netherfield provides important opportunities for Elizabeth to interact with Mr. Darcy, though at this point in the novel their interactions are marked by pride and prejudice on both sides.\n",
"\n",
"3. It's where several important events take place, including a ball where Elizabeth and Mr. Darcy have significant interactions.\n",
"\n",
"4. Jane Bennet stays at Netherfield for a period when she falls ill, allowing for further development of relationships between the characters.\n",
"\n",
"5. It serves as a symbol of wealth and social status in the story, contrasting with the more modest Longbourn estate of the Bennets.\n",
"\n",
"The comings and goings at Netherfield Park, and the social events held there, are crucial to the development of the romantic relationships and social dynamics in the novel.\n",
"The house and estate represent wealth and social status in the novel, and its occupancy by the Bingleys brings the higher social circles of London into contact with the more provincial society of Meryton and its surroundings.\n",
"User input tokens: 4\n",
"Output tokens: 234\n",
"Output tokens: 286\n",
"Input tokens (cache read): 187390\n",
"Input tokens (cache write): 229\n",
"Input tokens (cache write): 306\n",
"100.0% of input prompt cached (187394 tokens)\n",
"Time taken: 8.24 seconds\n",
"Time taken: 10.73 seconds\n",
"\n",
"Turn 4:\n",
"User: What is the main theme of this novel?\n",
"Assistant: The main theme of \"Pride and Prejudice\" is reflected in its title: the interplay between pride and prejudice in relationships and society. However, there are several important themes that run throughout the novel:\n",
"Assistant: The main theme of \"Pride and Prejudice\" is the interplay between pride and prejudice in relationships, particularly as shown through the central romance between Elizabeth Bennet and Mr. Darcy. However, there are several important related themes:\n",
"\n",
"1. Love and Marriage: The novel explores various attitudes towards marriage, from practical arrangements to romantic love.\n",
"1. Pride and Prejudice:\n",
"- Darcy's pride in his social position initially makes him appear arrogant and disdainful\n",
"- Elizabeth's prejudice against Darcy is based on first impressions and incomplete information\n",
"- Both characters must overcome these flaws to find happiness together\n",
"\n",
"2. Pride and Prejudice: How first impressions and preconceived notions can lead to misunderstandings and misjudgments.\n",
"2. Marriage and Social Class:\n",
"- The novel explores different types of marriages (for love, security, or social advancement)\n",
"- Social class differences and their impact on relationships\n",
"- The economic necessity of marriage for women in the period\n",
"- Contrast between marriages based on true understanding (Elizabeth/Darcy, Jane/Bingley) versus those based on superficial attractions (Lydia/Wickham) or practical considerations (Charlotte/Collins)\n",
"\n",
"3. Class and Social Status: The impact of social hierarchy on relationships and personal choices.\n",
"3. Reputation and Social Expectations:\n",
"- The importance of reputation, particularly for women\n",
"- Social manners and proper behavior\n",
"- The constraints placed on women in Regency society\n",
"\n",
"4. Personal Growth and Self-awareness: Particularly through the character development of Elizabeth and Darcy.\n",
"\n",
"5. The Role of Women in Society: The novel examines the limited options available to women in early 19th-century England.\n",
"\n",
"6. Family Relationships: The dynamics within the Bennet family and how they influence the characters' decisions.\n",
"\n",
"7. Reputation and Honor: How these concepts affect social standing and personal relationships.\n",
"\n",
"8. The Balance between Sense and Sensibility: Finding a middle ground between emotional impulses and rational thought.\n",
"\n",
"While all these themes are present, the central focus is on how pride and prejudice influence relationships, particularly in the developing romance between Elizabeth Bennet and Mr. Darcy. Their journey from mutual dislike to understanding and love forms the core of the novel's thematic exploration.\n",
"4. Personal Growth and Self-Knowledge:\n",
"- Elizabeth and Darcy's journey to better understand themselves and each other\n",
"- The importance of overcoming first impressions and preconceptions\n",
"- Learning from mistakes and misj\n",
"User input tokens: 4\n",
"Output tokens: 299\n",
"Input tokens (cache read): 187619\n",
"Input tokens (cache write): 247\n",
"100.0% of input prompt cached (187623 tokens)\n",
"Time taken: 9.75 seconds\n"
"Output tokens: 300\n",
"Input tokens (cache read): 187696\n",
"Input tokens (cache write): 298\n",
"100.0% of input prompt cached (187700 tokens)\n",
"Time taken: 7.07 seconds\n"
]
}
],
@@ -494,7 +499,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see in this example, response times decreased from nearly 24 seconds to just 8-9 seconds after the initial cache setup, while maintaining the same level of quality across the answers. Most of this remaining latency is due to the time it takes to generate the response, which is not affected by prompt caching.\n",
"As you can see in this example, response times decreased from nearly 24 seconds to just 7-11 seconds after the initial cache setup, while maintaining the same level of quality across the answers. Most of this remaining latency is due to the time it takes to generate the response, which is not affected by prompt caching.\n",
"\n",
"And since nearly 100% of input tokens were cached in subsequent turns as we kept adjusting the cache breakpoints, we were able to read the next user message nearly instantly."
]
@@ -502,7 +507,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "myenv",
"display_name": "base",
"language": "python",
"name": "python3"
},
@@ -516,7 +521,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.14"
}
},
"nbformat": 4,