Skip to content

Commit 563da8a

Browse files
Dttbdjameszyao
authored andcommitted
feat: update retrieval and assistant
1 parent d0d957d commit 563da8a

File tree

76 files changed

+952
-3747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searcx below for content that may be hidden.

76 files changed

+952
-3747
lines changed

‎README.md

-32
Original file line numberDiff line numberDiff line change
@@ -138,38 +138,6 @@ taskingai.retrieval.delete_collection(collection_id=coll.collection_id)
138138
print("Collection deleted.")
139139
```
140140

141-
### Tools
142-
143-
The Tools module in TaskingAI is an essential suite designed to augment the capabilities of TaskingAI agents. Here is an example of how to create, run, and delete a tool action:
144-
145-
```python
146-
import taskingai
147-
148-
# Define a schema for the tool action
149-
OPENAPI_SCHEMA = {
150-
# Schema definition goes here
151-
}
152-
153-
# Create a tool action based on the defined schema
154-
actions = taskingai.tool.bulk_create_actions(
155-
openapi_schema=OPENAPI_SCHEMA,
156-
authentication={"type": "none"},
157-
)
158-
action = actions[0]
159-
print(f"Action created: {action.action_id}")
160-
161-
# Run the action for a test purpose
162-
result = taskingai.tool.run_action(
163-
action_id=action.action_id,
164-
parameters={"number": 42}
165-
)
166-
print(f"Action result: {result}")
167-
168-
# Delete the action when done
169-
taskingai.tool.delete_action(action_id=action.action_id)
170-
print("Action deleted.")
171-
```
172-
173141
## Contributing
174142

175143
We welcome contributions of all kinds. Please read our [Contributing Guidelines](./CONTRIBUTING.md) for more information on how to get started.

‎examples/assistant/chat_with_assistant.ipynb

+67-121
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,49 @@
22
"cells": [
33
{
44
"cell_type": "code",
5+
"execution_count": null,
56
"id": "initial_id",
67
"metadata": {
78
"collapsed": true
89
},
10+
"outputs": [],
911
"source": [
1012
"import time\n",
1113
"import taskingai\n",
1214
"# Load TaskingAI API Key from environment variable"
13-
],
14-
"outputs": [],
15-
"execution_count": null
15+
]
1616
},
1717
{
1818
"cell_type": "markdown",
19+
"id": "4ca20b4a868dedd8",
20+
"metadata": {
21+
"collapsed": false
22+
},
1923
"source": [
2024
"# TaskingAI: Chat with Assistant Example\n",
2125
"\n",
2226
"In this example, we will first create an assistant who knows the meaning of various numbers and will explain it in certain language.\n",
2327
"Then we will start a chat with the assistant."
24-
],
25-
"metadata": {
26-
"collapsed": false
27-
},
28-
"id": "4ca20b4a868dedd8"
28+
]
2929
},
3030
{
3131
"cell_type": "markdown",
32-
"source": [
33-
"## Create Assistant"
34-
],
32+
"id": "5e19ac923d84e898",
3533
"metadata": {
3634
"collapsed": false
3735
},
38-
"id": "5e19ac923d84e898"
36+
"source": [
37+
"## Create Assistant"
38+
]
3939
},
4040
{
4141
"cell_type": "code",
42-
"source": [
43-
"from taskingai.tool import Action, ActionAuthentication, ActionAuthenticationType\n",
44-
"from typing import List\n",
45-
"\n",
46-
"# create an assistant action\n",
47-
"NUMBERS_API_SCHEMA = {\n",
48-
" \"openapi\": \"3.0.0\",\n",
49-
" \"info\": {\n",
50-
" \"title\": \"Numbers API\",\n",
51-
" \"version\": \"1.0.0\",\n",
52-
" \"description\": \"API for fetching interesting number facts\"\n",
53-
" },\n",
54-
" \"servers\": [\n",
55-
" {\n",
56-
" \"url\": \"http://numbersapi.com\"\n",
57-
" }\n",
58-
" ],\n",
59-
" \"paths\": {\n",
60-
" \"/{number}\": {\n",
61-
" \"get\": {\n",
62-
" \"description\": \"Get a fact about a number\",\n",
63-
" \"operationId\": \"getNumberFact\",\n",
64-
" \"parameters\": [\n",
65-
" {\n",
66-
" \"name\": \"number\",\n",
67-
" \"in\": \"path\",\n",
68-
" \"required\": True,\n",
69-
" \"description\": \"The number to get the fact for\",\n",
70-
" \"schema\": {\n",
71-
" \"type\": \"integer\"\n",
72-
" }\n",
73-
" }\n",
74-
" ],\n",
75-
" \"responses\": {\n",
76-
" \"200\": {\n",
77-
" \"description\": \"A fact about the number\",\n",
78-
" \"content\": {\n",
79-
" \"text/plain\": {\n",
80-
" \"schema\": {\n",
81-
" \"type\": \"string\"\n",
82-
" }\n",
83-
" }\n",
84-
" }\n",
85-
" }\n",
86-
" }\n",
87-
" }\n",
88-
" }\n",
89-
" }\n",
90-
"}\n",
91-
"actions: List[Action] = taskingai.tool.bulk_create_actions(\n",
92-
" openapi_schema=NUMBERS_API_SCHEMA,\n",
93-
" authentication=ActionAuthentication(\n",
94-
" type=ActionAuthenticationType.NONE,\n",
95-
" )\n",
96-
")\n",
97-
"action = actions[0]\n",
98-
"print(f\"created action: {action}\\n\")"
99-
],
42+
"execution_count": null,
43+
"id": "3b3df0f232021283",
10044
"metadata": {
10145
"collapsed": false
10246
},
103-
"id": "3b2fda39ba58c5e9",
10447
"outputs": [],
105-
"execution_count": null
106-
},
107-
{
108-
"cell_type": "code",
10948
"source": [
11049
"from taskingai.assistant import Assistant, Chat, ToolRef, ToolType\n",
11150
"from taskingai.assistant.memory import AssistantMessageWindowMemory\n",
@@ -118,7 +57,6 @@
11857
" name=\"My Assistant\",\n",
11958
" description=\"A assistant who knows the meaning of various numbers.\",\n",
12059
" memory=AssistantMessageWindowMemory(\n",
121-
" max_messages=20,\n",
12260
" max_tokens=1000\n",
12361
" ),\n",
12462
" system_prompt_template=[\n",
@@ -127,49 +65,49 @@
12765
" ],\n",
12866
" tools=[\n",
12967
" ToolRef(\n",
130-
" type=ToolType.ACTION,\n",
131-
" id=action.action_id,\n",
68+
" type=ToolType.PLUGIN,\n",
69+
" id=\"open_weather/get_hourly_forecast\",\n",
13270
" )\n",
13371
" ],\n",
13472
" retrievals=[],\n",
13573
" metadata={\"k\": \"v\"},\n",
13674
")\n",
13775
"print(f\"created assistant: {assistant}\\n\")"
138-
],
139-
"metadata": {
140-
"collapsed": false
141-
},
142-
"id": "3b3df0f232021283",
143-
"outputs": [],
144-
"execution_count": null
76+
]
14577
},
14678
{
14779
"cell_type": "markdown",
148-
"source": [
149-
"## Start a Chat "
150-
],
80+
"id": "8e7c1b9461f0a344",
15181
"metadata": {
15282
"collapsed": false
15383
},
154-
"id": "8e7c1b9461f0a344"
84+
"source": [
85+
"## Start a Chat "
86+
]
15587
},
15688
{
15789
"cell_type": "code",
90+
"execution_count": null,
91+
"id": "f1e2f0b2af8b1d8d",
92+
"metadata": {
93+
"collapsed": false
94+
},
95+
"outputs": [],
15896
"source": [
15997
"chat: Chat = taskingai.assistant.create_chat(\n",
16098
" assistant_id=assistant.assistant_id,\n",
16199
")\n",
162100
"print(f\"created chat: {chat.chat_id}\\n\")"
163-
],
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"id": "b26e30b79b71697a",
164107
"metadata": {
165108
"collapsed": false
166109
},
167-
"id": "f1e2f0b2af8b1d8d",
168110
"outputs": [],
169-
"execution_count": null
170-
},
171-
{
172-
"cell_type": "code",
173111
"source": [
174112
"from taskingai.assistant import Message, MessageChunk\n",
175113
"user_input = input(\"User Input: \")\n",
@@ -181,7 +119,7 @@
181119
" text=user_input,\n",
182120
" )\n",
183121
" print(f\"User: {user_input}\")\n",
184-
" \n",
122+
"\n",
185123
" # generate assistant response\n",
186124
" assistant_message: Message = taskingai.assistant.generate_message(\n",
187125
" assistant_id=assistant.assistant_id,\n",
@@ -194,16 +132,16 @@
194132
" time.sleep(2)\n",
195133
" # quit by input 'q\n",
196134
" user_input = input(\"User: \")"
197-
],
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": null,
140+
"id": "c7d73e0b138e3eba",
198141
"metadata": {
199142
"collapsed": false
200143
},
201-
"id": "b26e30b79b71697a",
202144
"outputs": [],
203-
"execution_count": null
204-
},
205-
{
206-
"cell_type": "code",
207145
"source": [
208146
"user_input = input(\"User Input: \")\n",
209147
"while user_input.strip() and user_input != \"q\":\n",
@@ -214,7 +152,7 @@
214152
" text=user_input,\n",
215153
" )\n",
216154
" print(f\"User: {user_input} ({user_message.message_id})\")\n",
217-
" \n",
155+
"\n",
218156
" # generate assistant response\n",
219157
" assistant_message_response = taskingai.assistant.generate_message(\n",
220158
" assistant_id=assistant.assistant_id,\n",
@@ -224,27 +162,37 @@
224162
" },\n",
225163
" stream=True,\n",
226164
" )\n",
227-
" \n",
228-
" print(f\"Assistant:\", end=\" \", flush=True)\n",
165+
"\n",
166+
" print(\"Assistant:\", end=\" \", flush=True)\n",
229167
" for item in assistant_message_response:\n",
230168
" if isinstance(item, MessageChunk):\n",
231169
" print(item.delta, end=\"\", flush=True)\n",
232170
" elif isinstance(item, Message):\n",
233171
" print(f\" ({item.message_id})\")\n",
234-
" \n",
172+
"\n",
235173
" time.sleep(2)\n",
236174
" # quit by input 'q\n",
237175
" user_input = input(\"User: \")"
238-
],
239-
"metadata": {
240-
"collapsed": false
241-
},
242-
"id": "c7d73e0b138e3eba",
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "3a67261c",
182+
"metadata": {},
243183
"outputs": [],
244-
"execution_count": null
184+
"source": [
185+
"# clean chat context\n",
186+
"taskingai.assistant.clean_chat_context(\n",
187+
" assistant_id=assistant.assistant_id,\n",
188+
" chat_id=chat.chat_id,\n",
189+
")"
190+
]
245191
},
246192
{
247193
"cell_type": "code",
194+
"execution_count": null,
195+
"outputs": [],
248196
"source": [
249197
"# list messages\n",
250198
"messages = taskingai.assistant.list_messages(\n",
@@ -258,12 +206,12 @@
258206
"metadata": {
259207
"collapsed": false
260208
},
261-
"id": "e94e3adb0d15373b",
262-
"outputs": [],
263-
"execution_count": null
209+
"id": "e94e3adb0d15373b"
264210
},
265211
{
266212
"cell_type": "code",
213+
"execution_count": null,
214+
"outputs": [],
267215
"source": [
268216
"# delete assistant\n",
269217
"taskingai.assistant.delete_assistant(\n",
@@ -273,9 +221,7 @@
273221
"metadata": {
274222
"collapsed": false
275223
},
276-
"id": "ed39836bbfdc7a4e",
277-
"outputs": [],
278-
"execution_count": null
224+
"id": "ed39836bbfdc7a4e"
279225
}
280226
],
281227
"metadata": {
@@ -287,14 +233,14 @@
287233
"language_info": {
288234
"codemirror_mode": {
289235
"name": "ipython",
290-
"version": 2
236+
"version": 3
291237
},
292238
"file_extension": ".py",
293239
"mimetype": "text/x-python",
294240
"name": "python",
295241
"nbconvert_exporter": "python",
296-
"pygments_lexer": "ipython2",
297-
"version": "2.7.6"
242+
"pygments_lexer": "ipython3",
243+
"version": "3.10.14"
298244
}
299245
},
300246
"nbformat": 4,

0 commit comments

Comments
 (0)