|
| 1 | +--- |
| 2 | +title: Assistants <span style="font-weight:bold; margin-left:10px; color:red;">Beta</span> |
| 3 | +--- |
| 4 | + |
| 5 | +!!! Note |
| 6 | + |
| 7 | + Please build the client before calling, the build code is as follows: |
| 8 | + |
| 9 | + ```java |
| 10 | + OpenAiClient client = OpenAiClient.builder() |
| 11 | + .apiHost("https://api.openai.com") |
| 12 | + .apiKey(System.getProperty("openai.token")) |
| 13 | + .build(); |
| 14 | + ``` |
| 15 | + |
| 16 | + `System.getProperty("openai.token")` is the key to access the API authorization. |
| 17 | + |
| 18 | +### Create assistant |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +Create an assistant with a model and instructions. |
| 23 | + |
| 24 | +```java |
| 25 | +AssistantsEntity entity = AssistantsEntity.builder() |
| 26 | + .name("Math Tutor") |
| 27 | + .model(CompletionModel.GPT_35_TURBO) |
| 28 | + .instructions("You are a personal math tutor. When asked a question, write and run Python code to answer the question.") |
| 29 | + .build(); |
| 30 | +client. |
| 31 | + |
| 32 | +createAssistants(entity); |
| 33 | +``` |
| 34 | + |
| 35 | +Returns: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "id": "asst_abc123", |
| 40 | + "object": "assistant", |
| 41 | + "created_at": 1698984975, |
| 42 | + "name": "Math Tutor", |
| 43 | + "description": null, |
| 44 | + "model": "gpt-4", |
| 45 | + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", |
| 46 | + "tools": [ |
| 47 | + { |
| 48 | + "type": "code_interpreter" |
| 49 | + } |
| 50 | + ], |
| 51 | + "file_ids": [], |
| 52 | + "metadata": {} |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Create assistant file |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +Create an assistant file by attaching a File to an assistant. |
| 61 | + |
| 62 | +```java |
| 63 | +client.createAssistantsFile("file-jNuKdx61rNQ0FUhuPFpMNmGZ","asst_xv9N9dNXstuV8OVLElLqgV7U") |
| 64 | +``` |
| 65 | + |
| 66 | +Returns: |
| 67 | + |
| 68 | +```json |
| 69 | +{ |
| 70 | + "id": "file-abc123", |
| 71 | + "object": "assistant.file", |
| 72 | + "created_at": 1699055364, |
| 73 | + "assistant_id": "asst_abc123" |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### List assistants |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +Returns a list of assistants. |
| 82 | + |
| 83 | +```java |
| 84 | +client.listAssistants(null); |
| 85 | + |
| 86 | +// With query params |
| 87 | +QueryEntity configure = QueryEntity.builder() |
| 88 | + .limit(2) |
| 89 | + .build(); |
| 90 | +client. |
| 91 | + |
| 92 | +assistants(configure); |
| 93 | +``` |
| 94 | + |
| 95 | +Returns: |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "object": "list", |
| 100 | + "data": [ |
| 101 | + { |
| 102 | + "id": "asst_abc123", |
| 103 | + "object": "assistant", |
| 104 | + "created_at": 1698982736, |
| 105 | + "name": "Coding Tutor", |
| 106 | + "description": null, |
| 107 | + "model": "gpt-4", |
| 108 | + "instructions": "You are a helpful assistant designed to make me better at coding!", |
| 109 | + "tools": [], |
| 110 | + "file_ids": [], |
| 111 | + "metadata": {} |
| 112 | + } |
| 113 | + ], |
| 114 | + "first_id": "asst_abc123", |
| 115 | + "last_id": "asst_abc789", |
| 116 | + "has_more": false |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### List assistant files |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +Returns a list of assistant files. |
| 125 | + |
| 126 | +```java |
| 127 | +client.assistantsFiles("asst_xv9N9dNXstuV8OVLElLqgV7U")); |
| 128 | +``` |
| 129 | + |
| 130 | +Returns: |
| 131 | + |
| 132 | +```json |
| 133 | +{ |
| 134 | + "object": "list", |
| 135 | + "data": [ |
| 136 | + { |
| 137 | + "id": "file-abc123", |
| 138 | + "object": "assistant.file", |
| 139 | + "created_at": 1699060412, |
| 140 | + "assistant_id": "asst_abc123" |
| 141 | + } |
| 142 | + ], |
| 143 | + "first_id": "file-abc123", |
| 144 | + "last_id": "file-abc456", |
| 145 | + "has_more": false |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +### Retrieve assistant |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +Retrieves an assistant. |
| 154 | + |
| 155 | +```java |
| 156 | +client.retrieveAssistant("asst_xv9N9dNXstuV8OVLElLqgV7U"); |
| 157 | +``` |
| 158 | + |
| 159 | +Returns: |
| 160 | + |
| 161 | +```json |
| 162 | +{ |
| 163 | + "id": "asst_abc123", |
| 164 | + "object": "assistant", |
| 165 | + "created_at": 1698984975, |
| 166 | + "name": "Math Tutor", |
| 167 | + "description": null, |
| 168 | + "model": "gpt-4", |
| 169 | + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", |
| 170 | + "tools": [ |
| 171 | + { |
| 172 | + "type": "code_interpreter" |
| 173 | + } |
| 174 | + ], |
| 175 | + "file_ids": [], |
| 176 | + "metadata": {} |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +### Retrieve assistant file |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +Retrieves an assistant file. |
| 185 | + |
| 186 | +```java |
| 187 | +client.retrieveAssistantFile("asst_xv9N9dNXstuV8OVLElLqgV7U","file-jNuKdx61rNQ0FUhuPFpMNmGZ"); |
| 188 | +``` |
| 189 | + |
| 190 | +Returns: |
| 191 | + |
| 192 | +```json |
| 193 | +{ |
| 194 | + "id": "file-abc123", |
| 195 | + "object": "assistant.file", |
| 196 | + "created_at": 1699055364, |
| 197 | + "assistant_id": "asst_abc123" |
| 198 | +} |
| 199 | +``` |
| 200 | + |
| 201 | +### Modify assistant |
| 202 | + |
| 203 | +--- |
| 204 | + |
| 205 | +Modifies an assistant. |
| 206 | + |
| 207 | +```java |
| 208 | +AssistantsEntity entity = AssistantsEntity.builder() |
| 209 | + .name("Math Tutor 1") |
| 210 | + .model(CompletionModel.GPT_35_TURBO) |
| 211 | + .instructions("You are a personal math tutor. When asked a question, write and run Python code to answer the question.") |
| 212 | + .build(); |
| 213 | +client. |
| 214 | + |
| 215 | +updateAssistant("asst_xv9N9dNXstuV8OVLElLqgV7U",entity); |
| 216 | +``` |
| 217 | + |
| 218 | +Returns: |
| 219 | + |
| 220 | +```json |
| 221 | +{ |
| 222 | + "id": "asst_abc123", |
| 223 | + "object": "assistant", |
| 224 | + "created_at": 1698984975, |
| 225 | + "name": "Math Tutor 1", |
| 226 | + "description": null, |
| 227 | + "model": "gpt-4", |
| 228 | + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", |
| 229 | + "tools": [ |
| 230 | + { |
| 231 | + "type": "code_interpreter" |
| 232 | + } |
| 233 | + ], |
| 234 | + "file_ids": [], |
| 235 | + "metadata": {} |
| 236 | +} |
| 237 | +``` |
| 238 | + |
| 239 | +### Delete assistant |
| 240 | + |
| 241 | +--- |
| 242 | + |
| 243 | +Deletes an assistant. |
| 244 | + |
| 245 | +```java |
| 246 | +client.deleteAssistant("asst_xv9N9dNXstuV8OVLElLqgV7U"); |
| 247 | +``` |
| 248 | + |
| 249 | +Returns: |
| 250 | + |
| 251 | +```json |
| 252 | +{ |
| 253 | + "id": "asst_abc123", |
| 254 | + "object": "assistant.deleted", |
| 255 | + "deleted": true |
| 256 | +} |
| 257 | +``` |
| 258 | + |
| 259 | +### Delete assistant file |
| 260 | + |
| 261 | +--- |
| 262 | + |
| 263 | +Deletes an assistant file. |
| 264 | + |
| 265 | +```java |
| 266 | +client.deleteAssistantFile("asst_xv9N9dNXstuV8OVLElLqgV7U","file-jNuKdx61rNQ0FUhuPFpMNmGZ"); |
| 267 | +``` |
| 268 | + |
| 269 | +Returns: |
| 270 | + |
| 271 | +```json |
| 272 | +{ |
| 273 | + "id": "file-abc123", |
| 274 | + "object": "assistant.file.deleted", |
| 275 | + "deleted": true |
| 276 | +} |
| 277 | +``` |
0 commit comments