-
Notifications
You must be signed in to change notification settings - Fork 5
feat: support file parsing sync #60
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
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ddd26b7
add sdk: file parsing
a9744c0
Merge remote-tracking branch 'newRemote/main' into feature/file-parsing
9196eea
add sdk: file parsing
24b9ed6
add sdk: file parsing sync
24767ca
Merge remote-tracking branch 'origin/main' into feature/file-parsing-2nd
6697eae
add sdk: file parsing sync
8e31398
Merge remote-tracking branch 'origin/main' into feature/file-parsing-2nd
547d5f7
Synchronous parsing interface for tool type "prime"
81ee306
fix:base url
5f6e28e
fix:base url
e196338
fix:comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
samples/src/main/ai.z.openapi.samples/FileParsingSyncExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package ai.z.openapi.samples; | ||
|
|
||
| import ai.z.openapi.ZaiClient; | ||
| import ai.z.openapi.service.fileparsing.FileParsingDownloadResponse; | ||
| import ai.z.openapi.service.fileparsing.FileParsingUploadReq; | ||
| import ai.z.openapi.utils.StringUtils; | ||
|
|
||
| public class FileParsingSyncExample { | ||
|
|
||
| public static void main(String[] args) { | ||
| // It is recommended to set the API Key using an environment variable | ||
| // export ZAI_API_KEY=your.api_key | ||
| // ZaiClient client = ZaiClient.builder().build(); | ||
|
|
||
| // Alternatively, the API Key can be specified directly in the code | ||
| ZaiClient client = ZaiClient.builder() | ||
| .apiKey("API Key") | ||
| .build(); | ||
|
|
||
| try { | ||
| System.out.println("=== Example: Creating file parsing task ==="); | ||
|
|
||
| String filePath = "your file path"; | ||
| FileParsingDownloadResponse result = syncFileParsingTaskExample(client, filePath, "pdf", "prime-sync"); | ||
|
|
||
| System.out.println("Parsing task created successfully, TaskId: " + result.getData().getTaskId()); | ||
| System.out.println("File content: " + result.getData().getContent()); | ||
| System.out.println("Download link: " + result.getData().getParsingResultUrl()); | ||
|
|
||
| } catch (Exception e) { | ||
| System.err.println("Exception occurred: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Example: Create parsing task (upload file and parse) | ||
| * | ||
| * @param client ZaiClient instance | ||
| * @return Parsing task's taskId | ||
| */ | ||
| private static FileParsingDownloadResponse syncFileParsingTaskExample(ZaiClient client, String filePath, String fileType, String toolType) { | ||
| if (StringUtils.isEmpty(filePath)) { | ||
| System.err.println("Invalid file path."); | ||
| return null; | ||
| } | ||
| try { | ||
| FileParsingUploadReq uploadReq = FileParsingUploadReq.builder() | ||
| .filePath(filePath) | ||
| .fileType(fileType) // Supported types: pdf, docx, etc. | ||
| .toolType(toolType) // Parsing tool type: lite, prime, expert | ||
| .build(); | ||
|
|
||
| System.out.println("Uploading file and creating parsing task..."); | ||
| return client.fileParsing().syncParse(uploadReq); | ||
| } catch (Exception e) { | ||
| System.err.println("File parsing task error: " + e.getMessage()); | ||
| } | ||
| // Returning null means task creation failed | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix here