Skip to content

Commit

Permalink
fix(agents-api): Fix JobStatus name in get job endpoint (#544)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Fixes `name` attribute in `get_job_status` in `routers.py` and updates
string encoding and exception syntax in other files.
> 
>   - **Behavior**:
> - Fixes `name` attribute in `get_job_status` function in `routers.py`
to use `job_description.workflow_type` instead of `handle.id`.
>   - **Formatting**:
> - Adjusts string encoding in `raise_complete_async.py` and
`update_execution.py` to use double quotes for `ascii`.
> - Updates exception raising syntax in `update_execution.py` for
consistency.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for bfc8490. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
HamadaSalhab authored Oct 2, 2024
1 parent 50a95ca commit 990ea1a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64

from temporalio import activity

from ...autogen.openapi_model import CreateTransitionRequest
Expand All @@ -11,10 +12,9 @@

@activity.defn
async def raise_complete_async(context: StepContext, output: StepOutcome) -> None:

activity_info = activity.info()

captured_token = base64.b64encode(activity_info.task_token).decode('ascii')
captured_token = base64.b64encode(activity_info.task_token).decode("ascii")
activity_id = activity_info.activity_id
workflow_run_id = activity_info.workflow_run_id
workflow_id = activity_info.workflow_id
Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/routers/jobs/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def get_job_status(job_id: UUID) -> JobStatus:
state = map_job_status(job_description.status)

return JobStatus(
name=handle.id,
name=job_description.workflow_type,
reason=f"Execution status: {state}",
created_at=job_description.start_time,
updated_at=job_description.execution_time,
Expand Down
8 changes: 6 additions & 2 deletions agents-api/agents_api/routers/tasks/update_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async def update_execution(
workflow_id = token_data["metadata"].get("x-workflow-id", None)
if activity_id is None or run_id is None or workflow_id is None:
act_handle = temporal_client.get_async_activity_handle(
task_token=base64.b64decode(token_data["task_token"].encode('ascii')),
task_token=base64.b64decode(
token_data["task_token"].encode("ascii")
),
)

else:
Expand All @@ -59,6 +61,8 @@ async def update_execution(
try:
await act_handle.complete(data.input)
except Exception as e:
raise HTTPException(status_code=500, detail="Failed to resume execution")
raise HTTPException(
status_code=500, detail="Failed to resume execution"
)
case _:
raise HTTPException(status_code=400, detail="Invalid request data")
4 changes: 3 additions & 1 deletion agents-api/notebooks/03-summarise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@
" messages.append(user(start_message))\n",
"\n",
" print(\"Starting chatml generation\")\n",
" trim_result = generate(messages, model=\"gpt-4-turbo\", temperature=0.1, stop=[\"</ct\"])\n",
" trim_result = generate(\n",
" messages, model=\"gpt-4-turbo\", temperature=0.1, stop=[\"</ct\"]\n",
" )\n",
" print(\"End chatml generation\")\n",
" messages.append(trim_result)\n",
"\n",
Expand Down
84 changes: 48 additions & 36 deletions agents-api/notebooks/RecSum-experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"source": [
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv(\"../../.env\")"
]
},
Expand Down Expand Up @@ -56,7 +57,9 @@
"}\n",
"\n",
"user = lambda content, name=None: make_chatml(role=\"user\", content=content, name=name)\n",
"assistant = lambda content, name=None: make_chatml(role=\"assistant\", content=content, name=name)\n",
"assistant = lambda content, name=None: make_chatml(\n",
" role=\"assistant\", content=content, name=name\n",
")\n",
"system = lambda content, name=None: make_chatml(content, name=name)\n",
"thought = lambda content: system(content, name=\"thought\")\n",
"information = lambda content: system(content, name=\"information\")\n",
Expand All @@ -76,7 +79,13 @@
" # ((chat_session, 0): (chat_summaries, 1)),\n",
"]\n",
"\n",
"generate = lambda history, model=\"gpt-3.5-turbo\", **kwargs: client.chat.completions.create(messages=history, model=model, **kwargs).choices[0].message.__dict__"
"generate = (\n",
" lambda history, model=\"gpt-3.5-turbo\", **kwargs: client.chat.completions.create(\n",
" messages=history, model=model, **kwargs\n",
" )\n",
" .choices[0]\n",
" .message.__dict__\n",
")"
]
},
{
Expand All @@ -88,13 +97,14 @@
"source": [
"from pprint import pprint\n",
"\n",
"\n",
"def chat():\n",
" while (user_input := input('You: ')) != \"bye\":\n",
" while (user_input := input(\"You: \")) != \"bye\":\n",
" chat_session.append(user(user_input))\n",
" \n",
"\n",
" result = generate(chat_session)\n",
" print(f\"GPT: {result['content']}\")\n",
" \n",
"\n",
" chat_session.append(make_chatml(**result))"
]
},
Expand All @@ -106,23 +116,19 @@
"outputs": [],
"source": [
"import json\n",
"\n",
"example_chat = [\n",
" {\n",
" \"role\": \"system\",\n",
" \"content\": \"just have a casual chat with a friend friend\",\n",
" \"index\": 0,\n",
" },\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"yo\",\n",
" \"index\": 1,\n",
" \"name\": \"Camille\"\n",
" },\n",
" {\"role\": \"user\", \"content\": \"yo\", \"index\": 1, \"name\": \"Camille\"},\n",
" {\n",
" \"role\": \"assistant\",\n",
" \"content\": \"Hey, how's it going?\",\n",
" \"index\": 2,\n",
" \"name\": \"JaneBot\"\n",
" \"name\": \"JaneBot\",\n",
" },\n",
" {\n",
" \"role\": \"user\",\n",
Expand Down Expand Up @@ -221,7 +227,7 @@
" },\n",
" {\n",
" \"role\": \"assistant\",\n",
" \"content\": \"Based on the themes of starting anew, embracing failure, and the journey from zero to one, I would guess that the title of this story is \\\"Back to One.\\\" It seems to capture the essence of the protagonist's experience and mindset throughout the story. How did I do?\",\n",
" \"content\": 'Based on the themes of starting anew, embracing failure, and the journey from zero to one, I would guess that the title of this story is \"Back to One.\" It seems to capture the essence of the protagonist\\'s experience and mindset throughout the story. How did I do?',\n",
" \"index\": 22,\n",
" },\n",
" {\n",
Expand Down Expand Up @@ -283,7 +289,7 @@
" \"role\": \"assistant\",\n",
" \"content\": \"From my interactions with you so far, I can tell that you have a great sense of humor and enjoy playful banter. You seem open to random and fun conversations, and you're not afraid to keep things interesting with unexpected twists and turns.\\n\\nYour creativity shines through in the way you approach different topics, and you have a knack for surprising me with your responses. You're also quite adept at changing the direction of the conversation while maintaining a light and friendly tone.\\n\\nOverall, chatting with you has been enjoyable and entertaining, and I appreciate the lighthearted and casual vibe you bring to our interactions. I look forward to more fun conversations with you in the future!\",\n",
" \"index\": 34,\n",
" }\n",
" },\n",
"]"
]
},
Expand Down Expand Up @@ -316,17 +322,23 @@
"2. JaneBot (The assistant): Engages in lighthearted conversation and tries to guess user's thoughts.\n",
"3. Elon Musk: Polarizing tech and space industry figure.\n",
"4. Bananas: User has a tattoo of one on their arm.\"\"\"),\n",
" summary(\"Event: Camille says hi to JaneBot and they reply that they are working and trying to stay busy.\"),\n",
" summary(\"Event: They discuss Elon Musk and agree that he can be a polarizing personality.\"),\n",
" summary(\n",
" \"Event: Camille says hi to JaneBot and they reply that they are working and trying to stay busy.\"\n",
" ),\n",
" summary(\n",
" \"Event: They discuss Elon Musk and agree that he can be a polarizing personality.\"\n",
" ),\n",
" *example_chat[9:17],\n",
" summary(\"Event: Camille appreciates JaneBot's sense of humor.\"),\n",
" *example_chat[21:23],\n",
" summary('Event: Camille asks JaneBot to play \"What number I am thinking of?\" game but she keeps saying \"no\" to all guesses which JaneBot finds really funny.'),\n",
" summary(\n",
" 'Event: Camille asks JaneBot to play \"What number I am thinking of?\" game but she keeps saying \"no\" to all guesses which JaneBot finds really funny.'\n",
" ),\n",
" example_chat[33],\n",
" summary(\"\"\"Event: JaneBot wrote an essay about Camille. Summary of the essay:\n",
"1. You have a great sense of humor and enjoy playful, lighthearted banter in conversations.\n",
"2. Your creativity is evident in how you approach topics in unexpected ways and keep conversations interesting.\n",
"3. Chatting with you is enjoyable due to the casual, friendly tone you bring to interactions.\"\"\")\n",
"3. Chatting with you is enjoyable due to the casual, friendly tone you bring to interactions.\"\"\"),\n",
"]"
]
},
Expand Down Expand Up @@ -423,7 +435,8 @@
"source": [
"# Load test chat from json file\n",
"import json\n",
"with open(\"./test-chat.json\", 'r') as f:\n",
"\n",
"with open(\"./test-chat.json\", \"r\") as f:\n",
" chat_session = json.load(f)"
]
},
Expand All @@ -444,19 +457,18 @@
"metadata": {},
"outputs": [],
"source": [
"def get_leaf_nodes(chat_session=chat_session, chat_summaries=chat_summaries, session_summary_map=session_summary_map):\n",
"def get_leaf_nodes(\n",
" chat_session=chat_session,\n",
" chat_summaries=chat_summaries,\n",
" session_summary_map=session_summary_map,\n",
"):\n",
" all_messages = [*chat_session, *chat_summaries]\n",
"\n",
" # Collect non-leaf nodes\n",
" non_leaf_nodes = [\n",
" source[idx]\n",
" for (source, idx), _ in session_summary_map\n",
" ]\n",
" \n",
" non_leaf_nodes = [source[idx] for (source, idx), _ in session_summary_map]\n",
"\n",
" # Remove non-leaf nodes\n",
" remaining = [\n",
" msg for msg in all_messages if msg not in non_leaf_nodes\n",
" ]\n",
" remaining = [msg for msg in all_messages if msg not in non_leaf_nodes]\n",
"\n",
" return remaining"
]
Expand Down Expand Up @@ -501,16 +513,17 @@
"from pprint import pprint\n",
"import time\n",
"\n",
"\n",
"def compactify(chat_session=chat_session):\n",
" start = time.time()\n",
" pprint(start)\n",
" \n",
"\n",
" _sys_msg, *history_to_compact = get_leaf_nodes(chat_session=chat_session)\n",
"\n",
" history_to_compact = [\n",
" {\"index\": i+1, **msg} for i, msg in enumerate(history_to_compact)\n",
" {\"index\": i + 1, **msg} for i, msg in enumerate(history_to_compact)\n",
" ]\n",
" \n",
"\n",
" system_prompt = f\"\"\"\\\n",
"You are given a session history of a chat between a user and a gpt-4-turbo language model created through the\n",
"openai api.\n",
Expand Down Expand Up @@ -552,8 +565,8 @@
"\n",
" pprint(time.time() - start)\n",
" print(\"Starting CoT generation\")\n",
" cot_result = generate(messages, model=\"gpt-4-turbo\", stop=['</ct'], temperature=0.7)\n",
" \n",
" cot_result = generate(messages, model=\"gpt-4-turbo\", stop=[\"</ct\"], temperature=0.7)\n",
"\n",
" cot_result = make_chatml(**cot_result)\n",
" pprint(cot_result)\n",
"\n",
Expand All @@ -569,16 +582,15 @@
"\"\"\".strip()\n",
"\n",
" messages.append(user(start_message))\n",
" \n",
"\n",
" pprint(time.time() - start)\n",
" print(\"Starting chatml generation\")\n",
"\n",
" result = generate(messages, model=\"gpt-4-turbo\", temperature=0.1, stop=['</ct'])\n",
" result = generate(messages, model=\"gpt-4-turbo\", temperature=0.1, stop=[\"</ct\"])\n",
"\n",
" print(\"End chatml generation\")\n",
" pprint(time.time() - start)\n",
"\n",
" \n",
" return make_chatml(**result)"
]
},
Expand Down

0 comments on commit 990ea1a

Please sign in to comment.