generated from softwaremill/sbt-template
-
Notifications
You must be signed in to change notification settings - Fork 12
add Upload API #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add Upload API #291
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/scala/sttp/openai/requests/upload/UploadRequestBody.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sttp.openai.requests.upload | ||
|
||
import sttp.openai.json.SnakePickle | ||
|
||
/** Represents the request body for uploading a file. | ||
* | ||
* @param filename | ||
* The name of the file to upload. | ||
* @param purpose | ||
* The intended purpose of the uploaded file. | ||
* @param bytes | ||
* The number of bytes in the file you are uploading. | ||
* @param mimeType | ||
* The MIME type of the file. | ||
* | ||
* This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision. | ||
*/ | ||
case class UploadRequestBody( | ||
filename: String, | ||
purpose: String, | ||
bytes: Int, | ||
mimeType: String | ||
) | ||
|
||
object UploadRequestBody { | ||
implicit val uploadRequestBodyW: SnakePickle.Writer[UploadRequestBody] = SnakePickle.macroW[UploadRequestBody] | ||
} | ||
|
||
/** @param partIds | ||
* The ordered list of Part IDs. | ||
* @param md5 | ||
* The optional md5 checksum for the file contents to verify if the bytes uploaded matches what you expect. | ||
*/ | ||
case class CompleteUploadRequestBody( | ||
partIds: Seq[String], | ||
md5: Option[String] | ||
) | ||
|
||
object CompleteUploadRequestBody { | ||
implicit val completeUploadRequestBodyW: SnakePickle.Writer[CompleteUploadRequestBody] = SnakePickle.macroW[CompleteUploadRequestBody] | ||
} |
75 changes: 75 additions & 0 deletions
75
core/src/main/scala/sttp/openai/requests/upload/UploadResponse.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package sttp.openai.requests.upload | ||
|
||
import sttp.openai.json.SnakePickle | ||
|
||
/** Represents the response for an upload request. | ||
* | ||
* @param id | ||
* The Upload unique identifier, which can be referenced in API endpoints. | ||
* @param `object` | ||
* The object type, which is always "upload". | ||
* @param bytes | ||
* The intended number of bytes to be uploaded. | ||
* @param createdAt | ||
* The Unix timestamp (in seconds) for when the Upload was created. | ||
* @param filename | ||
* The name of the file to be uploaded. | ||
* @param purpose | ||
* The intended purpose of the file. Please refer here for acceptable values. | ||
* @param status | ||
* The status of the Upload. | ||
* @param expiresAt | ||
* The Unix timestamp (in seconds) for when the Upload will expire. | ||
* @param file | ||
* The File object represents a document that has been uploaded to OpenAI. | ||
*/ | ||
case class UploadResponse( | ||
id: String, | ||
`object`: String = "upload", | ||
bytes: Int, | ||
createdAt: Int, | ||
filename: String, | ||
purpose: String, | ||
status: String, | ||
expiresAt: Int, | ||
file: Option[File] | ||
) | ||
|
||
object UploadResponse { | ||
implicit val uploadResponseR: SnakePickle.Reader[UploadResponse] = SnakePickle.macroR[UploadResponse] | ||
} | ||
|
||
case class File( | ||
id: String, | ||
`object`: String, | ||
bytes: Int, | ||
createdAt: Int, | ||
filename: String, | ||
purpose: String | ||
) | ||
|
||
object File { | ||
implicit val fileR: SnakePickle.Reader[File] = SnakePickle.macroR[File] | ||
} | ||
|
||
/** Represents the response for an upload part. | ||
* | ||
* @param id | ||
* The upload Part unique identifier, which can be referenced in API endpoints. | ||
* @param createdAt | ||
* The Unix timestamp (in seconds) for when the Part was created. | ||
* @param uploadId | ||
* The ID of the Upload object that this Part was added to. | ||
* @param `object` | ||
* The object type, which is always upload.part. | ||
*/ | ||
case class UploadPartResponse( | ||
id: String, | ||
createdAt: Int, | ||
uploadId: String, | ||
`object`: String = "upload.part" | ||
) | ||
|
||
object UploadPartResponse { | ||
implicit val uploadPartResponseR: SnakePickle.Reader[UploadPartResponse] = SnakePickle.macroR[UploadPartResponse] | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/test/scala/sttp/openai/fixtures/UploadFixture.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package sttp.openai.fixtures | ||
|
||
object UploadFixture { | ||
|
||
val jsonCreateUpload: String = | ||
"""{ | ||
| "filename": "file-name", | ||
| "purpose": "file-purpose", | ||
| "bytes": 123, | ||
| "mime_type": "file/mime-type" | ||
|}""".stripMargin | ||
|
||
val jsonCompleteUpload: String = | ||
"""{ | ||
| "part_ids": ["part_abc123", "part_def456"], | ||
| "md5": "md5-checksum" | ||
|}""".stripMargin | ||
|
||
val jsonUpdateResponse: String = | ||
"""{ | ||
| "id": "upload_abc123", | ||
| "object": "upload", | ||
| "bytes": 1147483648, | ||
| "created_at": 1719184911, | ||
| "filename": "training_examples.jsonl", | ||
| "purpose": "fine-tune", | ||
| "status": "completed", | ||
| "expires_at": 1719127296, | ||
| "file": { | ||
| "id": "file-xyz321", | ||
| "object": "file", | ||
| "bytes": 1147483648, | ||
| "created_at": 1719186911, | ||
| "filename": "training_examples.jsonl", | ||
| "purpose": "fine-tune" | ||
| } | ||
|}""".stripMargin | ||
|
||
val jsonUploadPartResponse: String = | ||
"""{ | ||
| "id": "part_def456", | ||
| "object": "upload.part", | ||
| "created_at": 1719186911, | ||
| "upload_id": "upload_abc123" | ||
|}""".stripMargin | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can you deserialise a
File
from JSON? what's the intended content of this field?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, it's the
File
below, notjava.io.File
:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is just some file metadata :) Perhaps I should rename this class (FileMetadata) to make it clear that this is not an actual file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, this is a good idea, let's do that :)