Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

390 Added runs #401

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/MessageCreation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class MessageCreation {
@JsonProperty("message_id")
String messageId;
}
45 changes: 45 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/Run.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Run {

@JsonProperty("assistant_id")
String assistantId;
@JsonProperty("cancelled_at")
Long cancelledAt;
@JsonProperty("completed_at")
Long completedAt;
@JsonProperty("created_at")
Long createdAt;
@JsonProperty("expires_at")
Long expiresAt;
@JsonProperty("failed_at")
Long failedAt;
@JsonProperty("file_ids")
List<String> fileIds;
String id;
String instructions;
@JsonProperty("last_error")
String lastError;
Map<String, String> metadata;
String model;
String object;
@JsonProperty("started_at")
Long startedAt;
String status;
@JsonProperty("thread_id")
String threadId;
List<Tool> tools;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.theokanning.openai.runs;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class RunCreateRequest {
String assistantId;

// Optional
String model;
String instructions;
List<Tool> tools;
Map<String, String> metadata;
}
39 changes: 39 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/RunStep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class RunStep {

@JsonProperty("assistant_id")
String assistantId;
@JsonProperty("canelled_at")
Long cancelledAt;
@JsonProperty("completed_at")
Long completedAt;
@JsonProperty("created_at")
Long createdAt;
@JsonProperty("expired_at")
Long expiredAt;
@JsonProperty("failed_at")
Long failedAt;
String id;
@JsonProperty("last_error")
String lastError;
String object;
@JsonProperty("run_id")
String runId;
String status;
@JsonProperty("step_details")
StepDetails stepDetails;
@JsonProperty("thread_id")
String threadId;
String type;
}
17 changes: 17 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/RunSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

public class RunSteps {

String object;
List<RunSteps> data;
@JsonProperty("first_id")
String firstId;
@JsonProperty("last_id")
String lastId;
@JsonProperty("has_more")
boolean hasMore;
}
17 changes: 17 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/Runs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

public class Runs {

String object;
List<Runs> data;
@JsonProperty("first_id")
String firstId;
@JsonProperty("last_id")
String lastId;
@JsonProperty("has_more")
boolean hasMore;
}
18 changes: 18 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/StepDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.theokanning.openai.runs;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class StepDetails {

@JsonProperty("message_creation")
MessageCreation messageCreation;
String type;
}
15 changes: 15 additions & 0 deletions api/src/main/java/com/theokanning/openai/runs/Tool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.theokanning.openai.runs;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Tool {

String type;
}
10 changes: 10 additions & 0 deletions client/src/main/java/com/theokanning/openai/client/OpenAiApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.theokanning.openai.model.Model;
import com.theokanning.openai.moderation.ModerationRequest;
import com.theokanning.openai.moderation.ModerationResult;
import com.theokanning.openai.runs.Run;
import com.theokanning.openai.runs.RunCreateRequest;
import com.theokanning.openai.threads.Thread;
import com.theokanning.openai.threads.ThreadRequest;
import io.reactivex.Single;
Expand Down Expand Up @@ -278,4 +280,12 @@ public interface OpenAiApi {
@GET("/v1/threads/{thread_id}/messages/{message_id}/files")
Single<OpenAiResponse<MessageFile>> listMessageFiles(@Path("thread_id") String threadId, @Path("message_id") String messageId, @QueryMap Map<String, Object> filterRequest);

@Headers("OpenAI-Beta: assistants=v1")
@POST("/v1/threads/{thread_id}/runs")
Single<Run> createRun(@Path("thread_id") String threadId, @Body RunCreateRequest runCreateRequest);

@Headers("OpenAI-Beta: assistants=v1")
@GET("/v1/threads/{thread_id}/runs/{run_id}")
Single<Run> retrieveRun(@Path("thread_id") String threadId, @Path("run_id") String runId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import com.fasterxml.jackson.databind.node.TextNode;
import com.theokanning.openai.*;
import com.theokanning.openai.assistants.*;
import com.theokanning.openai.audio.CreateSpeechRequest;
import com.theokanning.openai.audio.CreateTranscriptionRequest;
import com.theokanning.openai.audio.CreateTranslationRequest;
import com.theokanning.openai.audio.TranscriptionResult;
import com.theokanning.openai.audio.TranslationResult;
import com.theokanning.openai.audio.*;
import com.theokanning.openai.billing.BillingUsage;
import com.theokanning.openai.billing.Subscription;
import com.theokanning.openai.client.OpenAiApi;
Expand Down Expand Up @@ -42,6 +38,8 @@
import com.theokanning.openai.model.Model;
import com.theokanning.openai.moderation.ModerationRequest;
import com.theokanning.openai.moderation.ModerationResult;
import com.theokanning.openai.runs.Run;
import com.theokanning.openai.runs.RunCreateRequest;
import com.theokanning.openai.threads.Thread;
import com.theokanning.openai.threads.ThreadRequest;
import io.reactivex.BackpressureStrategy;
Expand Down Expand Up @@ -166,7 +164,7 @@ public List<File> listFiles() {

public File uploadFile(String purpose, String filepath) {
java.io.File file = new java.io.File(filepath);
RequestBody purposeBody = RequestBody.create(okhttp3.MultipartBody.FORM, purpose);
RequestBody purposeBody = RequestBody.create(MultipartBody.FORM, purpose);
RequestBody fileBody = RequestBody.create(MediaType.parse("text"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", filepath, fileBody);

Expand Down Expand Up @@ -364,7 +362,7 @@ public ModerationResult createModeration(ModerationRequest request) {
public ResponseBody createSpeech(CreateSpeechRequest request) {
return execute(api.createSpeech(request));
}

public Assistant createAssistant(AssistantRequest request) {
return execute(api.createAssistant(request));
}
Expand All @@ -382,7 +380,8 @@ public DeleteResult deleteAssistant(String assistantId) {
}

public ListAssistant<Assistant> listAssistants(ListAssistantQueryRequest filterRequest) {
Map<String, Object> queryParameters = mapper.convertValue(filterRequest, new TypeReference<Map<String, Object>>() {});
Map<String, Object> queryParameters = mapper.convertValue(filterRequest, new TypeReference<Map<String, Object>>() {
});
return execute(api.listAssistants(queryParameters));
}

Expand All @@ -399,7 +398,8 @@ public DeleteResult deleteAssistantFile(String assistantId, String fileId) {
}

public ListAssistant<Assistant> listAssistantFiles(String assistantId, ListAssistantQueryRequest filterRequest) {
Map<String, Object> queryParameters = mapper.convertValue(filterRequest, new TypeReference<Map<String, Object>>() {});
Map<String, Object> queryParameters = mapper.convertValue(filterRequest, new TypeReference<Map<String, Object>>() {
});
return execute(api.listAssistantFiles(assistantId, queryParameters));
}

Expand All @@ -424,35 +424,44 @@ public Message createMessage(String threadId, MessageRequest request) {
}

public Message retrieveMessage(String threadId, String messageId) {
return execute(api.retrieveMessage(threadId,messageId));
return execute(api.retrieveMessage(threadId, messageId));
}

public Message modifyMessage(String threadId, String messageId, ModifyMessageRequest request) {
return execute(api.modifyMessage(threadId,messageId, request));
return execute(api.modifyMessage(threadId, messageId, request));
}

public OpenAiResponse<Message> listMessages(String threadId) {
return execute(api.listMessages(threadId));
}

public OpenAiResponse<Message> listMessages(String threadId, ListSearchParameters params) {
Map<String, Object> queryParameters = mapper.convertValue(params, new TypeReference<Map<String, Object>>() {});
return execute(api.listMessages(threadId,queryParameters));
Map<String, Object> queryParameters = mapper.convertValue(params, new TypeReference<Map<String, Object>>() {
});
return execute(api.listMessages(threadId, queryParameters));
}

public MessageFile retrieveMessageFile(String threadId, String messageId, String fileId) {
return execute(api.retrieveMessageFile(threadId,messageId, fileId));
return execute(api.retrieveMessageFile(threadId, messageId, fileId));
}

public OpenAiResponse<MessageFile> listMessageFiles(String threadId, String messageId) {
return execute(api.listMessageFiles(threadId,messageId));
return execute(api.listMessageFiles(threadId, messageId));
}

public OpenAiResponse<MessageFile> listMessageFiles(String threadId, String messageId, ListSearchParameters params) {
Map<String, Object> queryParameters = mapper.convertValue(params, new TypeReference<Map<String, Object>>() {});
return execute(api.listMessageFiles(threadId,messageId, queryParameters));
Map<String, Object> queryParameters = mapper.convertValue(params, new TypeReference<Map<String, Object>>() {
});
return execute(api.listMessageFiles(threadId, messageId, queryParameters));
}

public Run createRun(String threadId, RunCreateRequest runCreateRequest) {
return execute(api.createRun(threadId, runCreateRequest));
}

public Run retrieveRun(String threadId, String runId) {
return execute(api.retrieveRun(threadId, runId));
}

/**
* Calls the Open AI api, returns the response, and parses error messages if the request fails
Expand Down
Loading