Skip to content

Commit

Permalink
feat: Add ai_agent info to AiResponse (box/box-openapi#485) (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Dec 9, 2024
1 parent 1c54bf5 commit 351a5b8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "f073ce3", "specHash": "544d370", "version": "1.8.0" }
{ "engineHash": "a839036", "specHash": "d7dfe68", "version": "1.8.0" }
10 changes: 8 additions & 2 deletions box_sdk_gen/managers/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ def create_ai_extract(
"""
Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs.
Freeform metadata extraction does not require any metadata template setup before sending the request.
In this request, both the prompt and the output can be freeform.
Metadata template setup before sending the request is not required.
:param prompt: The prompt provided to a Large Language Model (LLM) in the request. The prompt can be up to 10000 characters long and it can be an XML or a JSON schema.
:type prompt: str
Expand Down Expand Up @@ -414,7 +417,10 @@ def create_ai_extract_structured(
"""
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 a define a schema yourself.
For this request, you either need a metadata template or a list of fields you want to extract.
Input is **either** a metadata template or a list of fields to ensure the structure.
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)
Expand Down
10 changes: 6 additions & 4 deletions box_sdk_gen/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from box_sdk_gen.schemas.ai_agent_info import *

from box_sdk_gen.schemas.ai_response import *

from box_sdk_gen.schemas.ai_citation import *

from box_sdk_gen.schemas.ai_response_full import *

from box_sdk_gen.schemas.ai_dialogue_history import *

from box_sdk_gen.schemas.ai_extract_response import *
Expand Down Expand Up @@ -40,10 +46,6 @@

from box_sdk_gen.schemas.ai_ask import *

from box_sdk_gen.schemas.ai_response import *

from box_sdk_gen.schemas.ai_response_full import *

from box_sdk_gen.schemas.app_item import *

from box_sdk_gen.schemas.classification import *
Expand Down
49 changes: 49 additions & 0 deletions box_sdk_gen/schemas/ai_agent_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing import Optional

from box_sdk_gen.internal.base_object import BaseObject

from typing import List

from box_sdk_gen.box.errors import BoxSDKError


class AiAgentInfoModelsField(BaseObject):
def __init__(
self,
*,
name: Optional[str] = None,
provider: Optional[str] = None,
supported_purpose: Optional[str] = None,
**kwargs
):
"""
:param name: The name of the model used for the request, defaults to None
:type name: Optional[str], optional
:param provider: The provider that owns the model used for the request, defaults to None
:type provider: Optional[str], optional
:param supported_purpose: The supported purpose utilized by the model used for the request, defaults to None
:type supported_purpose: Optional[str], optional
"""
super().__init__(**kwargs)
self.name = name
self.provider = provider
self.supported_purpose = supported_purpose


class AiAgentInfo(BaseObject):
def __init__(
self,
*,
models: Optional[List[AiAgentInfoModelsField]] = None,
processor: Optional[str] = None,
**kwargs
):
"""
:param models: The models used for the request, defaults to None
:type models: Optional[List[AiAgentInfoModelsField]], optional
:param processor: The processor used for the request, defaults to None
:type processor: Optional[str], optional
"""
super().__init__(**kwargs)
self.models = models
self.processor = processor
4 changes: 4 additions & 0 deletions box_sdk_gen/schemas/ai_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from box_sdk_gen.internal.base_object import BaseObject

from box_sdk_gen.schemas.ai_agent_info import AiAgentInfo

from box_sdk_gen.box.errors import BoxSDKError

from box_sdk_gen.internal.utils import DateTime
Expand All @@ -14,6 +16,7 @@ def __init__(
created_at: DateTime,
*,
completion_reason: Optional[str] = None,
ai_agent_info: Optional[AiAgentInfo] = None,
**kwargs
):
"""
Expand All @@ -28,3 +31,4 @@ def __init__(
self.answer = answer
self.created_at = created_at
self.completion_reason = completion_reason
self.ai_agent_info = ai_agent_info
4 changes: 4 additions & 0 deletions box_sdk_gen/schemas/ai_response_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from box_sdk_gen.internal.utils import DateTime

from box_sdk_gen.schemas.ai_agent_info import AiAgentInfo

from box_sdk_gen.schemas.ai_response import AiResponse

from box_sdk_gen.schemas.ai_citation import AiCitation
Expand All @@ -19,6 +21,7 @@ def __init__(
*,
citations: Optional[List[AiCitation]] = None,
completion_reason: Optional[str] = None,
ai_agent_info: Optional[AiAgentInfo] = None,
**kwargs
):
"""
Expand All @@ -35,6 +38,7 @@ def __init__(
answer=answer,
created_at=created_at,
completion_reason=completion_reason,
ai_agent_info=ai_agent_info,
**kwargs
)
self.citations = citations
6 changes: 4 additions & 2 deletions docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ This response can be one of the following four objects:
## Extract metadata (freeform)

Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs.
Freeform metadata extraction does not require any metadata template setup before sending the request.
In this request, both the prompt and the output can be freeform.
Metadata template setup before sending the request is not required.

This operation is performed by calling function `create_ai_extract`.

Expand Down Expand Up @@ -196,7 +197,8 @@ A response including the answer from the LLM.
## Extract metadata (structured)

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 a define a schema yourself.
For this request, you either need a metadata template or a list of fields you want to extract.
Input is **either** a metadata template or a list of fields to ensure the structure.
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)
or use the [metadata template API](g://metadata/templates/create).

Expand Down

0 comments on commit 351a5b8

Please sign in to comment.