Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
91cf70e
Add cancel run endpoint
branislav-burdiliak Jul 15, 2024
ba9e33d
Add modify run endpoint
branislav-burdiliak Jul 15, 2024
9a986bd
Add list runs endpoint
branislav-burdiliak Jul 15, 2024
771a8d2
Add newly introduced methods to service wrapper
branislav-burdiliak Jul 15, 2024
584d59e
Finish createRun
branislav-burdiliak Aug 4, 2024
626850a
Separate assistant tool hierarchy to be used by create assistant and …
branislav-burdiliak Aug 4, 2024
c23d710
wip
branislav-burdiliak Aug 6, 2024
20b953c
Add order param to list runs endpoint
branislav-burdiliak Aug 9, 2024
1ec0e1d
Fix submit tool outputs endpoint
branislav-burdiliak Aug 9, 2024
eae9d68
Add retrieve run step endpoint
branislav-burdiliak Aug 9, 2024
5387e5b
Fix assistant tool codec
branislav-burdiliak Aug 9, 2024
c2a80dd
Reformat code
branislav-burdiliak Aug 9, 2024
810373b
Fix serialization of assistant's code interpreter tool's file IDs
branislav-burdiliak Aug 9, 2024
c55fc19
WIP - create thread and run
branislav-burdiliak Sep 5, 2024
a196332
added JsonFormats, compiling
bburdiliak Sep 9, 2024
8f9025a
fix formats, add Assistants example
bburdiliak Sep 10, 2024
b456777
scalafmt
bburdiliak Sep 10, 2024
95c1986
Merge remote-tracking branch 'origin/master' into feature/finish_run_API
bburdiliak Sep 11, 2024
84f94de
compilable after merging master
bburdiliak Sep 11, 2024
eecf951
scalafmt
bburdiliak Sep 11, 2024
bd4c94e
deleteThreadMessage + reorder methods to match the API reference
bburdiliak Sep 12, 2024
c319641
get rid of UploadFileSettings
bburdiliak Sep 12, 2024
a38d2ab
polling example for createThreadAndRun
bburdiliak Sep 12, 2024
6f44021
added methods: modifyVectorStore, retrieveVectorStore, retrieveVector…
bburdiliak Sep 13, 2024
b4b6bf9
scalafmt
bburdiliak Sep 13, 2024
e6ff47d
Merge branch 'master' into feature/finish_run_API
peterbanda Sep 16, 2024
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
Prev Previous commit
Next Next commit
deleteThreadMessage + reorder methods to match the API reference
  • Loading branch information
bburdiliak committed Sep 12, 2024
commit bd4c94e6543dddb2f480dbc161ea0aa77f9d3902
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@ private[service] trait OpenAIServiceImpl
)
}

override def cancelRun(
threadId: String,
runId: String
): Future[Run] =
execPOST(
EndPoint.threads,
Some(s"$threadId/runs/$runId/cancel")
).map(
_.asSafeJson[Run]
)

override def modifyRun(
threadId: String,
runId: String,
Expand Down Expand Up @@ -173,6 +162,19 @@ private[service] trait OpenAIServiceImpl
_.asSafeJson[Run]
)

override def cancelRun(
threadId: String,
runId: String
): Future[Run] = {
execPOST(
EndPoint.threads,
Some(s"$threadId/runs/$runId/cancel")
).map(
_.asSafeJson[Run]
)

}

override def retrieveRun(
threadId: String,
runId: String
Expand Down Expand Up @@ -857,6 +859,15 @@ private[service] trait OpenAIServiceImpl
readAttribute(response.json, "data").asSafeArray[ThreadFullMessage]
}

override def deleteThreadMessage(
threadId: String,
messageId: String
): Future[DeleteResponse] =
execDELETERich(
EndPoint.threads,
endPointParam = Some(s"$threadId/messages/$messageId")
).map(handleDeleteEndpointResponse)

override def retrieveThreadMessageFile(
threadId: String,
messageId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,122 +88,6 @@ trait OpenAIService extends OpenAICoreService {
settings: CreateChatCompletionSettings = DefaultSettings.CreateChatFunCompletion
): Future[ChatFunCompletionResponse]

/**
* @param assistantId
* The ID of the assistant to use to execute this run.
* @param thread
* The ID of the thread to run.
* @param instructions
* Override the default system message of the assistant. This is useful for modifying the
* behavior on a per-run basis.
* @param tools
* Override the tools the assistant can use for this run. This is useful for modifying the
* behavior on a per-run basis.
* @param toolResources
* A set of resources that are used by the assistant's tools. The resources are specific to
* the type of tool. For example, the code_interpreter tool requires a list of file IDs,
* while the file_search tool requires a list of vector store IDs.
* @param toolChoice
* Controls which (if any) tool is called by the model. none means the model will not call
* any tools and instead generates a message. auto is the default value and means the model
* can pick between generating a message or calling one or more tools. required means the
* model must call one or more tools before responding to the user. Specifying a particular
* tool like {"type": "file_search"} or {"type": "function", "function": {"name":
* "my_function"}} forces the model to call that tool.
* @param settings
* @param stream
* If true, returns a stream of events that happen during the Run as server-sent events,
* terminating when the Run enters a terminal state with a data: [DONE] message.
* @returns
* A run object.
*/
def createThreadAndRun(
assistantId: AssistantId,
thread: Option[ThreadAndRun],
instructions: Option[String] = None,
tools: Seq[AssistantTool] = Seq.empty,
toolResources: Option[ThreadAndRunToolResource] = None,
toolChoice: Option[ToolChoice] = None,
settings: CreateThreadAndRunSettings = DefaultSettings.CreateThreadAndRun,
stream: Boolean
): Future[Run]

/**
* Cancels a run that is in_progress
*
* @param threadId
* The ID of the thread to which this run belongs.
* @param runId
* The ID of the run to cancel.
* @return
* The modified run object matching the specified ID.
*/
def cancelRun(
threadId: String,
runId: String
): Future[Run]

/**
* Modifies a run.
*
* @param threadId
* The ID of the thread that was run.
* @param runId
* The ID of the run to modify.
* @param metadata
* Set of 16 key-value pairs that can be attached to an object. This can be useful for
* storing additional information about the object in a structured format. Keys can be a
* maximum of 64 characters long and values can be a maximum of 512 characters long.
* @return
* The modified run object matching the specified ID.
*/
def modifyRun(
threadId: String,
runId: String,
metadata: Map[String, String]
): Future[Run]

def retrieveRun(
threadId: String,
runId: String
): Future[Option[Run]]

/**
* Returns a list of runs belonging to a thread.
*
* @param threadId
* The ID of the thread the run belongs to.
* @param pagination
* @param order
* Sort order by the created_at timestamp of the objects. asc for ascending order and desc
* for descending order.
* @return
* A list of run objects.
*/
def listRuns(
threadId: String,
pagination: Pagination = Pagination.default,
order: Option[SortOrder] = None
): Future[Seq[Run]]

/**
* Retrieves a run step.
*
* @param threadID
* The ID of the thread to which the run and run step belongs.
* @param runId
* The ID of the run to which the run step belongs.
* @param stepId
* The ID of the run step to retrieve.
* @return
* The run step object matching the specified ID.
*/
def retrieveRunStep(
threadID: String,
runId: String,
stepId: String
): Future[Option[RunStep]]

/**
* Creates a model response for the given chat conversation expecting a tool call.
*
Expand Down Expand Up @@ -1037,6 +921,24 @@ trait OpenAIService extends OpenAICoreService {
order: Option[SortOrder] = None
): Future[Seq[ThreadFullMessage]]

/**
* Deletes a thread message.
*
* @param threadId
* The ID of the thread to which this message belongs.
* @param messageId
* The ID of the message to delete.
* @return
* Deletion status.
* @see
* <a href="https://platform.openai.com/docs/api-reference/messages/deleteMessage">OpenAI
* Doc</a>
*/
def deleteThreadMessage(
threadId: String,
messageId: String
): Future[DeleteResponse]

/////////////////
// THREAD FILE //
/////////////////
Expand Down Expand Up @@ -1131,6 +1033,89 @@ trait OpenAIService extends OpenAICoreService {
stream: Boolean
): Future[Run]

/**
* @param assistantId
* The ID of the assistant to use to execute this run.
* @param thread
* The ID of the thread to run.
* @param instructions
* Override the default system message of the assistant. This is useful for modifying the
* behavior on a per-run basis.
* @param tools
* Override the tools the assistant can use for this run. This is useful for modifying the
* behavior on a per-run basis.
* @param toolResources
* A set of resources that are used by the assistant's tools. The resources are specific to
* the type of tool. For example, the code_interpreter tool requires a list of file IDs,
* while the file_search tool requires a list of vector store IDs.
* @param toolChoice
* Controls which (if any) tool is called by the model. none means the model will not call
* any tools and instead generates a message. auto is the default value and means the model
* can pick between generating a message or calling one or more tools. required means the
* model must call one or more tools before responding to the user. Specifying a particular
* tool like {"type": "file_search"} or {"type": "function", "function": {"name":
* "my_function"}} forces the model to call that tool.
* @param settings
* @param stream
* If true, returns a stream of events that happen during the Run as server-sent events,
* terminating when the Run enters a terminal state with a data: [DONE] message.
* @returns
* A run object.
*/
def createThreadAndRun(
assistantId: AssistantId,
thread: Option[ThreadAndRun],
instructions: Option[String] = None,
tools: Seq[AssistantTool] = Seq.empty,
toolResources: Option[ThreadAndRunToolResource] = None,
toolChoice: Option[ToolChoice] = None,
settings: CreateThreadAndRunSettings = DefaultSettings.CreateThreadAndRun,
stream: Boolean
): Future[Run]

/**
* Returns a list of runs belonging to a thread.
*
* @param threadId
* The ID of the thread the run belongs to.
* @param pagination
* @param order
* Sort order by the created_at timestamp of the objects. asc for ascending order and desc
* for descending order.
* @return
* A list of run objects.
*/
def listRuns(
threadId: String,
pagination: Pagination = Pagination.default,
order: Option[SortOrder] = None
): Future[Seq[Run]]

def retrieveRun(
threadId: String,
runId: String
): Future[Option[Run]]

/**
* Modifies a run.
*
* @param threadId
* The ID of the thread that was run.
* @param runId
* The ID of the run to modify.
* @param metadata
* Set of 16 key-value pairs that can be attached to an object. This can be useful for
* storing additional information about the object in a structured format. Keys can be a
* maximum of 64 characters long and values can be a maximum of 512 characters long.
* @return
* The modified run object matching the specified ID.
*/
def modifyRun(
threadId: String,
runId: String,
metadata: Map[String, String]
): Future[Run]

/**
* When a run has the status: "requires_action" and required_action.type is
* submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls
Expand All @@ -1155,12 +1140,28 @@ trait OpenAIService extends OpenAICoreService {
stream: Boolean
): Future[Run]

/**
* Cancels a run that is in_progress
*
* @param threadId
* The ID of the thread to which this run belongs.
* @param runId
* The ID of the run to cancel.
* @return
* The modified run object matching the specified ID.
*/
def cancelRun(
threadId: String,
runId: String
): Future[Run]

///////////////
// RUN STEPS //
///////////////

/**
* Returns a list of run steps belonging to a run.
* Returns a list of run steps belonging to a run. Returns a list of run steps belonging to a
* run.
*
* @param threadId
* The ID of the thread the run and run step belongs to.
Expand All @@ -1181,7 +1182,23 @@ trait OpenAIService extends OpenAICoreService {
order: Option[SortOrder] = None
): Future[Seq[RunStep]]

// TODO: retrieveRunStep - https://platform.openai.com/docs/api-reference/run-steps/getRunStep
/**
* Retrieves a run step.
*
* @param threadID
* The ID of the thread to which the run and run step belongs.
* @param runId
* The ID of the run to which the run step belongs.
* @param stepId
* The ID of the run step to retrieve.
* @return
* The run step object matching the specified ID.
*/
def retrieveRunStep(
threadID: String,
runId: String,
stepId: String
): Future[Option[RunStep]]

//////////////////
// VECTOR STORE //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ trait OpenAIServiceWrapper
_.listThreadMessages(threadId, pagination, order)
)

def deleteThreadMessage(
threadId: String,
messageId: String
): Future[DeleteResponse] = wrap(
_.deleteThreadMessage(threadId, messageId)
)

override def retrieveThreadMessageFile(
threadId: String,
messageId: String,
Expand Down