Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set verbose as the default behavior #250

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/apps/slackapp/slackapp/bolt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@
signing_secret=cfg.SLACK_SIGNING_SECRET,
)
bot = app.client.auth_test()
ai_name = "Sherpa"
logger.info(f"App init: bot auth_test results {bot}")


###########################################################################
# usage tracker database downloader on every deployment:
###########################################################################
def before_first_request():
UserUsageTracker().download_from_s3("sherpa-sqlight" , "token_counter.db" , "./token_counter.db")
UserUsageTracker().download_from_s3(
"sherpa-sqlight", "token_counter.db", "./token_counter.db"
)


if not cfg.FLASK_DEBUG:
before_first_request()
Expand All @@ -61,14 +66,15 @@ def hello_command(ack, body):
def convert_thread_history_messages(messages: List[dict]) -> List[BaseMessage]:
results = []

ai_id = bot["user_id"]
for message in messages:
logger.info(message)
if message["type"] != "message" and message["type"] != "text":
continue

message_cls = AIMessage if message["user"] == self.ai_id else HumanMessage
message_cls = AIMessage if message["user"] == ai_id else HumanMessage
# replace the at in the message with the name of the bot
text = message["text"].replace(f"@{self.ai_id}", f"@{self.ai_name}")
text = message["text"].replace(f"@{ai_id}", f"@{ai_name}")

text = text.split("#verbose", 1)[0] # remove everything after #verbose
text = text.replace("-verbose", "") # remove -verbose if it exists
Expand Down Expand Up @@ -104,7 +110,6 @@ def get_response(
verbose_logger = verbose_logger if agent_config.verbose else DummyVerboseLogger()

tools = get_tools(memory, agent_config)
ai_name = "Sherpa"
ai_id = bot_info["user_id"]

task_agent = TaskAgent.from_llm_and_tools(
Expand All @@ -129,7 +134,7 @@ def get_response(
def file_event_handler(say, files, team_id, user_id, thread_ts, question):
if files[0]["size"] > cfg.FILE_SIZE_LIMIT:
say(
"Sorry, the file you attached is larger than 2mb. Please try again with a smaller file",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not asking for a change at this time, but noting that we should really put FILE_SIZE_LIMIT (as MB) in the message here instead of hard-coding.

"Sorry, the file you attached is larger than 2mb. Please try again with a smaller file", # noqa E501
thread_ts=thread_ts,
)
return {"status": "error"}
Expand Down Expand Up @@ -177,7 +182,7 @@ def event_test(client, say, event):
usage_cheker = user_db.check_usage(
user_id=user_id,
combined_id=combined_id,
token_amount=count_string_tokens(question, "gpt-3.5-turbo")
token_amount=count_string_tokens(question, "gpt-3.5-turbo"),
)
can_excute = usage_cheker["can_excute"]
user_db.close_connection()
Expand Down Expand Up @@ -211,7 +216,6 @@ def event_test(client, say, event):

llm = SherpaChatOpenAI(
openai_api_key=cfg.OPENAI_API_KEY,
request_timeout=120,
user_id=user_id,
team_id=team_id,
temperature=cfg.TEMPRATURE,
Expand All @@ -228,7 +232,7 @@ def event_test(client, say, event):
say(results, thread_ts=thread_ts)
else:
say(
f"""I'm sorry for any inconvenience, but it appears you've gone over your daily token limit. Don't worry, you'll be able to use our service again in approximately {usage_cheker['time_left']}.Thank you for your patience and understanding.""",
f"""I'm sorry for any inconvenience, but it appears you've gone over your daily token limit. Don't worry, you'll be able to use our service again in approximately {usage_cheker['time_left']}.Thank you for your patience and understanding.""", # noqa E501
thread_ts=thread_ts,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"input": [{"text": "You are a friendly assistent bot called Sherpa\\n\\n\\n\\nConstraints:\\n1. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\\n2. You can seek for user assistance only by using the corresponding tool\\n3. Exclusively use the commands listed in double quotes e.g. \"command name\"\\n4. You must always choose a command unless you want to \"finish\"\\n\\nCommands:\\n1. UserInput: Access the user input for the task.You use this tool if you need more context and would like to ask clarifying questions to solve the task, args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n2. Search: Access the internet to search for the information. Only use this tool when you cannot find the information using internal search., args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n3. finish: use this to signal that you have finished the current task, args: \"response\": \"final response to let people know you have finished the current task\"\\n\\nPerformance Evaluation:\\n1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\\n2. Constructively self-criticize your big-picture behavior constantly.\\n3. Reflect on past decisions and strategies to refine your approach.\\n4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\\n\\nYou should only respond in JSON format as described below without any extra text.\\nResponse Format: \\n{\\n \"thoughts\": {\\n \"text\": \"thought\",\\n \"speak\": \"thoughts summary to say to user\"\\n },\\n \"command\": {\\n \"name\": \"tool/command name you choose\",\\n \"args\": {\\n \"arg name\": \"value\"\\n }\\n }\\n} \\nEnsure the response can be parsed by Python json.loads", "agent": "system"}, {"text": "The current time and date is Mon Nov 27 11:23:37 2023", "agent": "system"}, {"text": "Current task: What is AutoGPT and how does it compare with MetaGPT \\n Determine which next command to use. Select the finish command if you and respond using the JSON format specified above without any extra text.\\n JSON Response: \\n", "agent": "human"}], "output": "{\\n \"thoughts\": {\\n \"text\": \"I'm not familiar with AutoGPT and MetaGPT. I should use the Search tool to find more information.\",\\n \"speak\": \"I'm not familiar with AutoGPT and MetaGPT. Let me search for more information.\"\\n },\\n \"command\": {\\n \"name\": \"Search\",\\n \"args\": {\\n \"query\": \"AutoGPT vs MetaGPT\"\\n }\\n }\\n}", "llm_name": "gpt-3.5-turbo"}
{"input": [{"text": "You are a friendly assistent bot called Sherpa\\n\\n\\n\\nConstraints:\\n1. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\\n2. You can seek for user assistance only by using the corresponding tool\\n3. Exclusively use the commands listed in double quotes e.g. \"command name\"\\n4. You must always choose a command unless you want to \"finish\"\\n\\nCommands:\\n1. UserInput: Access the user input for the task.You use this tool if you need more context and would like to ask clarifying questions to solve the task, args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n2. Search: Access the internet to search for the information. Only use this tool when you cannot find the information using internal search., args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n3. finish: use this to signal that you have finished the current task, args: \"response\": \"final response to let people know you have finished the current task\"\\n\\nPerformance Evaluation:\\n1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\\n2. Constructively self-criticize your big-picture behavior constantly.\\n3. Reflect on past decisions and strategies to refine your approach.\\n4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\\n\\nYou should only respond in JSON format as described below without any extra text.\\nResponse Format: \\n{\\n \"thoughts\": {\\n \"text\": \"thought\",\\n \"speak\": \"thoughts summary to say to user\"\\n },\\n \"command\": {\\n \"name\": \"tool/command name you choose\",\\n \"args\": {\\n \"arg name\": \"value\"\\n }\\n }\\n} \\nEnsure the response can be parsed by Python json.loads", "agent": "system"}, {"text": "The current time and date is Mon Nov 27 11:23:42 2023", "agent": "system"}, {"text": "Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I'm not familiar with AutoGPT and MetaGPT. I should use the Search tool to find more information.\",\\n \"speak\": \"I'm not familiar with AutoGPT and MetaGPT. Let me search for more information.\"\\n },\\n \"command\": {\\n \"name\": \"Search\",\\n \"args\": {\\n \"query\": \"AutoGPT vs MetaGPT\"\\n }\\n }\\n} \\nResult: Command Search returned: Answer: AutoGPT: AutoGPT could be used to generate text, translate languages, or write different kinds of creative content. MetaGPT: MetaGPT could be used to create multi-agent systems, or to learn from multiple datasets.\\nDocID:[1]\\n\\n ", "agent": "human"}, {"text": "Current task: What is AutoGPT and how does it compare with MetaGPT \\n Use the above information to respond to the user's message:\\nWhat is AutoGPT and how does it compare with MetaGPT\\n\\nIf you use any resource, then create inline citation by addingthe DocID of the reference document at the end of the sentence in the format of 'Sentence [DocID]'\\nExample:\\nSentence1 [1]. Sentence2. Sentence3 [2].\\nOnly use the reference document. DO NOT use any links DO NOT include citation if the resource is notnecessary. only write text but not the JSON format specified above. \\nResult:", "agent": "human"}], "output": "AutoGPT is a language model that can be used to generate text, translate languages, or write various types of creative content [1]. On the other hand, MetaGPT is a language model that can be used to create multi-agent systems or learn from multiple datasets [1]. Both AutoGPT and MetaGPT are powerful language models with different applications and use cases.", "llm_name": "gpt-3.5-turbo"}
{"input": [{"text": "You are a friendly assistent bot called Sherpa\\n\\n\\n\\nConstraints:\\n1. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\\n2. You can seek for user assistance only by using the corresponding tool\\n3. Exclusively use the commands listed in double quotes e.g. \"command name\"\\n4. You must always choose a command unless you want to \"finish\"\\n\\nCommands:\\n1. UserInput: Access the user input for the task.You use this tool if you need more context and would like to ask clarifying questions to solve the task, args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n2. Search: Access the internet to search for the information. Only use this tool when you cannot find the information using internal search., args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n3. finish: use this to signal that you have finished the current task, args: \"response\": \"final response to let people know you have finished the current task\"\\n\\nPerformance Evaluation:\\n1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\\n2. Constructively self-criticize your big-picture behavior constantly.\\n3. Reflect on past decisions and strategies to refine your approach.\\n4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\\n\\nYou should only respond in JSON format as described below without any extra text.\\nResponse Format: \\n{\\n \"thoughts\": {\\n \"text\": \"thought\",\\n \"speak\": \"thoughts summary to say to user\"\\n },\\n \"command\": {\\n \"name\": \"tool/command name you choose\",\\n \"args\": {\\n \"arg name\": \"value\"\\n }\\n }\\n} \\nEnsure the response can be parsed by Python json.loads", "agent": "system"}, {"text": "The current time and date is Tue Dec 5 20:44:23 2023", "agent": "system"}, {"text": "Current task: What is AutoGPT and how does it compare with MetaGPT \\n Determine which next command to use. Select the finish command if you and respond using the JSON format specified above without any extra text.\\n JSON Response: \\n", "agent": "human"}], "output": "{\\n \"thoughts\": {\\n \"text\": \"I'm not familiar with AutoGPT and MetaGPT. I should use the Search tool to find more information about them.\",\\n \"speak\": \"I'm not familiar with AutoGPT and MetaGPT. Let me search for more information.\"\\n },\\n \"command\": {\\n \"name\": \"Search\",\\n \"args\": {\\n \"query\": \"AutoGPT and MetaGPT comparison\"\\n }\\n }\\n}", "llm_name": "gpt-3.5-turbo"}
{"input": [{"text": "You are a friendly assistent bot called Sherpa\\n\\n\\n\\nConstraints:\\n1. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.\\n2. You can seek for user assistance only by using the corresponding tool\\n3. Exclusively use the commands listed in double quotes e.g. \"command name\"\\n4. You must always choose a command unless you want to \"finish\"\\n\\nCommands:\\n1. UserInput: Access the user input for the task.You use this tool if you need more context and would like to ask clarifying questions to solve the task, args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n2. Search: Access the internet to search for the information. Only use this tool when you cannot find the information using internal search., args json schema: {\"query\": {\"title\": \"Query\", \"type\": \"string\"}}\\n3. finish: use this to signal that you have finished the current task, args: \"response\": \"final response to let people know you have finished the current task\"\\n\\nPerformance Evaluation:\\n1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.\\n2. Constructively self-criticize your big-picture behavior constantly.\\n3. Reflect on past decisions and strategies to refine your approach.\\n4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.\\n\\nYou should only respond in JSON format as described below without any extra text.\\nResponse Format: \\n{\\n \"thoughts\": {\\n \"text\": \"thought\",\\n \"speak\": \"thoughts summary to say to user\"\\n },\\n \"command\": {\\n \"name\": \"tool/command name you choose\",\\n \"args\": {\\n \"arg name\": \"value\"\\n }\\n }\\n} \\nEnsure the response can be parsed by Python json.loads", "agent": "system"}, {"text": "The current time and date is Tue Dec 5 20:44:28 2023", "agent": "system"}, {"text": "Assistant Reply: {\\n \"thoughts\": {\\n \"text\": \"I'm not familiar with AutoGPT and MetaGPT. I should use the Search tool to find more information about them.\",\\n \"speak\": \"I'm not familiar with AutoGPT and MetaGPT. Let me search for more information.\"\\n },\\n \"command\": {\\n \"name\": \"Search\",\\n \"args\": {\\n \"query\": \"AutoGPT and MetaGPT comparison\"\\n }\\n }\\n} \\nResult: Command Search returned: Answer: AutoGPT: AutoGPT is the simplest of the three projects. It is easy to install and use, but it does not offer as many features as MetaGPT or SuperAGI. MetaGPT: MetaGPT is more complex than AutoGPT, but it offers a wider range of features.\\nDocID:[1]\\n\\n ", "agent": "human"}, {"text": "Current task: What is AutoGPT and how does it compare with MetaGPT \\n Use the above information to respond to the user's message:\\nWhat is AutoGPT and how does it compare with MetaGPT\\n\\nIf you use any resource, then create inline citation by addingthe DocID of the reference document at the end of the sentence in the format of 'Sentence [DocID]'\\nExample:\\nSentence1 [1]. Sentence2. Sentence3 [2].\\nOnly use the reference document. DO NOT use any links DO NOT include citation if the resource is notnecessary. only write text but not the JSON format specified above. \\nResult:", "agent": "human"}], "output": "AutoGPT is a project that focuses on simplicity and ease of use. It is easy to install and use, but it does not offer as many features as MetaGPT or SuperAGI [1].\\n\\nMetaGPT, on the other hand, is more complex than AutoGPT and offers a wider range of features [1].\\n\\nIn summary, AutoGPT is a simpler project compared to MetaGPT, but MetaGPT provides more advanced features and capabilities [1].", "llm_name": "gpt-3.5-turbo"}
Loading