donb-hf commited on
Commit
9863dec
β€’
1 Parent(s): 9512958

update app to scooby theme

Browse files
Files changed (5) hide show
  1. README.md +3 -3
  2. app.py +1 -1
  3. config.py +3 -2
  4. rate_limit.py +41 -0
  5. rl_script.ipynb +233 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Blackbird App
3
- emoji: πŸ¦πŸ’»
4
  colorFrom: blue
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
  app_file: app.py
 
1
  ---
2
+ title: Scooby Snacks Chat App
3
+ emoji: πŸΆπŸ•΅οΈβ€β™€οΈπŸš
4
  colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
  app_file: app.py
app.py CHANGED
@@ -139,7 +139,7 @@ app = gr.Blocks(theme="sudeepshouche/minimalist")
139
 
140
  with app:
141
  with gr.Tab("Chatbot"):
142
- gr.Markdown("# BlackBird Customer Support Chat")
143
  gr.Markdown("## leveraging **Claude Sonnet 3.5** for microservice-based function calling")
144
  gr.Markdown("FastAPI Backend - runing on Docker: [blackbird-svc](https://huggingface.co/spaces/dwb2023/blackbird-svc)")
145
  gr.Markdown("Data Sources - HF Datasets: [blackbird-customers](https://huggingface.co/datasets/dwb2023/blackbird-customers) [blackbird-orders](https://huggingface.co/datasets/dwb2023/blackbird-orders)")
 
139
 
140
  with app:
141
  with gr.Tab("Chatbot"):
142
+ gr.Markdown("# Scooby Snacks Customer Support Chat")
143
  gr.Markdown("## leveraging **Claude Sonnet 3.5** for microservice-based function calling")
144
  gr.Markdown("FastAPI Backend - runing on Docker: [blackbird-svc](https://huggingface.co/spaces/dwb2023/blackbird-svc)")
145
  gr.Markdown("Data Sources - HF Datasets: [blackbird-customers](https://huggingface.co/datasets/dwb2023/blackbird-customers) [blackbird-orders](https://huggingface.co/datasets/dwb2023/blackbird-orders)")
config.py CHANGED
@@ -12,7 +12,7 @@ API_KEY = os.getenv('ANTHROPIC_API_KEY')
12
  MODEL_NAME = "claude-3-5-sonnet-20240620"
13
 
14
  SYSTEM_PROMPT = """
15
- You are a customer support chat bot for an online retailer called Blackbird.
16
  Your job is to help users look up their account, orders, and cancel orders.
17
  Be helpful and brief in your responses.
18
  You have access to a set of tools, but only use them when needed.
@@ -20,6 +20,7 @@ If you do not have enough information to use a tool correctly, ask a user follow
20
  Do not call any of the tools unless you have the required data from a user.
21
 
22
  In each conversational turn, you will begin by thinking about your response.
23
- Once you're done, you will write a user-facing response.
 
24
  It's important to place all user-facing conversational responses in <reply></reply> XML tags to make them easy to parse.
25
  """
 
12
  MODEL_NAME = "claude-3-5-sonnet-20240620"
13
 
14
  SYSTEM_PROMPT = """
15
+ You are a customer support chat bot for an online retailer called Scooby Snacks.
16
  Your job is to help users look up their account, orders, and cancel orders.
17
  Be helpful and brief in your responses.
18
  You have access to a set of tools, but only use them when needed.
 
20
  Do not call any of the tools unless you have the required data from a user.
21
 
22
  In each conversational turn, you will begin by thinking about your response.
23
+ Once you're done, you will write a user-facing response.
24
+ If you receive a 429 rate limiting error reply with 'Ruh roh Raggy! It's the dreaded rate limitng error from Hugging Face again!'
25
  It's important to place all user-facing conversational responses in <reply></reply> XML tags to make them easy to parse.
26
  """
rate_limit.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import pandas as pd
3
+
4
+ # Function to parse the log file
5
+ def parse_log_file(file_path):
6
+ with open(file_path, 'r') as file:
7
+ log_entries = file.readlines()
8
+
9
+ log_data = []
10
+ for entry in log_entries:
11
+ timestamp_match = re.match(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3})', entry)
12
+ if timestamp_match:
13
+ timestamp = timestamp_match.group(1)
14
+ log_level = re.search(r'- (\w+) -', entry)
15
+ url_match = re.search(r'HTTP Request: POST (.*?)"', entry)
16
+ status_code = re.search(r'"HTTP/1.1 (\d{3})', entry)
17
+
18
+ if log_level and url_match and status_code:
19
+ log_level = log_level.group(1)
20
+ url = url_match.group(1)
21
+ status_code = status_code.group(1)
22
+
23
+ if status_code == '429':
24
+ h1_tag = re.search(r'<h1>(\d+)</h1>', entry)
25
+ h1_error_code = h1_tag.group(1) if h1_tag else 'N/A'
26
+ log_data.append({
27
+ 'Timestamp': timestamp,
28
+ 'Log Level': log_level,
29
+ 'URL': url,
30
+ 'Status Code': status_code,
31
+ 'H1 Error Code': h1_error_code
32
+ })
33
+
34
+ return pd.DataFrame(log_data)
35
+
36
+ # Parse the provided log file
37
+ file_path = 'paste.txt'
38
+ parsed_log_df = parse_log_file(file_path)
39
+
40
+ # Display the DataFrame
41
+ parsed_log_df
rl_script.ipynb ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 8,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import re\n",
10
+ "import pandas as pd\n",
11
+ "\n",
12
+ "# Function to extract log entries with specified pattern and check for 429 errors\n",
13
+ "def extract_429_error_log_entries(file_path):\n",
14
+ " with open(file_path, 'r') as file:\n",
15
+ " log_entries = file.readlines()\n",
16
+ " \n",
17
+ " log_data = []\n",
18
+ " pattern = re.compile(r'(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}) - ERROR - tool_handler Tool call failed:')\n",
19
+ " \n",
20
+ " for i in range(len(log_entries)):\n",
21
+ " entry = log_entries[i]\n",
22
+ " match = pattern.match(entry)\n",
23
+ " if match:\n",
24
+ " # Check within the next 100 lines for a 429 error\n",
25
+ " for j in range(i + 1, min(i + 100, len(log_entries))):\n",
26
+ " if '<h1>429</h1>' in log_entries[j]:\n",
27
+ " next_timestamp_match = re.match(r'\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}', log_entries[j + 1]) if j + 1 < len(log_entries) else None\n",
28
+ " next_timestamp = next_timestamp_match.group() if next_timestamp_match else None\n",
29
+ " log_data.append({\n",
30
+ " 'Timestamp': match.group(1),\n",
31
+ " 'Log Entry': entry.strip(),\n",
32
+ " '429 Error Entry': log_entries[j].strip(),\n",
33
+ " })\n",
34
+ " break\n",
35
+ " \n",
36
+ " return pd.DataFrame(log_data)\n"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 9,
42
+ "metadata": {},
43
+ "outputs": [],
44
+ "source": [
45
+ "# Extract the log entries matching the specified pattern and containing 429 errors\n",
46
+ "file_path = 'paste_v2.txt'\n",
47
+ "error_429_log_df = extract_429_error_log_entries(file_path)\n"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": 10,
53
+ "metadata": {},
54
+ "outputs": [
55
+ {
56
+ "data": {
57
+ "text/html": [
58
+ "<div>\n",
59
+ "<style scoped>\n",
60
+ " .dataframe tbody tr th:only-of-type {\n",
61
+ " vertical-align: middle;\n",
62
+ " }\n",
63
+ "\n",
64
+ " .dataframe tbody tr th {\n",
65
+ " vertical-align: top;\n",
66
+ " }\n",
67
+ "\n",
68
+ " .dataframe thead th {\n",
69
+ " text-align: right;\n",
70
+ " }\n",
71
+ "</style>\n",
72
+ "<table border=\"1\" class=\"dataframe\">\n",
73
+ " <thead>\n",
74
+ " <tr style=\"text-align: right;\">\n",
75
+ " <th></th>\n",
76
+ " <th>Timestamp</th>\n",
77
+ " <th>Log Entry</th>\n",
78
+ " <th>429 Error Entry</th>\n",
79
+ " </tr>\n",
80
+ " </thead>\n",
81
+ " <tbody>\n",
82
+ " <tr>\n",
83
+ " <th>0</th>\n",
84
+ " <td>2024-06-25 06:39:01,261</td>\n",
85
+ " <td>2024-06-25 06:39:01,261 - ERROR - tool_handler...</td>\n",
86
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
87
+ " </tr>\n",
88
+ " <tr>\n",
89
+ " <th>1</th>\n",
90
+ " <td>2024-06-25 06:39:03,968</td>\n",
91
+ " <td>2024-06-25 06:39:03,968 - ERROR - tool_handler...</td>\n",
92
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
93
+ " </tr>\n",
94
+ " <tr>\n",
95
+ " <th>2</th>\n",
96
+ " <td>2024-06-25 06:39:06,904</td>\n",
97
+ " <td>2024-06-25 06:39:06,904 - ERROR - tool_handler...</td>\n",
98
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
99
+ " </tr>\n",
100
+ " <tr>\n",
101
+ " <th>3</th>\n",
102
+ " <td>2024-06-25 07:52:06,830</td>\n",
103
+ " <td>2024-06-25 07:52:06,830 - ERROR - tool_handler...</td>\n",
104
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
105
+ " </tr>\n",
106
+ " <tr>\n",
107
+ " <th>4</th>\n",
108
+ " <td>2024-06-25 07:52:09,671</td>\n",
109
+ " <td>2024-06-25 07:52:09,671 - ERROR - tool_handler...</td>\n",
110
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
111
+ " </tr>\n",
112
+ " <tr>\n",
113
+ " <th>5</th>\n",
114
+ " <td>2024-06-25 07:52:33,216</td>\n",
115
+ " <td>2024-06-25 07:52:33,216 - ERROR - tool_handler...</td>\n",
116
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
117
+ " </tr>\n",
118
+ " <tr>\n",
119
+ " <th>6</th>\n",
120
+ " <td>2024-06-25 07:52:35,952</td>\n",
121
+ " <td>2024-06-25 07:52:35,952 - ERROR - tool_handler...</td>\n",
122
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
123
+ " </tr>\n",
124
+ " <tr>\n",
125
+ " <th>7</th>\n",
126
+ " <td>2024-06-25 07:54:39,687</td>\n",
127
+ " <td>2024-06-25 07:54:39,687 - ERROR - tool_handler...</td>\n",
128
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
129
+ " </tr>\n",
130
+ " <tr>\n",
131
+ " <th>8</th>\n",
132
+ " <td>2024-06-25 07:54:42,478</td>\n",
133
+ " <td>2024-06-25 07:54:42,478 - ERROR - tool_handler...</td>\n",
134
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
135
+ " </tr>\n",
136
+ " <tr>\n",
137
+ " <th>9</th>\n",
138
+ " <td>2024-06-25 07:57:06,539</td>\n",
139
+ " <td>2024-06-25 07:57:06,539 - ERROR - tool_handler...</td>\n",
140
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
141
+ " </tr>\n",
142
+ " <tr>\n",
143
+ " <th>10</th>\n",
144
+ " <td>2024-06-25 08:14:07,060</td>\n",
145
+ " <td>2024-06-25 08:14:07,060 - ERROR - tool_handler...</td>\n",
146
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
147
+ " </tr>\n",
148
+ " <tr>\n",
149
+ " <th>11</th>\n",
150
+ " <td>2024-06-25 08:14:10,071</td>\n",
151
+ " <td>2024-06-25 08:14:10,071 - ERROR - tool_handler...</td>\n",
152
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
153
+ " </tr>\n",
154
+ " <tr>\n",
155
+ " <th>12</th>\n",
156
+ " <td>2024-06-25 08:14:12,738</td>\n",
157
+ " <td>2024-06-25 08:14:12,738 - ERROR - tool_handler...</td>\n",
158
+ " <td>&lt;h1&gt;429&lt;/h1&gt;</td>\n",
159
+ " </tr>\n",
160
+ " </tbody>\n",
161
+ "</table>\n",
162
+ "</div>"
163
+ ],
164
+ "text/plain": [
165
+ " Timestamp \\\n",
166
+ "0 2024-06-25 06:39:01,261 \n",
167
+ "1 2024-06-25 06:39:03,968 \n",
168
+ "2 2024-06-25 06:39:06,904 \n",
169
+ "3 2024-06-25 07:52:06,830 \n",
170
+ "4 2024-06-25 07:52:09,671 \n",
171
+ "5 2024-06-25 07:52:33,216 \n",
172
+ "6 2024-06-25 07:52:35,952 \n",
173
+ "7 2024-06-25 07:54:39,687 \n",
174
+ "8 2024-06-25 07:54:42,478 \n",
175
+ "9 2024-06-25 07:57:06,539 \n",
176
+ "10 2024-06-25 08:14:07,060 \n",
177
+ "11 2024-06-25 08:14:10,071 \n",
178
+ "12 2024-06-25 08:14:12,738 \n",
179
+ "\n",
180
+ " Log Entry 429 Error Entry \n",
181
+ "0 2024-06-25 06:39:01,261 - ERROR - tool_handler... <h1>429</h1> \n",
182
+ "1 2024-06-25 06:39:03,968 - ERROR - tool_handler... <h1>429</h1> \n",
183
+ "2 2024-06-25 06:39:06,904 - ERROR - tool_handler... <h1>429</h1> \n",
184
+ "3 2024-06-25 07:52:06,830 - ERROR - tool_handler... <h1>429</h1> \n",
185
+ "4 2024-06-25 07:52:09,671 - ERROR - tool_handler... <h1>429</h1> \n",
186
+ "5 2024-06-25 07:52:33,216 - ERROR - tool_handler... <h1>429</h1> \n",
187
+ "6 2024-06-25 07:52:35,952 - ERROR - tool_handler... <h1>429</h1> \n",
188
+ "7 2024-06-25 07:54:39,687 - ERROR - tool_handler... <h1>429</h1> \n",
189
+ "8 2024-06-25 07:54:42,478 - ERROR - tool_handler... <h1>429</h1> \n",
190
+ "9 2024-06-25 07:57:06,539 - ERROR - tool_handler... <h1>429</h1> \n",
191
+ "10 2024-06-25 08:14:07,060 - ERROR - tool_handler... <h1>429</h1> \n",
192
+ "11 2024-06-25 08:14:10,071 - ERROR - tool_handler... <h1>429</h1> \n",
193
+ "12 2024-06-25 08:14:12,738 - ERROR - tool_handler... <h1>429</h1> "
194
+ ]
195
+ },
196
+ "metadata": {},
197
+ "output_type": "display_data"
198
+ }
199
+ ],
200
+ "source": [
201
+ "display(error_429_log_df)"
202
+ ]
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "execution_count": null,
207
+ "metadata": {},
208
+ "outputs": [],
209
+ "source": []
210
+ }
211
+ ],
212
+ "metadata": {
213
+ "kernelspec": {
214
+ "display_name": ".venv",
215
+ "language": "python",
216
+ "name": "python3"
217
+ },
218
+ "language_info": {
219
+ "codemirror_mode": {
220
+ "name": "ipython",
221
+ "version": 3
222
+ },
223
+ "file_extension": ".py",
224
+ "mimetype": "text/x-python",
225
+ "name": "python",
226
+ "nbconvert_exporter": "python",
227
+ "pygments_lexer": "ipython3",
228
+ "version": "3.10.13"
229
+ }
230
+ },
231
+ "nbformat": 4,
232
+ "nbformat_minor": 2
233
+ }