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

Commit

Permalink
Update to version 0.18.0 (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoKanning authored Nov 16, 2023
1 parent 741cfe2 commit 56b302b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.theokanning.openai-gpt3-java
VERSION_NAME=0.17.0
VERSION_NAME=0.18.0

POM_URL=https://github.com/theokanning/openai-java
POM_SCM_URL=https://github.com/theokanning/openai-java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ static void setup() {

@AfterAll
static void teardown() {
// todo delete thread
try {
service.deleteThread(threadId);
} catch (Exception e) {
// ignore
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
import com.theokanning.openai.messages.MessageRequest;
import com.theokanning.openai.threads.Thread;
import com.theokanning.openai.threads.ThreadRequest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import java.util.*;

import static org.junit.jupiter.api.Assertions.*;


@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ThreadTest {

String token = System.getenv("OPENAI_TOKEN");
OpenAiService service = new OpenAiService(token);

static String threadId;

@Test
@Order(1)
void createThread() {
MessageRequest messageRequest = MessageRequest.builder()
.content("Hello")
Expand All @@ -27,34 +33,34 @@ void createThread() {
.build();

Thread thread = service.createThread(threadRequest);
System.out.println(thread.getId());
threadId = thread.getId();
assertEquals("thread", thread.getObject());
}

@Test
@Order(2)
void retrieveThread() {
String threadId = "thread_K82pTg9kmhxpplGqalW6IHlc";

Thread thread = service.retrieveThread(threadId);
System.out.println(thread.getMetadata());
assertEquals("thread", thread.getObject());
}

@Test
@Order(3)
void modifyThread() {
String threadId = "thread_K82pTg9kmhxpplGqalW6IHlc";
Map<String, String> metadata = new HashMap<>();
metadata.put("action", "modify");
ThreadRequest threadRequest = ThreadRequest.builder()
.metadata(metadata)
.build();
Thread thread = service.modifyThread(threadId, threadRequest);
assertEquals("thread", thread.getObject());
assertEquals("modify", thread.getMetadata().get("action"));
}

@Test
@Order(4)
void deleteThread() {
String threadId = "thread_K82pTg9kmhxpplGqalW6IHlc";
DeleteResult deleteResult = service.deleteThread(threadId);
assertEquals("thread.deleted", deleteResult.getObject());
}
Expand Down

0 comments on commit 56b302b

Please sign in to comment.