-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Beta] Add support for runs endpoints
- Loading branch information
1 parent
33b1354
commit 0c43e7f
Showing
14 changed files
with
875 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
80 changes: 80 additions & 0 deletions
80
src/main/java/io/github/stefanbratanov/chatjpt/CreateRunRequest.java
This file contains 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,80 @@ | ||
package io.github.stefanbratanov.chatjpt; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record CreateRunRequest( | ||
String assistantId, | ||
Optional<String> model, | ||
Optional<String> instructions, | ||
Optional<List<Tool>> tools, | ||
Optional<Map<String, String>> metadata) { | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String assistantId; | ||
|
||
private Optional<String> model = Optional.empty(); | ||
private Optional<String> instructions = Optional.empty(); | ||
private Optional<List<Tool>> tools = Optional.empty(); | ||
private Optional<Map<String, String>> metadata = Optional.empty(); | ||
|
||
/** | ||
* @param assistantId The ID of the assistant to use to execute this run. | ||
*/ | ||
public Builder assistantId(String assistantId) { | ||
this.assistantId = assistantId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param model The ID of the Model to be used to execute this run. If a value is provided here, | ||
* it will override the model associated with the assistant. If not, the model associated | ||
* with the assistant will be used. | ||
*/ | ||
public Builder model(String model) { | ||
this.model = Optional.of(model); | ||
return this; | ||
} | ||
|
||
/** | ||
* @param instructions Overrides the instructions of the assistant. This is useful for modifying | ||
* the behavior on a per-run basis. | ||
*/ | ||
public Builder instructions(String instructions) { | ||
this.instructions = Optional.of(instructions); | ||
return this; | ||
} | ||
|
||
/** | ||
* @param tools Override the tools the assistant can use for this run. This is useful for | ||
* modifying the behavior on a per-run basis. | ||
*/ | ||
public Builder tools(List<Tool> tools) { | ||
this.tools = Optional.of(tools); | ||
return this; | ||
} | ||
|
||
/** | ||
* @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 maxium of 512 characters long. | ||
*/ | ||
public Builder metadata(Map<String, String> metadata) { | ||
this.metadata = Optional.of(metadata); | ||
return this; | ||
} | ||
|
||
public CreateRunRequest build() { | ||
if (assistantId == null) { | ||
throw new IllegalStateException("assistantId must be set"); | ||
} | ||
return new CreateRunRequest(assistantId, model, instructions, tools, metadata); | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/io/github/stefanbratanov/chatjpt/CreateThreadAndRunRequest.java
This file contains 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,129 @@ | ||
package io.github.stefanbratanov.chatjpt; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record CreateThreadAndRunRequest( | ||
String assistantId, | ||
Optional<Thread> thread, | ||
Optional<String> model, | ||
Optional<String> instructions, | ||
Optional<List<Tool>> tools, | ||
Optional<Map<String, String>> metadata) { | ||
|
||
public record Thread( | ||
Optional<List<CreateThreadRequest.Message>> messages, | ||
Optional<Map<String, String>> metadata) { | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private Optional<List<CreateThreadRequest.Message>> messages = Optional.empty(); | ||
private Optional<Map<String, String>> metadata = Optional.empty(); | ||
|
||
/** | ||
* @param messages A list of messages to start the thread with. | ||
*/ | ||
public Builder messages(List<CreateThreadRequest.Message> messages) { | ||
this.messages = Optional.of(messages); | ||
return this; | ||
} | ||
|
||
/** | ||
* @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 maxium of 512 characters | ||
* long. | ||
*/ | ||
public Builder metadata(Map<String, String> metadata) { | ||
this.metadata = Optional.of(metadata); | ||
return this; | ||
} | ||
|
||
public Thread build() { | ||
return new Thread(messages, metadata); | ||
} | ||
} | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String assistantId; | ||
|
||
private Optional<Thread> thread = Optional.empty(); | ||
private Optional<String> model = Optional.empty(); | ||
private Optional<String> instructions = Optional.empty(); | ||
private Optional<List<Tool>> tools = Optional.empty(); | ||
private Optional<Map<String, String>> metadata = Optional.empty(); | ||
|
||
/** | ||
* @param assistantId The ID of the assistant to use to execute this run. | ||
*/ | ||
public Builder assistantId(String assistantId) { | ||
this.assistantId = assistantId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param thread Thread to be created as part of the request | ||
*/ | ||
public Builder thread(Thread thread) { | ||
this.thread = Optional.of(thread); | ||
return this; | ||
} | ||
|
||
/** | ||
* @param model The ID of the Model to be used to execute this run. If a value is provided here, | ||
* it will override the model associated with the assistant. If not, the model associated | ||
* with the assistant will be used. | ||
*/ | ||
public Builder model(String model) { | ||
this.model = Optional.of(model); | ||
return this; | ||
} | ||
|
||
/** | ||
* @param instructions Overrides the instructions of the assistant. This is useful for modifying | ||
* the behavior on a per-run basis. | ||
*/ | ||
public Builder instructions(String instructions) { | ||
this.instructions = Optional.of(instructions); | ||
return this; | ||
} | ||
|
||
/** | ||
* @param tools Override the tools the assistant can use for this run. This is useful for | ||
* modifying the behavior on a per-run basis. | ||
*/ | ||
public Builder tools(List<Tool> tools) { | ||
this.tools = Optional.of(tools); | ||
return this; | ||
} | ||
|
||
/** | ||
* @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 maxium of 512 characters long. | ||
*/ | ||
public Builder metadata(Map<String, String> metadata) { | ||
this.metadata = Optional.of(metadata); | ||
return this; | ||
} | ||
|
||
public CreateThreadAndRunRequest build() { | ||
if (assistantId == null) { | ||
throw new IllegalStateException("assistantId must be set"); | ||
} | ||
return new CreateThreadAndRunRequest( | ||
assistantId, thread, model, instructions, tools, metadata); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/stefanbratanov/chatjpt/ModifyRunRequest.java
This file contains 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,30 @@ | ||
package io.github.stefanbratanov.chatjpt; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record ModifyRunRequest(Optional<Map<String, String>> metadata) { | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private Optional<Map<String, String>> metadata = Optional.empty(); | ||
|
||
/** | ||
* @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 maxium of 512 characters long. | ||
*/ | ||
public Builder metadata(Map<String, String> metadata) { | ||
this.metadata = Optional.of(metadata); | ||
return this; | ||
} | ||
|
||
public ModifyRunRequest build() { | ||
return new ModifyRunRequest(metadata); | ||
} | ||
} | ||
} |
Oops, something went wrong.