Skip to content
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

图片上传接口失败 #31

Open
dlwfeng opened this issue Jan 24, 2025 · 0 comments
Open

图片上传接口失败 #31

dlwfeng opened this issue Jan 24, 2025 · 0 comments

Comments

@dlwfeng
Copy link

dlwfeng commented Jan 24, 2025

示例代码example/src/main/java/example/chat/ChatWithImageExample.java

public static void main(String[] args) {

        // Get an access_token through personal access token or oauth.
        String token = "xxx";
        String botID = "123";
        String userID = "asd";

        TokenAuth authCli = new TokenAuth(token);

        // Init the Coze client through the access_token.
        CozeAPI coze = new CozeAPI.Builder()
                .baseURL("https://www.coze.cn/")
                .auth(authCli)
                .readTimeout(10000)
                .build();

        // Call the upload file interface to get the image id.
        String imagePath = "D:\\test.jpeg";
        FileInfo imageInfo = coze.files().upload(UploadFileReq.of(imagePath)).getFileInfo();

        /*
         * Step one, create chat
         * Call the coze.chat().stream() method to create a chat. The create method is a streaming
         * chat and will return a Flowable ChatEvent. Developers should iterate the iterator to get
         * chat event and handle them.
         * */
        CreateChatReq req =
                CreateChatReq.builder()
                        .botID(botID)
                        .userID(userID)
                        .messages(
                                Collections.singletonList(
                                        Message.buildUserQuestionObjects(
                                                Arrays.asList(
                                                        MessageObjectString.buildText("Describe this picture"),
                                                        MessageObjectString.buildImageByID(imageInfo.getID())))))
                        .build();

        Flowable<ChatEvent> resp = coze.chat().stream(req);
        resp.blockingForEach(
                event -> {
                    if (ChatEventType.CONVERSATION_MESSAGE_DELTA.equals(event.getEvent())) {
                        System.out.print(event.getMessage().getContent());
                    }
                });
    }

pom

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.coze</groupId>
            <artifactId>coze-api</artifactId>
            <version>0.2.1</version>
        </dependency>
    </dependencies>

错误提示

Exception in thread "main" java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 2]
	at com.coze.openapi.service.utils.Utils.execute(Utils.java:44)
	at com.coze.openapi.service.service.file.FileService.uploadFile(FileService.java:61)
	at com.coze.openapi.service.service.file.FileService.upload(FileService.java:39)
	at Chat.main(Chat.java:42)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:749)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:673)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:2082)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:805)
	at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:357)
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2095)
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1513)
	at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:33)
	at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:23)
	at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
	at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
	at com.coze.openapi.service.service.APIResponseCallAdapter$1.execute(APIResponseCallAdapter.java:35)
	at com.coze.openapi.service.utils.Utils.execute(Utils.java:22)
	... 3 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant