From e5e02dfe0125271a6271e94c03c9ef68c863716d Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 21:36:16 -0800 Subject: [PATCH 01/14] first attempt at reading in snippets and text-based files --- requirements.txt | 1 + slackAskBot.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0dc625c..735687e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ slack-bolt slack-sdk openai +requests diff --git a/slackAskBot.py b/slackAskBot.py index 95b8253..cd2a463 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -1,6 +1,7 @@ import os import re import json +import requests from slack_bolt import App from slack_bolt.adapter.socket_mode import SocketModeHandler @@ -49,13 +50,15 @@ def ask_chatgpt(text, user_id, channel_id, thread_ts=None, ts=None): messages = fetch_conversation_history(channel_id, thread_ts) #print(f"DEBUG: Messages fetched from thread: {messages}") + # Retrieve snippets or files from the messages + snippets_or_files = retrieve_snippets_or_files(messages) + # Determine channel or user name for settings channel_name = determine_channel_or_user_name(channel_id, user_id) print(f"Channel/user name: {channel_name}") # Print the channel name for debugging # Load channel-specific settings system_prompt, please_wait_message = load_channel_settings(channel_name) - #print(f"Using system_prompt: '{system_prompt}'") print(f"Using please_wait_message: '{please_wait_message}' for channel/user name: {channel_name}") # Get the bot's user ID @@ -63,7 +66,6 @@ def ask_chatgpt(text, user_id, channel_id, thread_ts=None, ts=None): # Construct the conversation history conversation_history = construct_conversation_history(messages, bot_user_id, user_id, text, thread_ts, ts) - #print(f"DEBUG: Constructed conversation history: {conversation_history}") # Send a message to indicate that GPT-4 is working on the request and capture the timestamp status_message_ts = post_message_to_slack(channel_id, please_wait_message, thread_ts) @@ -74,8 +76,15 @@ def worker(): initial_footer_ts = None initial_status_ts = None + # Retrieve snippet or file content + for snippet_or_file in snippets_or_files: + content = retrieve_snippet_or_file_content(snippet_or_file) + # Process the content as needed + processed_content = process_snippet_or_file_content(content) + # Append the processed content to the conversation history + conversation_history.append({"role": "assistant", "content": processed_content}) + # Generate initial response with GPT-3.5-turbo - #print(conversation_history) try: initial_response, initial_status_ts = gpt(conversation_history, system_prompt, model="gpt-3.5-turbo-16k", max_tokens=1000, channel_id=channel_id, thread_ts=thread_ts) # Modify the markdown to strip out the language specifier after the triple backticks @@ -93,7 +102,6 @@ def worker(): conversation_history.append({"role": "assistant", "content": synthetic_review}) except Exception as e: print(f"Error from GPT-3.5: {e}") - #print(conversation_history) # Enhance response with GPT-4-Turbo enhanced_response, enhanced_response_ts = gpt(conversation_history, system_prompt, model="gpt-4-turbo-preview", channel_id=channel_id, thread_ts=thread_ts) @@ -134,6 +142,36 @@ def worker(): thread = threading.Thread(target=worker) thread.start() +def retrieve_snippets_or_files(messages): + snippets_or_files_info = [] + for message in messages: + if 'files' in message: + for file in message['files']: + if file['filetype'] in ['text', 'python', 'javascript', 'html']: # Add other file types as needed + snippets_or_files_info.append({ + 'id': file['id'], + 'name': file.get('name'), + 'filetype': file['filetype'], + 'url_private': file['url_private'] + }) + return snippets_or_files_info + +def retrieve_snippet_or_file_content(snippet_or_file): + url = snippet_or_file['url_private'] + headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} + response = requests.get(url, headers=headers) + if response.status_code == 200: + return response.text + else: + print(f"Failed to retrieve file content: {response.status_code}") + return "" + +def process_snippet_or_file_content(content): + # This is a placeholder function. You can process the content as needed here. + # For example, you might want to clean up the text, parse code, etc. + # For simplicity, this example just returns the content as is. + return content + def fetch_conversation_history(channel_id, thread_ts): try: history = app.client.conversations_replies(channel=channel_id, ts=thread_ts) From 5f3217781bd22ea5672a36b507014b9064658540 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 21:51:30 -0800 Subject: [PATCH 02/14] debugging --- slackAskBot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index cd2a463..1732d18 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -161,9 +161,12 @@ def retrieve_snippet_or_file_content(snippet_or_file): headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} response = requests.get(url, headers=headers) if response.status_code == 200: + print(f"Successfully retrieved file content from URL: {url}") + print(f"Response: {response.text}") return response.text else: - print(f"Failed to retrieve file content: {response.status_code}") + print(f"Failed to retrieve file content from URL: {url}") + print(f"Response status code: {response.status_code}") return "" def process_snippet_or_file_content(content): From 0c10167222be283a8c68e1fe8a6cae3567155894 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 21:53:43 -0800 Subject: [PATCH 03/14] debugging --- slackAskBot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index 1732d18..674f7db 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -82,7 +82,8 @@ def worker(): # Process the content as needed processed_content = process_snippet_or_file_content(content) # Append the processed content to the conversation history - conversation_history.append({"role": "assistant", "content": processed_content}) + conversation_history.append({"role": "user", "content": processed_content}) + print(conversation_history) # Generate initial response with GPT-3.5-turbo try: From 3680731aa5348c891128e8b8c4e8ae55850087e5 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 22:43:28 -0800 Subject: [PATCH 04/14] integrate file loading code directly into construct_conversation_history --- slackAskBot.py | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/slackAskBot.py b/slackAskBot.py index 674f7db..2509e05 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -50,9 +50,6 @@ def ask_chatgpt(text, user_id, channel_id, thread_ts=None, ts=None): messages = fetch_conversation_history(channel_id, thread_ts) #print(f"DEBUG: Messages fetched from thread: {messages}") - # Retrieve snippets or files from the messages - snippets_or_files = retrieve_snippets_or_files(messages) - # Determine channel or user name for settings channel_name = determine_channel_or_user_name(channel_id, user_id) print(f"Channel/user name: {channel_name}") # Print the channel name for debugging @@ -76,15 +73,6 @@ def worker(): initial_footer_ts = None initial_status_ts = None - # Retrieve snippet or file content - for snippet_or_file in snippets_or_files: - content = retrieve_snippet_or_file_content(snippet_or_file) - # Process the content as needed - processed_content = process_snippet_or_file_content(content) - # Append the processed content to the conversation history - conversation_history.append({"role": "user", "content": processed_content}) - print(conversation_history) - # Generate initial response with GPT-3.5-turbo try: initial_response, initial_status_ts = gpt(conversation_history, system_prompt, model="gpt-3.5-turbo-16k", max_tokens=1000, channel_id=channel_id, thread_ts=thread_ts) @@ -143,20 +131,6 @@ def worker(): thread = threading.Thread(target=worker) thread.start() -def retrieve_snippets_or_files(messages): - snippets_or_files_info = [] - for message in messages: - if 'files' in message: - for file in message['files']: - if file['filetype'] in ['text', 'python', 'javascript', 'html']: # Add other file types as needed - snippets_or_files_info.append({ - 'id': file['id'], - 'name': file.get('name'), - 'filetype': file['filetype'], - 'url_private': file['url_private'] - }) - return snippets_or_files_info - def retrieve_snippet_or_file_content(snippet_or_file): url = snippet_or_file['url_private'] headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} @@ -170,12 +144,6 @@ def retrieve_snippet_or_file_content(snippet_or_file): print(f"Response status code: {response.status_code}") return "" -def process_snippet_or_file_content(content): - # This is a placeholder function. You can process the content as needed here. - # For example, you might want to clean up the text, parse code, etc. - # For simplicity, this example just returns the content as is. - return content - def fetch_conversation_history(channel_id, thread_ts): try: history = app.client.conversations_replies(channel=channel_id, ts=thread_ts) @@ -239,10 +207,24 @@ def construct_conversation_history(messages, bot_user_id, user_id, current_text, content = msg.get("text") if content: conversation_history.append({"role": role, "content": content}) + if 'files' in msg: + for file in msg['files']: + if file['filetype'] in ['text', 'python', 'javascript', 'html']: # Add other file types as needed + url = file['url_private'] + headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} + response = requests.get(url, headers=headers) + if response.status_code == 200: + print(f"Successfully retrieved file content from URL: {url}") + print(f"Response: {response.text}") + conversation_history.append({"role": role, "content": response.text}) + else: + print(f"Failed to retrieve file content from URL: {url}") + print(f"Response status code: {response.status_code}") # Add the current message to the conversation history if it's not already included if not thread_ts or thread_ts == ts: conversation_history.append({"role": "user", "content": current_text}) + print(conversation_history) return conversation_history From 9c60ab1c8d2ba5ae0a43a810c5c25e6120f2954b Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 22:58:26 -0800 Subject: [PATCH 05/14] break out generate_initial_response() from ask_chatgpt() --- slackAskBot.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/slackAskBot.py b/slackAskBot.py index 2509e05..9812472 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -68,29 +68,7 @@ def ask_chatgpt(text, user_id, channel_id, thread_ts=None, ts=None): status_message_ts = post_message_to_slack(channel_id, please_wait_message, thread_ts) def worker(): - initial_header_ts = None - initial_response_ts = None - initial_footer_ts = None - initial_status_ts = None - - # Generate initial response with GPT-3.5-turbo - try: - initial_response, initial_status_ts = gpt(conversation_history, system_prompt, model="gpt-3.5-turbo-16k", max_tokens=1000, channel_id=channel_id, thread_ts=thread_ts) - # Modify the markdown to strip out the language specifier after the triple backticks - initial_response = re.sub(r'```[a-zA-Z]+', '```', initial_response) - print(initial_response) - # Post the GPT-3.5-turbo response and save its timestamp - initial_header_ts = post_message_to_slack(channel_id, "Initial GPT-3.5-Turbo response:", thread_ts) - initial_response_ts = post_message_to_slack(channel_id, f"{initial_response}", thread_ts) - initial_footer_ts = post_message_to_slack(channel_id, "Checking that with GPT-4...", thread_ts) - # Append the initial GPT-3.5-turbo response to the conversation history - conversation_history.append({"role": "assistant", "content": f"GPT-3.5 response: {initial_response}"}) - - # Synthetic review process - synthetic_review = "Let’s review the GPT-3.5 response and determine whether any corrections, clarifications, or elaborations are required. If no changes are needed, reply with 'GOOD AS-IS' in all caps. If the GPT-3.5 response needs to be completely replaced, don't refer to it: just respond with a new message, and the old one be deleted and not visible. DO NOT make reference to 'a misunderstanding in my previous response', 'My mistake', or similar: just write a new and better response. If the GPT-3.5 response only needs clarification or elaboration, not correction, instead reply with 'ADDITIONAL RESPONSE: ' in all caps, followed by a follow-up message with any clarifications or elaborations we want to append to the last reply. If you can't tell for sure without a tool call whether the response is correct or not, go ahead and make the tool call." - conversation_history.append({"role": "assistant", "content": synthetic_review}) - except Exception as e: - print(f"Error from GPT-3.5: {e}") + initial_header_ts, initial_response_ts, initial_footer_ts, initial_status_ts = generate_initial_response(conversation_history, system_prompt, channel_id, thread_ts) # Enhance response with GPT-4-Turbo enhanced_response, enhanced_response_ts = gpt(conversation_history, system_prompt, model="gpt-4-turbo-preview", channel_id=channel_id, thread_ts=thread_ts) @@ -131,6 +109,27 @@ def worker(): thread = threading.Thread(target=worker) thread.start() +def generate_initial_response(conversation_history, system_prompt, channel_id, thread_ts): + initial_header_ts = None + initial_response_ts = None + initial_footer_ts = None + initial_status_ts = None + + try: + initial_response, initial_status_ts = gpt(conversation_history, system_prompt, model="gpt-3.5-turbo-16k", max_tokens=1000, channel_id=channel_id, thread_ts=thread_ts) + initial_response = re.sub(r'```[a-zA-Z]+', '```', initial_response) + print(initial_response) + initial_header_ts = post_message_to_slack(channel_id, "Initial GPT-3.5-Turbo response:", thread_ts) + initial_response_ts = post_message_to_slack(channel_id, f"{initial_response}", thread_ts) + initial_footer_ts = post_message_to_slack(channel_id, "Checking that with GPT-4...", thread_ts) + conversation_history.append({"role": "assistant", "content": f"GPT-3.5 response: {initial_response}"}) + synthetic_review = "Let's review the GPT-3.5 response and determine whether any corrections, clarifications, or elaborations are required. If no changes are needed, reply with 'GOOD AS-IS' in all caps. If the GPT-3.5 response needs to be completely replaced, don't refer to it: just respond with a new message, and the old one be deleted and not visible. DO NOT make reference to 'a misunderstanding in my previous response', 'My mistake', or similar: just write a new and better response. If the GPT-3.5 response only needs clarification or elaboration, not correction, instead reply with 'ADDITIONAL RESPONSE: ' in all caps, followed by a follow-up message with any clarifications or elaborations we want to append to the last reply. If you can't tell for sure without a tool call whether the response is correct or not, go ahead and make the tool call." + conversation_history.append({"role": "assistant", "content": synthetic_review}) + except Exception as e: + print(f"Error from GPT-3.5: {e}") + + return initial_header_ts, initial_response_ts, initial_footer_ts, initial_status_ts + def retrieve_snippet_or_file_content(snippet_or_file): url = snippet_or_file['url_private'] headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} From cbf187693a8b29c5d4722e1bcc819e5f6115140c Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 23:00:11 -0800 Subject: [PATCH 06/14] undebug --- slackAskBot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index 9812472..34ba1d6 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -223,7 +223,6 @@ def construct_conversation_history(messages, bot_user_id, user_id, current_text, # Add the current message to the conversation history if it's not already included if not thread_ts or thread_ts == ts: conversation_history.append({"role": "user", "content": current_text}) - print(conversation_history) return conversation_history From 8c5130cbfc219020f855d45f83e7108dbd8d2c97 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 23:02:11 -0800 Subject: [PATCH 07/14] undebug --- slackAskBot.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/slackAskBot.py b/slackAskBot.py index 34ba1d6..9cbd9d1 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -48,7 +48,6 @@ def ask_chatgpt(text, user_id, channel_id, thread_ts=None, ts=None): messages = [] if thread_ts: messages = fetch_conversation_history(channel_id, thread_ts) - #print(f"DEBUG: Messages fetched from thread: {messages}") # Determine channel or user name for settings channel_name = determine_channel_or_user_name(channel_id, user_id) @@ -136,7 +135,7 @@ def retrieve_snippet_or_file_content(snippet_or_file): response = requests.get(url, headers=headers) if response.status_code == 200: print(f"Successfully retrieved file content from URL: {url}") - print(f"Response: {response.text}") + #print(f"Response: {response.text}") return response.text else: print(f"Failed to retrieve file content from URL: {url}") @@ -146,7 +145,6 @@ def retrieve_snippet_or_file_content(snippet_or_file): def fetch_conversation_history(channel_id, thread_ts): try: history = app.client.conversations_replies(channel=channel_id, ts=thread_ts) - #print(f"DEBUG: Fetched conversation history for channel {channel_id} and thread {thread_ts}. Messages count: {len(history['messages'])}") return history['messages'] except SlackApiError as e: print(f"Failed to fetch conversation history: {e}") From 908084b4e7f514d5bd3b9ea9e5b0d86c03b76261 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Tue, 13 Feb 2024 23:04:46 -0800 Subject: [PATCH 08/14] remove unused function --- slackAskBot.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/slackAskBot.py b/slackAskBot.py index 9cbd9d1..3941e44 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -129,19 +129,6 @@ def generate_initial_response(conversation_history, system_prompt, channel_id, t return initial_header_ts, initial_response_ts, initial_footer_ts, initial_status_ts -def retrieve_snippet_or_file_content(snippet_or_file): - url = snippet_or_file['url_private'] - headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} - response = requests.get(url, headers=headers) - if response.status_code == 200: - print(f"Successfully retrieved file content from URL: {url}") - #print(f"Response: {response.text}") - return response.text - else: - print(f"Failed to retrieve file content from URL: {url}") - print(f"Response status code: {response.status_code}") - return "" - def fetch_conversation_history(channel_id, thread_ts): try: history = app.client.conversations_replies(channel=channel_id, ts=thread_ts) @@ -212,7 +199,7 @@ def construct_conversation_history(messages, bot_user_id, user_id, current_text, response = requests.get(url, headers=headers) if response.status_code == 200: print(f"Successfully retrieved file content from URL: {url}") - print(f"Response: {response.text}") + #print(f"Response: {response.text}") conversation_history.append({"role": role, "content": response.text}) else: print(f"Failed to retrieve file content from URL: {url}") From ee31d3e9c36b24da8e803da1b507b460dd148209 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 00:31:28 -0800 Subject: [PATCH 09/14] surface context length errors to user in Slack --- slackAskBot.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index 3941e44..a924100 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -345,7 +345,17 @@ def gpt(conversation_history, system_prompt, channel_id, thread_ts=None, model=" if tools_parameter: request_payload["tools"] = tools_parameter - response = client.chat.completions.create(**request_payload) + try: + response = client.chat.completions.create(**request_payload) + except Exception as e: + error_message = str(e) + print(f"Error from GPT: {error_message}") + if "context length" in error_message: + if model == "gpt-3.5-turbo-16k": + post_message_to_slack(channel_id, "This thread is too long for GPT-3.5. Please wait for GPT-4.", thread_ts) + elif model == "gpt-4-turbo-preview": + post_message_to_slack(channel_id, "This thread is too long for GPT-4. Please start another shorter thread.", thread_ts) + return None, "error" # Debugging: Print the entire GPT response print("GPT Response:", response) From 0c1f9c296f7f42852c1299bccf5ba6e1f9ff22c2 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 00:45:38 -0800 Subject: [PATCH 10/14] catch Request too large too --- slackAskBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index a924100..121ec26 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -350,7 +350,7 @@ def gpt(conversation_history, system_prompt, channel_id, thread_ts=None, model=" except Exception as e: error_message = str(e) print(f"Error from GPT: {error_message}") - if "context length" in error_message: + if "context length" in error_message or "Request too large" in error_message: if model == "gpt-3.5-turbo-16k": post_message_to_slack(channel_id, "This thread is too long for GPT-3.5. Please wait for GPT-4.", thread_ts) elif model == "gpt-4-turbo-preview": From 891cc6564cd6faf951eb50a3fe3cb679e5af8b2f Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 00:55:45 -0800 Subject: [PATCH 11/14] file type debugging --- slackAskBot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slackAskBot.py b/slackAskBot.py index 121ec26..eacdef3 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -204,6 +204,8 @@ def construct_conversation_history(messages, bot_user_id, user_id, current_text, else: print(f"Failed to retrieve file content from URL: {url}") print(f"Response status code: {response.status_code}") + else: + print(f"Not adding file type {file['filetype']}") # Add the current message to the conversation history if it's not already included if not thread_ts or thread_ts == ts: From 8036e3947bec8e54cc932b604eea3ee0d1d2a7cc Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 00:56:44 -0800 Subject: [PATCH 12/14] add diff files --- slackAskBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slackAskBot.py b/slackAskBot.py index eacdef3..5933157 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -193,7 +193,7 @@ def construct_conversation_history(messages, bot_user_id, user_id, current_text, conversation_history.append({"role": role, "content": content}) if 'files' in msg: for file in msg['files']: - if file['filetype'] in ['text', 'python', 'javascript', 'html']: # Add other file types as needed + if file['filetype'] in ['text', 'python', 'javascript', 'html', 'diff']: # Add other file types as needed url = file['url_private'] headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"} response = requests.get(url, headers=headers) From e7d55d8b5eefc26f59c80cea3deb6c39317366c9 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 01:10:20 -0800 Subject: [PATCH 13/14] enforce a 128 KB size limit on context (well below GPT-4's 128k token limit) --- slackAskBot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/slackAskBot.py b/slackAskBot.py index 5933157..dc40b07 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -347,6 +347,13 @@ def gpt(conversation_history, system_prompt, channel_id, thread_ts=None, model=" if tools_parameter: request_payload["tools"] = tools_parameter + # Serialize the request payload to JSON for size check + serialized_payload = json.dumps(request_payload) + if len(serialized_payload.encode('utf-8')) > 128 * 1024: # Check if the payload exceeds 128 KB + print("Payload exceeds 128 KB limit.") + post_message_to_slack(channel_id, "This thread is too long. Please start another shorter thread.", thread_ts) + return "The request cannot be processed because it exceeds the 128 KB limit.", None + try: response = client.chat.completions.create(**request_payload) except Exception as e: From e1f90c7a86f555c5f65f86c0dcbd34f99e26d706 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Wed, 14 Feb 2024 01:14:39 -0800 Subject: [PATCH 14/14] remove redundant Slack posts --- slackAskBot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slackAskBot.py b/slackAskBot.py index dc40b07..ed7764d 100644 --- a/slackAskBot.py +++ b/slackAskBot.py @@ -351,8 +351,7 @@ def gpt(conversation_history, system_prompt, channel_id, thread_ts=None, model=" serialized_payload = json.dumps(request_payload) if len(serialized_payload.encode('utf-8')) > 128 * 1024: # Check if the payload exceeds 128 KB print("Payload exceeds 128 KB limit.") - post_message_to_slack(channel_id, "This thread is too long. Please start another shorter thread.", thread_ts) - return "The request cannot be processed because it exceeds the 128 KB limit.", None + return "This thread is too long. Please start another shorter thread.", None try: response = client.chat.completions.create(**request_payload)