Skip to content

Commit 00de987

Browse files
jameszyaoSimsonW
authored andcommitted
chore: update examples and readme
1 parent 6a64d6a commit 00de987

File tree

5 files changed

+138
-105
lines changed

5 files changed

+138
-105
lines changed

README.md

+87-44
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,172 @@
11
# TaskingAI-client
22

3-
The TaskingAI Python client for creating and managing AI-driven applications.
3+
The official TaskingAI Python client.
44

55
For more information, see the docs at [TaskingAI Documentation](https://docs.tasking.ai/)
66

7+
## Prerequisites
8+
9+
The TaskingAI client is compatible with Python 3.8 and above.
10+
711
## Installation
812

9-
Install the latest released version using pip:
13+
Use `pip` to install the TaskingAI Python client.
14+
15+
```shell
16+
# Install the latest version
17+
pip install taskingai
18+
19+
# Install a specific version
20+
pip install taskingai==0.2.2
21+
```
22+
23+
## Usage
24+
25+
### Initialization
26+
27+
Before you can use the TaskingAI SDK, you must have your TaskingAI project set up and running. For community version, visit [TaskingAI Community](https://www.github.com/taskingai/taskingai) to get started. For cloud version, visit [TaskingAI Cloud](https://www.tasking.ai) to sign up first.
28+
29+
You need to initialize the TaskingAI Python client with an API key you obtain from the TaskingAI console. You can set the API key as an environment variable or pass it directly to the `init` function.
30+
31+
#### Using environment variables (Recommended)
32+
33+
Set it as an environment variable on your local system, and the SDK will automatically load the key without passing the `api_key` parameter in the `init` function.
1034

1135
```shell
12-
pip3 install taskingai
36+
export TASKINGAI_API_KEY=$YOUR_API_KEY
37+
```
38+
39+
When you run your Python script, the SDK will automatically pick up the API key from the environment variable.
40+
41+
```python
42+
import taskingai
43+
# taskingai.init()
44+
# No need to initialize the SDK with the API key
45+
```
46+
47+
#### Passing the API key directly
48+
49+
You can also specify an API key to the SDK by passing it as a parameter to the init function:
50+
51+
```python
52+
import taskingai
53+
taskingai.init(api_key="YOUR_API_KEY")
1354
```
1455

15-
## Quickstart
56+
If you use community version, you can set the base URL to the TaskingAI server by passing it to the `init` function:
1657

17-
Here's how you can quickly start building and managing AI-driven applications using the TaskingAI client.
58+
```python
59+
import taskingai
60+
taskingai.init(api_key="YOUR_API_KEY", host="http://localhost:8080")
61+
```
1862

1963
### Assistants
2064

21-
Explore the ease of creating and customizing your own AI assistants with TaskingAI to enhance user interactions.
65+
The Assistant system in TaskingAI represents a sophisticated framework designed to create and manage AI agents with customizable functionalities.
66+
67+
Here is an example of how to create, update, and delete an assistant:
2268

2369
```python
2470
import taskingai
25-
from taskingai.assistant import *
26-
from taskingai.assistant.memory import AssistantNaiveMemory
2771

2872
# Initialize your API key if you haven't already set it in the environment
2973
taskingai.init(api_key="YOUR_API_KEY")
3074

3175
# Create an assistant
32-
assistant = create_assistant(
76+
asst = taskingai.assistant.create_assistant(
3377
model_id="YOUR_MODEL_ID",
34-
memory=AssistantNaiveMemory(),
78+
memory={"type": "naive"},
3579
system_prompt_template=["You are a professional assistant."],
3680
)
37-
print(f"Assistant created: {assistant.id}")
81+
print(f"Assistant created: {asst.assistant_id}")
3882

3983
# Get details about the assistant
40-
assistant_details = get_assistant(assistant_id=assistant.id)
84+
assistant_details = taskingai.assistant.get_assistant(assistant_id=asst.assistant_id)
4185
print(f"Assistant details: {assistant_details}")
4286

4387
# Update the assistant's description
44-
update_assistant(
45-
assistant_id=assistant.id,
46-
description="An updated description for my assistant."
88+
taskingai.assistant.update_assistant(
89+
assistant_id=asst.assistant_id,
90+
description="Updated description"
4791
)
4892
print(f"Assistant updated.")
4993

5094
# Delete the assistant when done
51-
delete_assistant(assistant_id=assistant.id)
95+
taskingai.assistant.delete_assistant(assistant_id=asst.assistant_id)
5296
print("Assistant deleted successfully.")
5397
```
5498

5599
### Retrieval
56100

57-
Leverage TaskingAI's retrieval capabilities to store, manage, and extract information, making your applications smarter and more responsive.
101+
TaskingAI offers comprehensive tools for the retrieval system, ranging from straightforward to intricate setups. Here is an example of how to create, add, retrieve, and delete a record in a collection:
58102

59103
```python
60104
import taskingai
61-
from taskingai.retrieval import *
62105

63106
# Create a collection for storing and retrieving data
64-
collection = create_collection(
65-
embedding_model_id="YOUR_MODEL_ID",
107+
coll = taskingai.retrieval.create_collection(
108+
embedding_model_id="YOUR_EMBEDDING_MODEL_ID",
66109
capacity=1000
67110
)
68-
print(f"Collection created: {collection.id}")
111+
print(f"Collection created: {coll.collection_id}")
69112

70113
# Add a record to the collection
71-
record = create_record(
72-
collection_id=collection.id,
73-
content="Example text for machine learning.",
74-
text_splitter=TokenTextSplitter(chunk_size=200, chunk_overlap=20),
114+
record = taskingai.retrieval.create_record(
115+
collection_id=coll.collection_id,
116+
type="text",
117+
content="Machine learning is ...",
118+
text_splitter={"type": "token", "chunk_size": 200, "chunk_overlap": 20}
75119
)
76-
print(f"Record added to collection: {record.id}")
120+
print(f"Record added to collection: {record.record_id}")
77121

78122
# Retrieve the record from the collection
79-
retrieved_record = get_record(
80-
collection_id=collection.id,
81-
record_id=record.id
123+
retrieved_record = taskingai.retrieval.get_record(
124+
collection_id=coll.collection_id,
125+
record_id=record.record_id
82126
)
83-
print(f"Record retrieved: {retrieved_record.text}")
127+
print(f"Record retrieved: {retrieved_record.content}")
84128

85129
# Delete the record
86-
delete_record(
87-
collection_id=collection.id,
88-
record_id=record.id
130+
taskingai.retrieval.delete_record(
131+
collection_id=coll.collection_id,
132+
record_id=record.record_id
89133
)
90134
print("Record deleted.")
91135

92136
# Delete the collection
93-
delete_collection(collection_id=collection.id)
137+
taskingai.retrieval.delete_collection(collection_id=coll.collection_id)
94138
print("Collection deleted.")
95139
```
96140

97141
### Tools
98142

99-
Utilize TaskingAI's tools to create actions that enable your assistant to interact with external APIs and services, enriching the user experience.
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:
100144

101145
```python
102146
import taskingai
103-
from taskingai.tool import *
104147

105148
# Define a schema for the tool action
106-
NUMBERS_API_SCHEMA = {
149+
OPENAPI_SCHEMA = {
107150
# Schema definition goes here
108151
}
109152

110153
# Create a tool action based on the defined schema
111-
actions = bulk_create_actions(
112-
openapi_schema=NUMBERS_API_SCHEMA,
113-
authentication=ActionAuthentication(type=ActionAuthenticationType.NONE)
154+
actions = taskingai.tool.bulk_create_actions(
155+
openapi_schema=OPENAPI_SCHEMA,
156+
authentication={"type": "none"},
114157
)
115158
action = actions[0]
116-
print(f"Action created: {action.id}")
159+
print(f"Action created: {action.action_id}")
117160

118161
# Run the action for a test purpose
119-
result = run_action(
120-
action_id=action.id,
162+
result = taskingai.tool.run_action(
163+
action_id=action.action_id,
121164
parameters={"number": 42}
122165
)
123166
print(f"Action result: {result}")
124167

125168
# Delete the action when done
126-
delete_action(action_id=action.id)
169+
taskingai.tool.delete_action(action_id=action.action_id)
127170
print("Action deleted.")
128171
```
129172

examples/assistant/chat_with_assistant.ipynb

+1-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"from taskingai.assistant.memory import AssistantMessageWindowMemory\n",
112112
"\n",
113113
"# choose an available chat_completion model from your project\n",
114-
"model_id = \"YOUR_MODEL_ID\"\n",
114+
"model_id = \"YOUR_CHAT_COMPLETION_MODEL_ID\"\n",
115115
"\n",
116116
"assistant: Assistant = taskingai.assistant.create_assistant(\n",
117117
" model_id=model_id,\n",
@@ -129,10 +129,6 @@
129129
" ToolRef(\n",
130130
" type=ToolType.ACTION,\n",
131131
" id=action.action_id,\n",
132-
" ), \n",
133-
" ToolRef(\n",
134-
" type=ToolType.ACTION,\n",
135-
" id=action.action_id,\n",
136132
" )\n",
137133
" ],\n",
138134
" retrievals=[],\n",

examples/crud/assistant_crud.ipynb

+30-34
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
28-
"from taskingai.assistant import Assistant, Chat\n",
29-
"from taskingai.assistant.memory import AssistantNaiveMemory\n",
30-
"\n",
3128
"# choose an available chat_completion model from your project\n",
32-
"model_id = \"YOUR_MODEL_ID\""
29+
"model_id = \"YOUR_CHAT_COMPLETION_MODEL_ID\""
3330
]
3431
},
3532
{
@@ -47,24 +44,27 @@
4744
"metadata": {},
4845
"outputs": [],
4946
"source": [
50-
"from taskingai.assistant import RetrievalConfig, RetrievalMethod\n",
51-
"\n",
5247
"# create an assistant\n",
53-
"def create_assistant() -> Assistant:\n",
54-
" assistant: Assistant = taskingai.assistant.create_assistant(\n",
48+
"def create_assistant():\n",
49+
" assistant = taskingai.assistant.create_assistant(\n",
5550
" model_id=model_id,\n",
5651
" name=\"Customer Service Assistant\",\n",
5752
" description=\"A professional assistant for customer service.\",\n",
5853
" system_prompt_template=[\"You are a professional customer service assistant speaking {{language}}.\"],\n",
59-
" memory=AssistantNaiveMemory(),\n",
54+
" memory={\"type\": \"naive\",},\n",
6055
" tools=[],\n",
6156
" retrievals=[],\n",
62-
" retrieval_configs=RetrievalConfig(top_k=3, max_tokens=4096, method=RetrievalMethod.USER_MESSAGE),\n",
57+
" retrieval_configs={\n",
58+
" \"top_k\": 3, \n",
59+
" \"max_tokens\": 4096,\n",
60+
" \"method\": \"user_message\"\n",
61+
" },\n",
6362
" metadata={\"foo\": \"bar\"},\n",
6463
" )\n",
6564
" return assistant\n",
6665
"\n",
67-
"assistant: Assistant = create_assistant()\n",
66+
"assistant = create_assistant()\n",
67+
"assistant_id: str = assistant.assistant_id\n",
6868
"print(f\"created assistant: {assistant}\\n\")"
6969
]
7070
},
@@ -77,11 +77,7 @@
7777
"outputs": [],
7878
"source": [
7979
"# get assistant\n",
80-
"assistant_id: str = assistant.assistant_id\n",
81-
"assistant: Assistant = taskingai.assistant.get_assistant(\n",
82-
" assistant_id=assistant_id\n",
83-
")\n",
84-
"\n",
80+
"assistant = taskingai.assistant.get_assistant(assistant_id)\n",
8581
"print(f\"got assistant: {assistant}\\n\")"
8682
]
8783
},
@@ -94,13 +90,16 @@
9490
"outputs": [],
9591
"source": [
9692
"# update assistant\n",
97-
"assistant: Assistant = taskingai.assistant.update_assistant(\n",
93+
"assistant = taskingai.assistant.update_assistant(\n",
9894
" assistant_id=assistant_id,\n",
99-
" name=\"New Assistant\",\n",
100-
" retrieval_configs=RetrievalConfig(top_k=4, max_tokens=8192, method=RetrievalMethod.USER_MESSAGE),\n",
95+
" name=\"New Assistant Name\",\n",
96+
" retrieval_configs={\n",
97+
" \"top_k\": 5, \n",
98+
" \"max_tokens\": 2048,\n",
99+
" \"method\": \"user_message\"\n",
100+
" },\n",
101101
")\n",
102-
"\n",
103-
"print(f\"updated assistant: {assistant}\\n\")\n"
102+
"print(f\"updated assistant: {assistant}\\n\")"
104103
]
105104
},
106105
{
@@ -112,7 +111,7 @@
112111
"outputs": [],
113112
"source": [
114113
"# delete assistant\n",
115-
"taskingai.assistant.delete_assistant(assistant_id=assistant_id)\n",
114+
"taskingai.assistant.delete_assistant(assistant_id)\n",
116115
"print(f\"deleted assistant: {assistant_id}\\n\")"
117116
]
118117
},
@@ -149,10 +148,10 @@
149148
"outputs": [],
150149
"source": [
151150
"# create a new assistant\n",
152-
"assistant: Assistant = create_assistant()\n",
151+
"assistant = create_assistant()\n",
153152
"\n",
154153
"# create a chat\n",
155-
"chat: Chat = taskingai.assistant.create_chat(\n",
154+
"chat = taskingai.assistant.create_chat(\n",
156155
" assistant_id=assistant.assistant_id,\n",
157156
")\n",
158157
"print(f\"created chat: {chat.chat_id} for assistant: {assistant.assistant_id}\\n\")"
@@ -168,7 +167,7 @@
168167
"source": [
169168
"# get chat\n",
170169
"chat_id: str = chat.chat_id\n",
171-
"chat: Chat = taskingai.assistant.get_chat(\n",
170+
"chat = taskingai.assistant.get_chat(\n",
172171
" assistant_id=assistant.assistant_id,\n",
173172
" chat_id=chat_id,\n",
174173
")\n",
@@ -184,7 +183,7 @@
184183
"outputs": [],
185184
"source": [
186185
"# update chat\n",
187-
"chat: Chat = taskingai.assistant.update_chat(\n",
186+
"chat = taskingai.assistant.update_chat(\n",
188187
" assistant_id=assistant.assistant_id,\n",
189188
" chat_id=chat_id,\n",
190189
" name=\"New Chat\",\n",
@@ -217,15 +216,12 @@
217216
},
218217
"outputs": [],
219218
"source": [
220-
"# list chats \n",
219+
"# create chats \n",
221220
"for _ in range(3):\n",
222-
" taskingai.assistant.create_chat(\n",
223-
" assistant_id=assistant.assistant_id,\n",
224-
" )\n",
221+
" taskingai.assistant.create_chat(assistant.assistant_id)\n",
225222
"\n",
226-
"chats = taskingai.assistant.list_chats(\n",
227-
" assistant_id=assistant.assistant_id,\n",
228-
")\n",
223+
"# list chats\n",
224+
"chats = taskingai.assistant.list_chats(assistant.assistant_id)\n",
229225
"print(f\"num chats = {len(chats)}\\n\")"
230226
]
231227
},
@@ -238,7 +234,7 @@
238234
"outputs": [],
239235
"source": [
240236
"# delete assistant\n",
241-
"taskingai.assistant.delete_assistant(assistant_id=assistant.assistant_id)"
237+
"taskingai.assistant.delete_assistant(assistant.assistant_id)"
242238
]
243239
}
244240
],

0 commit comments

Comments
 (0)