这是indexloc提供的服务,不要输入任何密码
Skip to content

delete assistant thread message endpoiont support #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public interface OpenAiApi {
@POST("threads/{thread_id}/messages/{message_id}")
Single<Message> modifyMessage(@Path("thread_id") String threadId, @Path("message_id") String messageId, @Body ModifyMessageRequest request);

@Headers({"OpenAI-Beta: assistants=v2"})
@DELETE("threads/{thread_id}/messages/{message_id}")
Single<DeleteResult> deleteMessage(@Path("thread_id") String threadId, @Path("message_id") String messageId);


@Headers("OpenAI-Beta: assistants=v2")
@POST("threads/{thread_id}/runs")
Expand Down
22 changes: 21 additions & 1 deletion example/src/main/java/example/ChatExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static void main(String[] args) {
// gptVision();
// toolChat();
// functionChat();
streamChatWithTool();
// streamChatWithTool();
gpt4oVision();
}

static void simpleChat() {
Expand Down Expand Up @@ -152,6 +153,25 @@ static void gptVision() {
System.out.println(choice.getMessage().getContent());
}

static void gpt4oVision() {
OpenAiService service = new OpenAiService(Duration.ofSeconds(20));
final List<ChatMessage> messages = new ArrayList<>();
//Here, the imageMessage is intended for image recognition
final ChatMessage imageMessage = UserMessage.buildImageMessage("What's in this image?",
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg");
messages.add(imageMessage);

ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
.model("gpt-4o")
.messages(messages)
.n(1)
.maxTokens(300)
.build();
ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
System.out.println(choice.getMessage().getContent());

}


static void streamChatWithTool() {
OpenAiService service = new OpenAiService(Duration.ofSeconds(30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ public OpenAiResponse<Message> listMessages(String threadId, MessageListSearchPa
return execute(api.listMessages(threadId, queryParameters));
}

public DeleteResult deleteMessage(String threadId, String messageId) {
return execute(api.deleteMessage(threadId, messageId));
}


public Run createRun(String threadId, RunCreateRequest runCreateRequest) {
return execute(api.createRun(threadId, runCreateRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void listMessages() {
createTestMessage(separateThreadId);
List<Message> messages = service.listMessages(separateThreadId, new MessageListSearchParameters()).getData();
assertEquals(3, messages.size());

service.deleteMessage(separateThreadId, messages.get(0).getId());
List<Message> messagesAfterDelete = service.listMessages(separateThreadId, new MessageListSearchParameters()).getData();
assertEquals(2, messagesAfterDelete.size());

DeleteResult deleteResult = service.deleteThread(separateThreadId);
assertTrue(deleteResult.isDeleted());
}
Expand Down