Skip to content

Commit 6143a4a

Browse files
committed
feat: update retrieval and assistant
1 parent d0d957d commit 6143a4a

Some content is hidden

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

72 files changed

+936
-3653
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

+70-123
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",
@@ -127,49 +66,49 @@
12766
" ],\n",
12867
" tools=[\n",
12968
" ToolRef(\n",
130-
" type=ToolType.ACTION,\n",
131-
" id=action.action_id,\n",
69+
" type=ToolType.PLUGIN,\n",
70+
" id=\"open_weather/get_hourly_forecast\",\n",
13271
" )\n",
13372
" ],\n",
13473
" retrievals=[],\n",
13574
" metadata={\"k\": \"v\"},\n",
13675
")\n",
13776
"print(f\"created assistant: {assistant}\\n\")"
138-
],
139-
"metadata": {
140-
"collapsed": false
141-
},
142-
"id": "3b3df0f232021283",
143-
"outputs": [],
144-
"execution_count": null
77+
]
14578
},
14679
{
14780
"cell_type": "markdown",
148-
"source": [
149-
"## Start a Chat "
150-
],
81+
"id": "8e7c1b9461f0a344",
15182
"metadata": {
15283
"collapsed": false
15384
},
154-
"id": "8e7c1b9461f0a344"
85+
"source": [
86+
"## Start a Chat "
87+
]
15588
},
15689
{
15790
"cell_type": "code",
91+
"execution_count": null,
92+
"id": "f1e2f0b2af8b1d8d",
93+
"metadata": {
94+
"collapsed": false
95+
},
96+
"outputs": [],
15897
"source": [
15998
"chat: Chat = taskingai.assistant.create_chat(\n",
16099
" assistant_id=assistant.assistant_id,\n",
161100
")\n",
162101
"print(f\"created chat: {chat.chat_id}\\n\")"
163-
],
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"id": "b26e30b79b71697a",
164108
"metadata": {
165109
"collapsed": false
166110
},
167-
"id": "f1e2f0b2af8b1d8d",
168111
"outputs": [],
169-
"execution_count": null
170-
},
171-
{
172-
"cell_type": "code",
173112
"source": [
174113
"from taskingai.assistant import Message, MessageChunk\n",
175114
"user_input = input(\"User Input: \")\n",
@@ -181,7 +120,7 @@
181120
" text=user_input,\n",
182121
" )\n",
183122
" print(f\"User: {user_input}\")\n",
184-
" \n",
123+
"\n",
185124
" # generate assistant response\n",
186125
" assistant_message: Message = taskingai.assistant.generate_message(\n",
187126
" assistant_id=assistant.assistant_id,\n",
@@ -194,16 +133,16 @@
194133
" time.sleep(2)\n",
195134
" # quit by input 'q\n",
196135
" user_input = input(\"User: \")"
197-
],
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"id": "c7d73e0b138e3eba",
198142
"metadata": {
199143
"collapsed": false
200144
},
201-
"id": "b26e30b79b71697a",
202145
"outputs": [],
203-
"execution_count": null
204-
},
205-
{
206-
"cell_type": "code",
207146
"source": [
208147
"user_input = input(\"User Input: \")\n",
209148
"while user_input.strip() and user_input != \"q\":\n",
@@ -214,7 +153,7 @@
214153
" text=user_input,\n",
215154
" )\n",
216155
" print(f\"User: {user_input} ({user_message.message_id})\")\n",
217-
" \n",
156+
"\n",
218157
" # generate assistant response\n",
219158
" assistant_message_response = taskingai.assistant.generate_message(\n",
220159
" assistant_id=assistant.assistant_id,\n",
@@ -224,27 +163,27 @@
224163
" },\n",
225164
" stream=True,\n",
226165
" )\n",
227-
" \n",
166+
"\n",
228167
" print(f\"Assistant:\", end=\" \", flush=True)\n",
229168
" for item in assistant_message_response:\n",
230169
" if isinstance(item, MessageChunk):\n",
231170
" print(item.delta, end=\"\", flush=True)\n",
232171
" elif isinstance(item, Message):\n",
233172
" print(f\" ({item.message_id})\")\n",
234-
" \n",
173+
"\n",
235174
" time.sleep(2)\n",
236175
" # quit by input 'q\n",
237176
" user_input = input(\"User: \")"
238-
],
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": null,
182+
"id": "e94e3adb0d15373b",
239183
"metadata": {
240184
"collapsed": false
241185
},
242-
"id": "c7d73e0b138e3eba",
243186
"outputs": [],
244-
"execution_count": null
245-
},
246-
{
247-
"cell_type": "code",
248187
"source": [
249188
"# list messages\n",
250189
"messages = taskingai.assistant.list_messages(\n",
@@ -254,28 +193,36 @@
254193
")\n",
255194
"for message in messages:\n",
256195
" print(f\"{message.role}: {message.content.text}\")"
257-
],
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"id": "ed39836bbfdc7a4e",
258202
"metadata": {
259203
"collapsed": false
260204
},
261-
"id": "e94e3adb0d15373b",
262205
"outputs": [],
263-
"execution_count": null
264-
},
265-
{
266-
"cell_type": "code",
267206
"source": [
268207
"# delete assistant\n",
269208
"taskingai.assistant.delete_assistant(\n",
270209
" assistant_id=assistant.assistant_id,\n",
271210
")"
272-
],
273-
"metadata": {
274-
"collapsed": false
275-
},
276-
"id": "ed39836bbfdc7a4e",
211+
]
212+
},
213+
{
214+
"cell_type": "code",
215+
"execution_count": null,
216+
"id": "3a67261c",
217+
"metadata": {},
277218
"outputs": [],
278-
"execution_count": null
219+
"source": [
220+
"# clean chat context\n",
221+
"taskingai.assistant.clean_chat_context(\n",
222+
" assistant_id=\"YOUR_ASSISTANT_ID\",\n",
223+
" chat_id=\"YOUR_CHAT_ID\",\n",
224+
")"
225+
]
279226
}
280227
],
281228
"metadata": {
@@ -294,7 +241,7 @@
294241
"name": "python",
295242
"nbconvert_exporter": "python",
296243
"pygments_lexer": "ipython2",
297-
"version": "2.7.6"
244+
"version": "3.10.14"
298245
}
299246
},
300247
"nbformat": 4,

examples/crud/assistant_crud.ipynb

+3-2
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,13 @@
240240
],
241241
"metadata": {
242242
"kernelspec": {
243-
"display_name": "Python 3 (ipykernel)",
243+
"display_name": "Python 3",
244244
"language": "python",
245245
"name": "python3"
246246
},
247247
"language_info": {
248-
"name": "python"
248+
"name": "python",
249+
"version": "3.10.14"
249250
}
250251
},
251252
"nbformat": 4,

0 commit comments

Comments
 (0)