Skip to content

Commit 9d7d872

Browse files
committed
python libraries
1 parent d36fb59 commit 9d7d872

10 files changed

Lines changed: 168 additions & 22 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Testing out a basic OpenFloorAgent"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"#add ../src to the path ready for python to find it\n",
17+
"import sys\n",
18+
"import os\n",
19+
"\n",
20+
"# Add the src directory to the Python path\n",
21+
"sys.path.append(os.path.abspath(os.path.join('..', 'src')))"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 2,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"#%pip install events"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 3,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"name": "stdout",
40+
"output_type": "stream",
41+
"text": [
42+
"registered handlers: 8\n",
43+
"Entering bot_on_envelope\n",
44+
"self._active_conversation: None\n",
45+
"in_envelope.conversation.id: conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\n",
46+
"Processing event: {\"eventType\": \"invite\", \"to\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\"}}\n",
47+
"Processing event with type: invite\n",
48+
"Entering bot_on_invite\n",
49+
"Entering bot_on_grant_floor\n",
50+
"out_envelope: {\"schema\": {\"version\": \"1.0.0\"}, \"conversation\": {\"id\": \"conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\", \"conversants\": [{\"identification\": {\"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"serviceUrl\": \"https://userproxy.com\", \"conversationalName\": \"John Doe\", \"role\": \"User\"}}]}, \"sender\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\"}, \"events\": []}\n",
51+
"Entering bot_on_envelope\n",
52+
"self._active_conversation: Conversation(id='conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64', conversants=[])\n",
53+
"in_envelope.conversation.id: conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\n",
54+
"Processing event: {\"eventType\": \"utterance\", \"to\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"private\": true}, \"parameters\": {\"dialogEvent\": {\"id\": \"de:ac725b50-ff80-465a-a966-ee0de38b4a99\", \"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"span\": {\"startTime\": \"2025-05-12T13:54:08.781524\"}, \"features\": {\"text\": {\"mimeType\": \"text/plain\", \"tokens\": [{\"value\": \"Give me the times to Vancouver!\"}]}}}}}\n",
55+
"Processing event with type: utterance\n",
56+
"Entering bot_on_utterance\n",
57+
"out_envelope: {\"schema\": {\"version\": \"1.0.0\"}, \"conversation\": {\"id\": \"conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\", \"conversants\": [{\"identification\": {\"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"serviceUrl\": \"https://userproxy.com\", \"conversationalName\": \"John Doe\", \"role\": \"User\"}}, {\"identification\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\", \"organization\": \"Travelbot Inc.\", \"conversationalName\": \"travelbot\", \"department\": \"Reservations and Customer Service\", \"role\": \"Reservation Specialist\", \"synopsis\": \"Reservation specialist as part of the Travelbot system.\"}}]}, \"sender\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\"}, \"events\": [{\"eventType\": \"utterance\", \"parameters\": {\"dialogEvent\": {\"id\": \"de:36cb6a90-96ba-4aad-a7eb-d0ab9f0c7976\", \"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"span\": {\"startTime\": \"2025-05-12T15:28:37.352479\"}, \"features\": {\"text\": {\"mimeType\": \"text/plain\", \"tokens\": [{\"value\": \"Sorry! I'm a simple bot that has not been programmed to do anything yet.\"}]}}}}}]}\n"
58+
]
59+
}
60+
],
61+
"source": [
62+
"from openfloor import BotAgent, Manifest, Identification, Envelope\n",
63+
"\n",
64+
"user_manifest = Manifest(\n",
65+
" Identification(\n",
66+
" conversationalName=\"John Doe\",\n",
67+
" speakerUri=\"tag:userproxy.com,2025:abc123\", \n",
68+
" serviceUrl=\"https://userproxy.com\",\n",
69+
" role=\"User\"\n",
70+
" )\n",
71+
")\n",
72+
"\n",
73+
"bot_manifest=Manifest.from_file(\"../sample_json/manifest1.json\")\n",
74+
"myagent=BotAgent(manifest=bot_manifest)\n",
75+
"\n",
76+
"input_envelopes = [\n",
77+
" Envelope.from_file(\"../sample_json/envelope1.json\",as_payload=True),\n",
78+
" Envelope.from_file(\"../sample_json/envelope2.json\",as_payload=True)\n",
79+
"]\n",
80+
"\n",
81+
"for n in range(len(input_envelopes)):\n",
82+
" out_envelope = myagent.process_envelope(input_envelopes[n])\n",
83+
" out_envelope.to_file(f\"../sample_json/out_envelope{n}.json\",as_payload=True,indent=2) \n"
84+
]
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.12.7"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 2
108+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
4+
#add ../src to the path ready for python to find it
5+
import sys
6+
import os
7+
8+
# Add the src directory to the Python path
9+
sys.path.append(os.path.abspath(os.path.join('..', 'src')))
10+
11+
12+
#%pip install events
13+
14+
15+
from openfloor import BotAgent, Manifest, Identification, Envelope
16+
17+
user_manifest = Manifest(
18+
Identification(
19+
conversationalName="John Doe",
20+
speakerUri="tag:userproxy.com,2025:abc123",
21+
serviceUrl="https://userproxy.com",
22+
role="User"
23+
)
24+
)
25+
26+
bot_manifest=Manifest.from_file("../sample_json/manifest1.json")
27+
myagent=BotAgent(manifest=bot_manifest)
28+
29+
input_envelopes = [
30+
Envelope.from_file("../sample_json/envelope1.json",as_payload=True),
31+
Envelope.from_file("../sample_json/envelope2.json",as_payload=True)
32+
]
33+
34+
for n in range(len(input_envelopes)):
35+
out_envelope = myagent.process_envelope(input_envelopes[n])
36+
out_envelope.to_file(f"../sample_json/out_envelope{n}.json",as_payload=True,indent=2)
37+
38+
39+
40+

python/notepads/Agent.ipynb

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,16 @@
3636
"metadata": {},
3737
"outputs": [
3838
{
39-
"name": "stdout",
40-
"output_type": "stream",
41-
"text": [
42-
"registered handlers: 8\n",
43-
"Entering bot_on_envelope\n",
44-
"self._active_conversation: None\n",
45-
"in_envelope.conversation.id: conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\n",
46-
"Processing event: {\"eventType\": \"invite\", \"to\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\"}}\n",
47-
"Processing event with type: invite\n",
48-
"Entering bot_on_invite\n",
49-
"Entering bot_on_grant_floor\n",
50-
"out_envelope: {\"schema\": {\"version\": \"1.0.0\"}, \"conversation\": {\"id\": \"conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\", \"conversants\": [{\"identification\": {\"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"serviceUrl\": \"https://userproxy.com\", \"conversationalName\": \"John Doe\", \"role\": \"User\"}}]}, \"sender\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\"}, \"events\": []}\n",
51-
"Entering bot_on_envelope\n",
52-
"self._active_conversation: Conversation(id='conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64', conversants=[])\n",
53-
"in_envelope.conversation.id: conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\n",
54-
"Processing event: {\"eventType\": \"utterance\", \"to\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"private\": true}, \"parameters\": {\"dialogEvent\": {\"id\": \"de:ac725b50-ff80-465a-a966-ee0de38b4a99\", \"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"span\": {\"startTime\": \"2025-05-12T13:54:08.781524\"}, \"features\": {\"text\": {\"mimeType\": \"text/plain\", \"tokens\": [{\"value\": \"Give me the times to Vancouver!\"}]}}}}}\n",
55-
"Processing event with type: utterance\n",
56-
"Entering bot_on_utterance\n",
57-
"out_envelope: {\"schema\": {\"version\": \"1.0.0\"}, \"conversation\": {\"id\": \"conv:558a5160-5937-4ca0-9b5e-4ee8f3e93a64\", \"conversants\": [{\"identification\": {\"speakerUri\": \"tag:userproxy.com,2025:abc123\", \"serviceUrl\": \"https://userproxy.com\", \"conversationalName\": \"John Doe\", \"role\": \"User\"}}, {\"identification\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\", \"organization\": \"Travelbot Inc.\", \"conversationalName\": \"travelbot\", \"department\": \"Reservations and Customer Service\", \"role\": \"Reservation Specialist\", \"synopsis\": \"Reservation specialist as part of the Travelbot system.\"}}]}, \"sender\": {\"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"serviceUrl\": \"https://dev.travelbot.ee/openfloor/conversation\"}, \"events\": [{\"eventType\": \"utterance\", \"parameters\": {\"dialogEvent\": {\"id\": \"de:36cb6a90-96ba-4aad-a7eb-d0ab9f0c7976\", \"speakerUri\": \"tag:dev.travelbot,2025:0001\", \"span\": {\"startTime\": \"2025-05-12T15:28:37.352479\"}, \"features\": {\"text\": {\"mimeType\": \"text/plain\", \"tokens\": [{\"value\": \"Sorry! I'm a simple bot that has not been programmed to do anything yet.\"}]}}}}}]}\n"
39+
"ename": "ModuleNotFoundError",
40+
"evalue": "No module named 'events'",
41+
"output_type": "error",
42+
"traceback": [
43+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
44+
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
45+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mopenfloor\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m BotAgent, Manifest, Identification, Envelope\n\u001b[32m 3\u001b[39m user_manifest = Manifest(\n\u001b[32m 4\u001b[39m Identification(\n\u001b[32m 5\u001b[39m conversationalName=\u001b[33m\"\u001b[39m\u001b[33mJohn Doe\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 9\u001b[39m )\n\u001b[32m 10\u001b[39m )\n\u001b[32m 12\u001b[39m bot_manifest=Manifest.from_file(\u001b[33m\"\u001b[39m\u001b[33m../sample_json/manifest1.json\u001b[39m\u001b[33m\"\u001b[39m)\n",
46+
"\u001b[36mFile \u001b[39m\u001b[32m~\\OneDrive\\Open Voice Network\\GitHub\\openfloor\\python\\src\\openfloor\\__init__.py:6\u001b[39m\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m *\n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mjson_serializable\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m *\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01magent\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m *\n\u001b[32m 7\u001b[39m __all__ = [\n\u001b[32m 8\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mDialogEvent\u001b[39m\u001b[33m\"\u001b[39m, \n\u001b[32m 9\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mDialogHistory\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 36\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mBotAgent\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 37\u001b[39m ]\n",
47+
"\u001b[36mFile \u001b[39m\u001b[32m~\\OneDrive\\Open Voice Network\\GitHub\\openfloor\\python\\src\\openfloor\\agent.py:2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtyping\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Optional, List, Tuple, Dict\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mevents\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mevents_module\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mabc\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m ABC, abstractmethod\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mopenfloor\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Parameters, DialogEvent, TextFeature, To, Sender, Manifest, Conversation, Envelope, Event, InviteEvent, UtteranceEvent, ContextEvent, UninviteEvent, DeclineInviteEvent, ByeEvent, GetManifestsEvent, PublishManifestsEvent, RequestFloorEvent, GrantFloorEvent, RevokeFloorEvent\n",
48+
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'events'"
5849
]
5950
}
6051
],
@@ -82,11 +73,18 @@
8273
" out_envelope = myagent.process_envelope(input_envelopes[n])\n",
8374
" out_envelope.to_file(f\"../sample_json/out_envelope{n}.json\",as_payload=True,indent=2) \n"
8475
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {},
81+
"outputs": [],
82+
"source": []
8583
}
8684
],
8785
"metadata": {
8886
"kernelspec": {
89-
"display_name": "Python 3",
87+
"display_name": "Python 3 (ipykernel)",
9088
"language": "python",
9189
"name": "python3"
9290
},
@@ -100,9 +98,9 @@
10098
"name": "python",
10199
"nbconvert_exporter": "python",
102100
"pygments_lexer": "ipython3",
103-
"version": "3.12.7"
101+
"version": "3.11.4"
104102
}
105103
},
106104
"nbformat": 4,
107-
"nbformat_minor": 2
105+
"nbformat_minor": 4
108106
}
784 Bytes
Binary file not shown.
12.6 KB
Binary file not shown.
18.2 KB
Binary file not shown.
16.2 KB
Binary file not shown.
7.9 KB
Binary file not shown.
Binary file not shown.
7.39 KB
Binary file not shown.

0 commit comments

Comments
 (0)