Skip to content

ResponseInputFileExample.java #446

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add example PDF file and fix lint
  • Loading branch information
nuclear-bean committed Apr 19, 2025
commit 8262534f762906bb7a748571b24e7ad70ef3b6fe
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.ResponseInputFile;
import com.openai.models.responses.ResponseInputItem;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -22,7 +21,7 @@ public static void main(String[] args) throws IOException {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();

// Read file content and construct data URI String
File file = new File("/absolute/path/to/your/file.pdf");
File file = new File("openai-java-example/src/main/resources/pdflatex-image.pdf");
byte[] fileContent = Files.readAllBytes(file.toPath());
String base64String = Base64.getEncoder().encodeToString(fileContent);
String dataUri = "data:application/pdf;base64," + base64String;
Expand All @@ -49,5 +48,4 @@ public static void main(String[] args) throws IOException {
.flatMap(content -> content.outputText().stream())
.forEach(outputText -> System.out.println(outputText.text()));
}

}
}
Binary file not shown.