-
Notifications
You must be signed in to change notification settings - Fork 0
add explain image preprocessing action #29
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -82,15 +82,16 @@ private async Task<PreprocessingActionData[]> ProgressPreprocessingActions(strin | |||||
| foreach (var actionData in actionArrayData) | ||||||
| { | ||||||
| if (actionData is not JObject data) continue; | ||||||
| try | ||||||
|
|
||||||
| var actionType = data.Value<string>("action"); | ||||||
| if (string.IsNullOrWhiteSpace(actionType)) | ||||||
| { | ||||||
| var actionType = data.Value<string>("action"); | ||||||
| if (string.IsNullOrWhiteSpace(actionType)) | ||||||
| { | ||||||
| Logger.LogWarning("Unable to parse the JSON: {Json}", data.ToString()); | ||||||
| continue; | ||||||
| } | ||||||
| Logger.LogWarning("Unable to parse the JSON: {Json}", data.ToString()); | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| try | ||||||
| { | ||||||
| var resultData = actionType switch | ||||||
| { | ||||||
| "web_search" => await PreprocessingWebSearch(data).ConfigureAwait(false), | ||||||
|
|
@@ -104,6 +105,7 @@ private async Task<PreprocessingActionData[]> ProgressPreprocessingActions(strin | |||||
| .ConfigureAwait(false), | ||||||
| "pixiv_user_info" => await PreprocessingPixivQueryUserInfo(data).ConfigureAwait(false), | ||||||
| "pixiv_illust_info" => await PreprocessingPixivQueryIllustInfo(data).ConfigureAwait(false), | ||||||
| "explain_image" => await PreprocessingExplainImage(data).ConfigureAwait(false), | ||||||
| _ => null, | ||||||
| }; | ||||||
|
|
||||||
|
|
@@ -113,6 +115,10 @@ private async Task<PreprocessingActionData[]> ProgressPreprocessingActions(strin | |||||
| catch (Exception ex) | ||||||
| { | ||||||
| Logger.LogError(ex, "Error while processing the JSON action: {Json}", data.ToString()); | ||||||
| result.Add(new(actionType, $""" | ||||||
| [Failed Action: {actionType}] | ||||||
| {ex.Message} | ||||||
| """)); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -407,6 +413,25 @@ await ChatClientProvider.ExplainImageAsync( | |||||
| return new($"Get Pixiv Illust Info: {param.Id}", sb.ToString()); | ||||||
| } | ||||||
|
|
||||||
| private async Task<PreprocessingActionData> PreprocessingExplainImage(JObject? data) | ||||||
| { | ||||||
| if (data is null || !data.TryGetValue("param", out var paramValue) || paramValue is not JObject paramToken) | ||||||
| throw new InvalidDataException("Invalid JSON data for explain image action"); | ||||||
| var param = paramToken.ToObject<PreprocessingActionParam.ExplainImageActionParam>() | ||||||
| ?? throw new InvalidDataException("Invalid JSON data for explain image action"); | ||||||
| if (string.IsNullOrWhiteSpace(param.Url)) | ||||||
| throw new InvalidDataException("Invalid URL for explain image action"); | ||||||
| var (success, result) = await ChatClientProvider.ExplainImageAsync(param.Url); | ||||||
| return !success | ||||||
| ? throw new InvalidDataException($"Unable to explain image: {result}") | ||||||
|
||||||
| ? throw new InvalidDataException($"Unable to explain image: {result}") | |
| ? throw new InvalidDataException("Unable to explain image at this time. Please try again later.") |
Oops, something went wrong.
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.
The URL validation only checks for null/empty/whitespace but doesn't validate if it's a properly formatted URL. Consider adding URL format validation using Uri.TryCreate() to catch malformed URLs early.