CJCrafter/ChatGPT-Java-API

Streaming for assistants

CJCrafter opened this issue · 3 comments

Discussed in #47

Originally posted by Nicodm13 March 16, 2024
Hello!

Do you have any plans on adding stream support for assistants?

Thanks in advance.

I have modified your code to implement the stream boolean in the RunRequest.

Skærmbillede 2024-04-11 152104

However when i run the code, i receive the error below. I have been unable to figure out why this is happening. Do you have any idea what could cause this?

Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'event': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"event: thread.run.created
data: {"id":"run_onav4ZIb9bMwSU5e8DGnKPx2","object":"thread.run","created_at":1712841742,"assistant_id":"asst_ngOCymSqqeLGXIxl4JuOnnwh","thread_id":"thread_SY9ylc4cXucEc1BH3QRMiRqz","status":"queued","started_at":null,"expires_at":1712842342,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo-preview","instructions":"--REDACTED--"[truncated 16481 chars]; line: 1, column: 6]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2477)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:760)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:3041)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2082)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:808)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4912)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4818)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3772)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3740)
	at com.cjcrafter.openai.RequestHelper.executeRequest(RequestHelper.kt:78)
	at com.cjcrafter.openai.threads.runs.RunHandlerImpl.create(RunHandlerImpl.kt:12)
	at assistant.ThreadExample.main(ThreadExample.java:51)

> Task :examples:ThreadExample.main() FAILED

Execution failed for task ':examples:ThreadExample.main()'.
> Process 'command 'C:\Program Files\Java\jdk-20\bin\java.exe'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.6/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 35s
8 actionable tasks: 7 executed, 1 up-to-date

Yes, it's not as simple as changing a boolean. The format of the data changes entirely.