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

Assistant : OpenAiApi.listRunSteps : @Body not supported on @Get #411

Closed
Aelentel opened this issue Nov 17, 2023 · 5 comments
Closed

Assistant : OpenAiApi.listRunSteps : @Body not supported on @Get #411

Aelentel opened this issue Nov 17, 2023 · 5 comments

Comments

@Aelentel
Copy link

Aelentel commented Nov 17, 2023

Hi, first and foremost, thanks everyone for this project :)

i encountered that issue when testing the Assistant API on v0.18.1

here's the exception (fluff removed)

java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.
    for method OpenAiApi.listRunSteps
	at retrofit2.Utils.methodError(Utils.java:54)
	at retrofit2.Utils.methodError(Utils.java:43)
	at retrofit2.RequestFactory$Builder.build(RequestFactory.java:213)
	at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67)
	at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26)
	at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
	at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
	at jdk.proxy2/jdk.proxy2.$Proxy27.listRunSteps(Unknown Source)
	at com.theokanning.openai.service.OpenAiService.listRunSteps(OpenAiService.java:494)

and the test code (GptService.getService() return the OpenAiService already initialized)

        @Test
	void test_execute_Assistant() throws InterruptedException
	{
		var service=gptService.getService();
		var assistant = service.retrieveAssistant("<Assistant ID>");
		
		var message=MessageRequest.builder()
				.role(ChatMessageRole.USER.value())
				.content("QUESTION: explain the Strategy pattern")
				.build();
		
		var threadRequest=ThreadRequest.builder()
				.messages(List.of(message))
				.build();
		
		
		var thread_run = CreateThreadAndRunRequest.builder()
				.assistantId(assistant.getId())
				.model(assistant.getModel())
				.thread(threadRequest)
				.build();
		
		var run = service.createThreadAndRun(thread_run);
		// run status
		// queued|in_progress|completed| failed ?
		var running=Set.of("queued","in_progress");
		while (running.contains(run.getStatus()))
		{
			log.info(run.toString());
			Thread.currentThread().sleep(Duration.ofMillis(1000));
			run =  service.retrieveRun(run.getThreadId(), run.getId());
		}
		log.info("run {}",run.toString());
		var runStep=service.listRunSteps(run.getThreadId(),run.getId(),ListSearchParameters.builder().build());
		log.info("thread {}",runStep.toString());
		
	}
@Aelentel Aelentel changed the title Assistant Retrieve Steps : @Body not supported on @Get Assistant : OpenAiApi.listRunSteps : @Body not supported on @Get Nov 17, 2023
@Aelentel
Copy link
Author

Aelentel commented Nov 17, 2023

just adding that i got the response nonetheless by using listMessage api, so if it can help other ppl, here's the code i'm using.

but it'll be slightly less cumbersome to retrieve the step as it's contain the messageId that have been generated by the assistant.

		var messageList=service.listMessages(run.getThreadId());
		String response=
				messageList.getData()
					.stream()
					.filter(t -> ChatMessageRole.ASSISTANT.value().equals(t.getRole()))
					.flatMap(t -> t.getContent().stream())
					.filter(t -> "text".equals(t.getType()))
					.map(t -> t.getText().getValue())
					.findFirst()
					.orElse(null);

@vacuityv
Copy link
Contributor

@Aelentel I will check this and if I know why I wiill try to fix it

@vacuityv
Copy link
Contributor

@Aelentel I will fix this.

@vacuityv
Copy link
Contributor

A pr here: #414

@TheoKanning
Copy link
Owner

Fixed in 0.18.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants