Skip to content

Commit

Permalink
OpenAIService - new functions/endpoints - retrieveAssistantFile
Browse files Browse the repository at this point in the history
  • Loading branch information
branislav-burdiliak committed Feb 14, 2024
1 parent 53efd2d commit a80220d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,21 @@ private trait OpenAIServiceImpl extends OpenAICoreServiceImpl with OpenAIService
).map { response =>
handleNotFoundAndError(response).map(_.asSafe[Assistant])
}

/**
* Retrieves an AssistantFile.
*
* @param assistantId
* The ID of the assistant who the file belongs to.
* @param fileId
* The ID of the file we're getting.
*/
override def retrieveAssistantFile(assistantId: String, fileId: String): Future[Option[AssistantFile]] =
execGETWithStatus(
EndPoint.assistants,
Some(s"$assistantId/files/$fileId")
).map { response =>
handleNotFoundAndError(response).map(_.asSafe[AssistantFile])
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -834,4 +834,14 @@ trait OpenAIService extends OpenAICoreService {
*/
def retrieveAssistant(assistantId: String): Future[Option[Assistant]]

/**
* Retrieves an AssistantFile.
*
* @param assistantId
* The ID of the assistant who the file belongs to.
* @param fileId
* The ID of the file we're getting.
*/
def retrieveAssistantFile(assistantId: String, fileId: String): Future[Option[AssistantFile]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ trait OpenAIServiceWrapper extends OpenAIService {
override def retrieveAssistant(assistantId: String): Future[Option[Assistant]] =
wrap(_.retrieveAssistant(assistantId))

override def retrieveAssistantFile(assistantId: String, fileId: String): Future[Option[AssistantFile]] =
wrap(_.retrieveAssistantFile(assistantId, fileId))

protected def wrap[T](
fun: OpenAIService => Future[T]
): Future[T]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.cequence.openaiscala.examples

import scala.concurrent.Future

object RetrieveAssistantFile extends Example {

override protected def run: Future[_] =
for {
assistant <- service.retrieveAssistantFile(
assistantId = "asst_Btbc2h7dqyDU52g1KfBa2XE8",
fileId = "file_2bX"
)
} yield {
println(assistant)
}

}

0 comments on commit a80220d

Please sign in to comment.