|
1 | 1 | # TaskingAI-client
|
2 | 2 |
|
3 |
| -The TaskingAI Python client for creating and managing AI-driven applications. |
| 3 | +The official TaskingAI Python client. |
4 | 4 |
|
5 | 5 | For more information, see the docs at [TaskingAI Documentation](https://docs.tasking.ai/)
|
6 | 6 |
|
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +The TaskingAI client is compatible with Python 3.8 and above. |
| 10 | + |
7 | 11 | ## Installation
|
8 | 12 |
|
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. |
10 | 34 |
|
11 | 35 | ```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") |
13 | 54 | ```
|
14 | 55 |
|
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: |
16 | 57 |
|
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 | +``` |
18 | 62 |
|
19 | 63 | ### Assistants
|
20 | 64 |
|
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: |
22 | 68 |
|
23 | 69 | ```python
|
24 | 70 | import taskingai
|
25 |
| -from taskingai.assistant import * |
26 |
| -from taskingai.assistant.memory import AssistantNaiveMemory |
27 | 71 |
|
28 | 72 | # Initialize your API key if you haven't already set it in the environment
|
29 | 73 | taskingai.init(api_key="YOUR_API_KEY")
|
30 | 74 |
|
31 | 75 | # Create an assistant
|
32 |
| -assistant = create_assistant( |
| 76 | +asst = taskingai.assistant.create_assistant( |
33 | 77 | model_id="YOUR_MODEL_ID",
|
34 |
| - memory=AssistantNaiveMemory(), |
| 78 | + memory={"type": "naive"}, |
35 | 79 | system_prompt_template=["You are a professional assistant."],
|
36 | 80 | )
|
37 |
| -print(f"Assistant created: {assistant.id}") |
| 81 | +print(f"Assistant created: {asst.assistant_id}") |
38 | 82 |
|
39 | 83 | # 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) |
41 | 85 | print(f"Assistant details: {assistant_details}")
|
42 | 86 |
|
43 | 87 | # 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" |
47 | 91 | )
|
48 | 92 | print(f"Assistant updated.")
|
49 | 93 |
|
50 | 94 | # Delete the assistant when done
|
51 |
| -delete_assistant(assistant_id=assistant.id) |
| 95 | +taskingai.assistant.delete_assistant(assistant_id=asst.assistant_id) |
52 | 96 | print("Assistant deleted successfully.")
|
53 | 97 | ```
|
54 | 98 |
|
55 | 99 | ### Retrieval
|
56 | 100 |
|
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: |
58 | 102 |
|
59 | 103 | ```python
|
60 | 104 | import taskingai
|
61 |
| -from taskingai.retrieval import * |
62 | 105 |
|
63 | 106 | # 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", |
66 | 109 | capacity=1000
|
67 | 110 | )
|
68 |
| -print(f"Collection created: {collection.id}") |
| 111 | +print(f"Collection created: {coll.collection_id}") |
69 | 112 |
|
70 | 113 | # 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} |
75 | 119 | )
|
76 |
| -print(f"Record added to collection: {record.id}") |
| 120 | +print(f"Record added to collection: {record.record_id}") |
77 | 121 |
|
78 | 122 | # 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 |
82 | 126 | )
|
83 |
| -print(f"Record retrieved: {retrieved_record.text}") |
| 127 | +print(f"Record retrieved: {retrieved_record.content}") |
84 | 128 |
|
85 | 129 | # 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 |
89 | 133 | )
|
90 | 134 | print("Record deleted.")
|
91 | 135 |
|
92 | 136 | # Delete the collection
|
93 |
| -delete_collection(collection_id=collection.id) |
| 137 | +taskingai.retrieval.delete_collection(collection_id=coll.collection_id) |
94 | 138 | print("Collection deleted.")
|
95 | 139 | ```
|
96 | 140 |
|
97 | 141 | ### Tools
|
98 | 142 |
|
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: |
100 | 144 |
|
101 | 145 | ```python
|
102 | 146 | import taskingai
|
103 |
| -from taskingai.tool import * |
104 | 147 |
|
105 | 148 | # Define a schema for the tool action
|
106 |
| -NUMBERS_API_SCHEMA = { |
| 149 | +OPENAPI_SCHEMA = { |
107 | 150 | # Schema definition goes here
|
108 | 151 | }
|
109 | 152 |
|
110 | 153 | # 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"}, |
114 | 157 | )
|
115 | 158 | action = actions[0]
|
116 |
| -print(f"Action created: {action.id}") |
| 159 | +print(f"Action created: {action.action_id}") |
117 | 160 |
|
118 | 161 | # 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, |
121 | 164 | parameters={"number": 42}
|
122 | 165 | )
|
123 | 166 | print(f"Action result: {result}")
|
124 | 167 |
|
125 | 168 | # Delete the action when done
|
126 |
| -delete_action(action_id=action.id) |
| 169 | +taskingai.tool.delete_action(action_id=action.action_id) |
127 | 170 | print("Action deleted.")
|
128 | 171 | ```
|
129 | 172 |
|
|
0 commit comments