Skip to content

Add non-image file chat completion example #483

Open
@xx-404

Description

@xx-404

Now , i known how to invoke chat with a imgage ,the code below

OpenAIClient client = OpenAIOkHttpClient.builder() .apiKey(apiKey) .baseUrl(baseUrl) .build(); // ClassLoader classloader = Thread.currentThread().getContextClassLoader(); // byte[] logoBytes = classloader.getResource("1.png").openStream().readAllBytes(); String logoBase64Url = "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(bytes); ChatCompletionContentPart logoContentPart = ChatCompletionContentPart.ofImageUrl(ChatCompletionContentPartImage.builder() .imageUrl(ChatCompletionContentPartImage.ImageUrl.builder() .url(logoBase64Url) .build()) .build()); ChatCompletionContentPart questionContentPart = ChatCompletionContentPart.ofText(ChatCompletionContentPartText.builder() .text(msg) .build()); ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder() .model(model) // .maxCompletionTokens(2048) .addUserMessageOfArrayOfContentParts(List.of(questionContentPart, logoContentPart)) .build();

But How to invoke chat with a file sush as pdf or docx?
I find the api is
ChatCompletionContentPart logoContentPart = ChatCompletionContentPart.ofFile(ChatCompletionContentPart.File.builder());
but i do not known how to complete it,could you give a example? thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions