Skip to content

Commit

Permalink
[rfc][sdk] 1/n Standardize Input Schema - Input Attachment Data (#929)
Browse files Browse the repository at this point in the history
[rfc][sdk] 1/n Standardize Input Schema - Input Attachment Data




Starting point of standardizing Input Schema for prompts

This diff introduces the type `AttachmentDataWithStringValue` to python
and typescript sdk which will allow attachments to have structure as
well as validation in python (pydantic validation).

## testplan

<img width="1273" alt="Screenshot 2024-01-15 at 5 52 11 PM"
src="https://github.com/lastmile-ai/aiconfig/assets/141073967/0e5b1c83-cf94-4b2e-b267-8e45b4296593">
  • Loading branch information
Ankush-lastmile authored Jan 15, 2024
2 parents a6e810b + dd1a4fa commit e101b67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/src/aiconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
AIConfig,
ConfigMetadata,
ExecuteResult,
AttachmentDataWithStringValue,
JSONObject,
ModelMetadata,
Output,
Expand Down
11 changes: 10 additions & 1 deletion python/src/aiconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class OutputDataWithToolCallsValue(BaseModel):
OutputDataWithToolCallsValue,
]

class AttachmentDataWithStringValue(BaseModel):
"""
This represents the attachment data that is stored as a string, but we use
both the `kind` field here and the `mime_type` in Attachment to convert
the string into the input format we want.
"""

kind: Literal["file_uri", "base64"]
value: str

class ExecuteResult(BaseModel):
"""
Expand Down Expand Up @@ -152,7 +161,7 @@ class Attachment(BaseModel):
"""

# The data representing the attachment
data: Any
data: Union[AttachmentDataWithStringValue, str, Any]
# The MIME type of the result. If not specified, the MIME type will be assumed to be text/plain
mime_type: Optional[str] = None
# Output metadata
Expand Down
13 changes: 12 additions & 1 deletion typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ export type SchemaVersion =
| "v1"
| "latest";

/**
* This represents the attachment data that is stored as a string, but we use
* both the `kind` field here and the `mime_type` in Attachment to convert
* the string into the input format we want.
*/
type AttachmentDataWithStringValue = {
kind: "file_uri" | "base64";
value: string;
};


export type Attachment = {
/**
* The data representing the attachment
*/
data: JSONValue;
data: JSONValue | AttachmentDataWithStringValue;

/**
* The MIME type of the result. If not specified, the MIME type will be
Expand Down

0 comments on commit e101b67

Please sign in to comment.