Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,11 +16,14 @@ logging.basicConfig(level=logging.INFO)
|
|
| 16 |
logging.info('App loading\n\n')
|
| 17 |
|
| 18 |
# Import tool from Hub
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
# Initialize the agent with the image generation tool
|
| 23 |
-
agent = ReactCodeAgent(
|
|
|
|
|
|
|
| 24 |
|
| 25 |
logging.info('App initialized \n')
|
| 26 |
|
|
@@ -29,10 +32,6 @@ app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
|
|
| 29 |
|
| 30 |
assistant = Assistant()
|
| 31 |
|
| 32 |
-
# call LLLM
|
| 33 |
-
def call_llm(query):
|
| 34 |
-
return agent.run(query)
|
| 35 |
-
|
| 36 |
# This listener is invoked when a human user opened an assistant thread
|
| 37 |
@assistant.thread_started
|
| 38 |
def start_assistant_thread(say: Say, set_suggested_prompts: SetSuggestedPrompts):
|
|
@@ -43,8 +42,8 @@ def start_assistant_thread(say: Say, set_suggested_prompts: SetSuggestedPrompts)
|
|
| 43 |
set_suggested_prompts(
|
| 44 |
prompts=[
|
| 45 |
# If the suggested prompt is long, you can use {"title": "short one to display", "message": "full prompt"} instead
|
| 46 |
-
{"title" : "
|
| 47 |
-
"message": "Read
|
| 48 |
],
|
| 49 |
)
|
| 50 |
|
|
@@ -60,26 +59,12 @@ def respond_in_assistant_thread(
|
|
| 60 |
):
|
| 61 |
try:
|
| 62 |
# Tell the human user the assistant bot acknowledges the request and is working on it
|
| 63 |
-
set_status("
|
| 64 |
|
| 65 |
query = payload['blocks'][0]['elements'][0]['elements'][0]['text']
|
| 66 |
-
|
| 67 |
-
logging.info('Query ' + query + '\n')
|
| 68 |
|
| 69 |
-
# # Collect the conversation history with this user
|
| 70 |
-
# replies_in_thread = client.conversations_replies(
|
| 71 |
-
# channel=context.channel_id,
|
| 72 |
-
# ts=context.thread_ts,
|
| 73 |
-
# oldest=context.thread_ts,
|
| 74 |
-
# limit=10,
|
| 75 |
-
# )
|
| 76 |
-
# messages_in_thread: List[Dict[str, str]] = []
|
| 77 |
-
# for message in replies_in_thread["messages"]:
|
| 78 |
-
# role = "user" if message.get("bot_id") is None else "assistant"
|
| 79 |
-
# messages_in_thread.append({"role": role, "content": message["text"]})
|
| 80 |
-
|
| 81 |
# Pass the latest prompt and chat history to the LLM (call_llm is your own code)
|
| 82 |
-
agent_gen = agent.run(task=query, stream=True, url="https://slack.engineering/")
|
| 83 |
|
| 84 |
for val in agent_gen:
|
| 85 |
if 'final_answer' in val:
|
|
|
|
| 16 |
logging.info('App loading\n\n')
|
| 17 |
|
| 18 |
# Import tool from Hub
|
| 19 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 20 |
+
|
| 21 |
+
llm_engine = HfApiEngine(model="Qwen/Qwen2.5-72B-Instruct", token=hf_token)
|
| 22 |
|
| 23 |
# Initialize the agent with the image generation tool
|
| 24 |
+
agent = ReactCodeAgent(
|
| 25 |
+
tools=[], llm_engine=llm_engine, additional_authorized_imports=['requests', 'bs4', "html5lib"], add_base_tools=True
|
| 26 |
+
)
|
| 27 |
|
| 28 |
logging.info('App initialized \n')
|
| 29 |
|
|
|
|
| 32 |
|
| 33 |
assistant = Assistant()
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# This listener is invoked when a human user opened an assistant thread
|
| 36 |
@assistant.thread_started
|
| 37 |
def start_assistant_thread(say: Say, set_suggested_prompts: SetSuggestedPrompts):
|
|
|
|
| 42 |
set_suggested_prompts(
|
| 43 |
prompts=[
|
| 44 |
# If the suggested prompt is long, you can use {"title": "short one to display", "message": "full prompt"} instead
|
| 45 |
+
{"title" : "Summarize latest post from Slack engineering blog",
|
| 46 |
+
"message": "Read blog post https://slack.engineering/slack-audit-logs-and-anomalies/ and summarize it in 200 words"}
|
| 47 |
],
|
| 48 |
)
|
| 49 |
|
|
|
|
| 59 |
):
|
| 60 |
try:
|
| 61 |
# Tell the human user the assistant bot acknowledges the request and is working on it
|
| 62 |
+
set_status("is hard at work...")
|
| 63 |
|
| 64 |
query = payload['blocks'][0]['elements'][0]['elements'][0]['text']
|
|
|
|
|
|
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# Pass the latest prompt and chat history to the LLM (call_llm is your own code)
|
| 67 |
+
agent_gen = agent.run(task=query, stream=True, url="https://slack.engineering/slack-audit-logs-and-anomalies/")
|
| 68 |
|
| 69 |
for val in agent_gen:
|
| 70 |
if 'final_answer' in val:
|