|
| 1 | +AI |
| 2 | +== |
| 3 | + |
| 4 | +AI allows to send an intelligence request to supported large language models and returns |
| 5 | +an answer based on the provided prompt and items. |
| 6 | + |
| 7 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 8 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 9 | + |
| 10 | +- [AI](#ai) |
| 11 | + - [Send AI request](#send-ai-request) |
| 12 | + - [Send AI text generation request](#send-ai-text-generation-request) |
| 13 | + - [Get AI Agent default configuration](#get-ai-agent-default-configuration) |
| 14 | + - [Extract metadata freeform](#extract-metadata-freeform) |
| 15 | + - [Extract metadata structured](#extract-metadata-structured) |
| 16 | + |
| 17 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 18 | + |
| 19 | +Send AI request |
| 20 | +-------------------------- |
| 21 | + |
| 22 | +To send an AI request, call static |
| 23 | +[`sendAIRequest(String prompt, List<BoxAIItem> items, Mode mode)`][send-ai-request] method. |
| 24 | +In the request you have to provide a prompt, a list of items that your prompt refers to and a mode of the request. |
| 25 | +There are two modes available: `SINGLE_ITEM_QA` and `MULTI_ITEM_QA`, which specifies if this request refers to |
| 26 | +for a single or multiple items. |
| 27 | + |
| 28 | +<!-- sample post_ai_ask --> |
| 29 | +```java |
| 30 | +BoxAIResponse response = BoxAI.sendAIRequest( |
| 31 | + api, |
| 32 | + "What is the content of the file?", |
| 33 | + Collections.singletonList("123456", BoxAIItem.Type.FILE), |
| 34 | + BoxAI.Mode.SINGLE_ITEM_QA |
| 35 | +); |
| 36 | +``` |
| 37 | + |
| 38 | +You can also provide a list of dialogue history entries to provide additional context to the LLM in generating the response, AI Agent configuration and flag to indicate whether citations should be returned. |
| 39 | + |
| 40 | +NOTE: The AI endpoint may return a 412 status code if you use for your request a file which has just been updated to the box. |
| 41 | +It usually takes a few seconds for the file to be indexed and available for the AI endpoint. |
| 42 | + |
| 43 | +[send-ai-request]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#sendAIRequest-com.box.sdk.BoxAPIConnection-java.lang.String-java.util.List-com.box.sdk.BoxAI.Mode- |
| 44 | + |
| 45 | +Send AI text generation request |
| 46 | +-------------- |
| 47 | + |
| 48 | +To send an AI request specifically focused on the creation of new text, call static |
| 49 | +[`sendAITextGenRequest(String prompt, List<BoxAIItem> items, List<BoxAIDialogueEntry> dialogueHistory)`][send-ai-text-gen-request] method. |
| 50 | +In the request you have to provide a prompt, a list of items that your prompt refers to and optionally a dialogue history, |
| 51 | +which provides additional context to the LLM in generating the response. |
| 52 | + |
| 53 | +<!-- sample post_ai_text_gen --> |
| 54 | +```java |
| 55 | +List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>(); |
| 56 | +dialogueHistory.add( |
| 57 | + new BoxAIDialogueEntry( |
| 58 | + "Make my email about public APIs sound more professional", |
| 59 | + "Here is the first draft of your professional email about public APIs.", |
| 60 | + BoxDateFormat.parse("2013-05-16T15:26:57-07:00") |
| 61 | + ) |
| 62 | + ); |
| 63 | +BoxAIResponse response = BoxAI.sendAITextGenRequest( |
| 64 | + api, |
| 65 | + "Write an email to a client about the importance of public APIs.", |
| 66 | + Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)), |
| 67 | + dialogueHistory |
| 68 | +); |
| 69 | +``` |
| 70 | + |
| 71 | +You can also provide an AI Agent configuration to customize the behavior of the AI response generation. |
| 72 | + |
| 73 | +[send-ai-text-gen-request]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#sendAITextGenRequest-com.box.sdk.BoxAPIConnection-java.lang.String-java.util.List-java.util.List- |
| 74 | + |
| 75 | +Get AI Agent default configuration |
| 76 | +-------------------------- |
| 77 | + |
| 78 | +To get the default configuration of the AI Agent, call static |
| 79 | +[`getAiAgentDefaultConfig(BoxAPIConnection api, BoxAIAgent.Mode mode, String language, String model)`][get-ai-agent-default-config] method. |
| 80 | +In the request you have to provide the mode of the AI Agent, the language and the model, with the model is required while the language and mode are optional. |
| 81 | + |
| 82 | +<!-- sample get_ai_agent_default --> |
| 83 | +```java |
| 84 | +BoxAIAgentConfig config = BoxAI.getAiAgentDefaultConfig( |
| 85 | + api, |
| 86 | + BoxAIAgent.Mode.ASK, |
| 87 | + "en", |
| 88 | + "openai__gpt_3_5_turbo" |
| 89 | +); |
| 90 | +``` |
| 91 | + |
| 92 | +[get-ai-agent-default-config]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#getAiAgentDefaultConfig-com.box.sdk.BoxAPIConnection-com.box.sdk.ai.BoxAIAgent.Mode-java.lang.String-java.lang.String- |
| 93 | + |
| 94 | +Extract metadata freeform |
| 95 | +-------------------------- |
| 96 | + |
| 97 | +To send an AI request to supported Large Language Models (LLMs) and extract metadata in form of key-value pairs, call static |
| 98 | +[`extractMetadataFreeform(BoxAPIConnection api, String prompt, List<BoxAIItem> items)`][extract-metadata-freeform] method. |
| 99 | +In the request you have to provide a prompt, a list of items that your prompt refers to and an optional agent configuration. |
| 100 | + |
| 101 | +<!-- sample post_ai_extract --> |
| 102 | +```java |
| 103 | +BoxAIResponse response = BoxAI.extractMetadataFreeform( |
| 104 | + api, |
| 105 | + "firstName, lastName, location, yearOfBirth, company", |
| 106 | + Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)) |
| 107 | +); |
| 108 | +``` |
| 109 | + |
| 110 | +[extract-metadata-freeform]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#extractMetadataFreeform-com.box.sdk.BoxAPIConnection-java.lang.String-java.util.List- |
| 111 | + |
| 112 | +Extract metadata structured |
| 113 | +-------------------------- |
| 114 | + |
| 115 | +Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs. For this request, you need to use an already defined metadata template or define a schema yourself. |
| 116 | + |
| 117 | +To send an AI request to extract metadata from files with a predefined metadata template, call static |
| 118 | +[`extractMetadataStructured extractMetadataStructured(BoxAPIConnection api, List<BoxAIItem> items, BoxAIExtractMetadataTemplate template)`][extract-metadata-structured-metadata-template] method. |
| 119 | + |
| 120 | +<!-- sample post_ai_extract_structured --> |
| 121 | +```java |
| 122 | +BoxAIExtractMetadataTemplate template = new BoxAIExtractMetadataTemplate("templateKey", "enterprise"); |
| 123 | +BoxAIExtractStructuredResponse result = BoxAI.extractMetadataStructured( |
| 124 | + api, |
| 125 | + Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)), |
| 126 | + template |
| 127 | +); |
| 128 | +JsonObject sourceJson = result.getSourceJson(); |
| 129 | +``` |
| 130 | + |
| 131 | +To send an AI request to extract metadata from files with custom fields, call static |
| 132 | +[`extractMetadataStructured extractMetadataStructured(BoxAPIConnection api, List<BoxAIItem> items, List<BoxAIExtractField> fields)`][extract-metadata-structured-fields] method. |
| 133 | + |
| 134 | +<!-- sample post_ai_extract_structured_fields --> |
| 135 | +```java |
| 136 | +List<BoxAIExtractField> fields = new ArrayList<>(); |
| 137 | +fields.add(new BoxAIExtractField("firstName")); |
| 138 | + |
| 139 | +BoxAIExtractStructuredResponse result = BoxAI.extractMetadataStructured( |
| 140 | + api, |
| 141 | + Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)), |
| 142 | + fields |
| 143 | +); |
| 144 | +JsonObject sourceJson = result.getSourceJson(); |
| 145 | +``` |
| 146 | + |
| 147 | +[extract-metadata-structured-metadata-template]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#extractMetadataStructured-com.box.sdk.BoxAPIConnection-java.util.List-com.box.sdk.ai.metadata.BoxAIExtractMetadataTemplate- |
| 148 | +[extract-metadata-structured-fields]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAI.html#extractMetadataStructured-com.box.sdk.BoxAPIConnection-java.util.List-java.util.List- |
0 commit comments