Skip to content

Commit 4a33562

Browse files
feat: Support ai/extract and ai/extract_structured endpoints (box/box-codegen#566) (#356)
1 parent 38ab75b commit 4a33562

22 files changed

+1383
-326
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "5b7aecf", "specHash": "b21666d", "version": "1.6.0" }
1+
{ "engineHash": "5ceb679", "specHash": "d9f90b8", "version": "1.6.0" }

docs/ai.md

+78-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# AiManager
22

3-
- [Send AI question request](#send-ai-question-request)
4-
- [Send AI request to generate text](#send-ai-request-to-generate-text)
3+
- [Ask question](#ask-question)
4+
- [Generate text](#generate-text)
55
- [Get AI agent default configuration](#get-ai-agent-default-configuration)
6+
- [Extract metadata (freeform)](#extract-metadata-freeform)
7+
- [Extract metadata (structured)](#extract-metadata-structured)
68

7-
## Send AI question request
9+
## Ask question
810

911
Sends an AI request to supported LLMs and returns an answer specifically focused on the user's question given the provided context.
1012

@@ -20,14 +22,14 @@ await client.ai.createAiAsk({
2022
mode: 'multiple_item_qa' as AiAskModeField,
2123
prompt: 'Which direction sun rises?',
2224
items: [
23-
new AiAskItemsField({
25+
new AiItemBase({
2426
id: fileToAsk1.id,
25-
type: 'file' as AiAskItemsTypeField,
27+
type: 'file' as AiItemBaseTypeField,
2628
content: 'Earth goes around the sun',
2729
}),
28-
new AiAskItemsField({
30+
new AiItemBase({
2931
id: fileToAsk2.id,
30-
type: 'file' as AiAskItemsTypeField,
32+
type: 'file' as AiItemBaseTypeField,
3133
content: 'Sun rises in the East in the morning',
3234
}),
3335
],
@@ -47,9 +49,9 @@ This function returns a value of type `AiResponseFull`.
4749

4850
A successful response including the answer from the LLM.
4951

50-
## Send AI request to generate text
52+
## Generate text
5153

52-
Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.
54+
Sends an AI request to supported Large Language Models (LLMs) and returns generated text based on the provided prompt.
5355

5456
This operation is performed by calling function `createAiTextGen`.
5557

@@ -124,9 +126,72 @@ await client.ai.getAiAgentDefaultConfig({
124126

125127
### Returns
126128

127-
This function returns a value of type `AiAgentAskOrAiAgentTextGen`.
129+
This function returns a value of type `AiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen`.
128130

129131
A successful response including the default agent configuration.
130-
This response can be one of the following two objects:
131-
AI agent for questions and AI agent for text generation. The response
132-
depends on the agent configuration requested in this endpoint.
132+
This response can be one of the following four objects:
133+
134+
- AI agent for questions
135+
- AI agent for text generation
136+
- AI agent for freeform metadata extraction
137+
- AI agent for structured metadata extraction.
138+
The response depends on the agent configuration requested in this endpoint.
139+
140+
## Extract metadata (freeform)
141+
142+
Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs.
143+
Freeform metadata extraction does not require any metadata template setup before sending the request.
144+
145+
This operation is performed by calling function `createAiExtract`.
146+
147+
See the endpoint docs at
148+
[API Reference](https://developer.box.com/reference/post-ai-extract/).
149+
150+
<!-- sample post_ai_extract -->
151+
152+
```ts
153+
await client.ai.createAiExtract({
154+
prompt: 'firstName, lastName, location, yearOfBirth, company',
155+
items: [new AiItemBase({ id: file.id })],
156+
} satisfies AiExtract);
157+
```
158+
159+
### Arguments
160+
161+
- requestBody `AiExtract`
162+
- Request body of createAiExtract method
163+
- optionalsInput `CreateAiExtractOptionalsInput`
164+
-
165+
166+
### Returns
167+
168+
This function returns a value of type `AiResponse`.
169+
170+
A response including the answer from the LLM.
171+
172+
## Extract metadata (structured)
173+
174+
Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs.
175+
For this request, you need to use an already defined metadata template or a define a schema yourself.
176+
To learn more about creating templates, see [Creating metadata templates in the Admin Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
177+
or use the [metadata template API](g://metadata/templates/create).
178+
179+
This operation is performed by calling function `createAiExtractStructured`.
180+
181+
See the endpoint docs at
182+
[API Reference](https://developer.box.com/reference/post-ai-extract-structured/).
183+
184+
_Currently we don't have an example for calling `createAiExtractStructured` in integration tests_
185+
186+
### Arguments
187+
188+
- requestBody `AiExtractStructured`
189+
- Request body of createAiExtractStructured method
190+
- optionalsInput `CreateAiExtractStructuredOptionalsInput`
191+
-
192+
193+
### Returns
194+
195+
This function returns a value of type `AiExtractResponse`.
196+
197+
A successful response including the answer from the LLM.

0 commit comments

Comments
 (0)