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

fix(forge, agent): Resolve several issues for Chinese language & region #7200

Conversation

WangShaoyu1
Copy link

update:
1、add response header Content-Type:application/json,charest=UT…F-8, solve cannot display chinese word

2、update the openai api key pattern, like sk-wa-xxx

3、add Optional for additional_input, in TaskRequestBody and StepRequestBody, to avoid 422 status in api

Background

1、cannot show the Chinese word in the fluuter web subproject. Add response data header Content-Type:charset-UTF-8
2、I get a new openAI key,like sk-wa-xxxx, it can work in the chatgpt page ,but cannot be Verified in our project
3、In the flutter for web project,you enter the task in the chat Input, the api will return 422 status, because that the additional_input can not be null, so I add Optional in the file: forge/agent_protocol/models/task.py

PR Quality Scorecard ✨

  • Have you used the PR description template?   +2 pts
  • Is your pull request atomic, focusing on a single change?   +5 pts
  • Have you linked the GitHub issue(s) that this PR addresses?   +5 pts
  • Have you documented your changes clearly and comprehensively?   +5 pts
  • Have you changed or added a feature?   -4 pts
    • Have you added/updated corresponding documentation?   +4 pts
    • Have you added/updated corresponding integration tests?   +5 pts
  • Have you changed the behavior of AutoGPT?   -5 pts
    • Have you also run agbenchmark to verify that these changes do not regress performance?   +10 pts

…F-8, solve cannot display chinese word

2、update the openai api key pattern, like sk-wa-xxx
3、add Optional for additional_input, in TaskRequestBody and StepRequestBody, to avoid 422 status in api
@WangShaoyu1 WangShaoyu1 requested a review from a team as a code owner June 8, 2024 13:23
@WangShaoyu1 WangShaoyu1 requested review from Bentlybro and aarushik93 and removed request for a team June 8, 2024 13:23
Copy link

netlify bot commented Jun 8, 2024

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 23dab79
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/669f8479ee8cbc000724adb5

Copy link

codecov bot commented Jun 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 33.77%. Comparing base (62c420e) to head (23dab79).
Report is 179 commits behind head on master.

Files Patch % Lines
autogpt/autogpt/app/agent_protocol_server.py 0.00% 9 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (62c420e) and HEAD (23dab79). Click for more details.

HEAD has 8 uploads less than BASE
Flag BASE (62c420e) HEAD (23dab79)
macOS 4 2
Linux 2 1
forge 4 0
Windows 2 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #7200       +/-   ##
===========================================
- Coverage   53.81%   33.77%   -20.04%     
===========================================
  Files         124       18      -106     
  Lines        7021     1273     -5748     
  Branches      909      191      -718     
===========================================
- Hits         3778      430     -3348     
+ Misses       3110      815     -2295     
+ Partials      133       28      -105     
Flag Coverage Δ
Linux 33.77% <0.00%> (-19.79%) ⬇️
Windows 33.62% <0.00%> (-16.80%) ⬇️
autogpt-agent 33.77% <0.00%> (-0.22%) ⬇️
forge ?
macOS 33.77% <0.00%> (-19.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ntindle ntindle requested a review from kcze June 8, 2024 15:27
Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR! I wasn't aware of the issue with Chinese characters, luckily that's a straight-forward fix.

In addition to the comments below: the linting check fails at the moment, please fix the issues reported by the check.

forge/forge/config/config.py Outdated Show resolved Hide resolved
forge/forge/agent_protocol/models/task.py Outdated Show resolved Hide resolved
autogpt/autogpt/app/agent_protocol_server.py Outdated Show resolved Hide resolved
response.headers["Content-Type"] = "application/json ; charset=UTF-8"
return response

app.middleware("http")(add_custom_header)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.middleware is intended to use as a decorator, like:

@app.middleware("http")
async def add_custom_header(request: Request, call_next: Callable) -> Response:
    response = await call_next(request)
    response.headers["Content-Type"] = "application/json; charset=utf-8"
    return response

autogpt/autogpt/app/agent_protocol_server.py Show resolved Hide resolved
@Pwuts Pwuts added the internationalization Multi-language support label Jun 8, 2024
@Pwuts Pwuts changed the title frontend project can support Chinese better by serval improment fix(forge, agent): Resolve several issues for Chinese language & region Jun 8, 2024
@kcze
Copy link
Contributor

kcze commented Jun 9, 2024

I cannot find any information about api keys with sk-wa- prefix.
This doesn't interfere with anything I'm doing.

@ntindle
Copy link
Member

ntindle commented Jun 13, 2024

Just made a new key and the service keys for projects are sk-(whatever-service-account-name-is)-random-Blbk-random

updated support in #7214

@github-actions github-actions bot removed the Forge label Jun 13, 2024
@Mirei124
Copy link

Maybe modifying the frontend is a better solution.

From 5962f04a543a2cddd9a25dbe59f55191b4506420 Mon Sep 17 00:00:00 2001
From: Mirei124 <[email protected]>
Date: Tue, 23 Jul 2024 17:23:39 +0800
Subject: [PATCH] Fix Chinese garbled characters

---
 frontend/lib/utils/rest_api_utility.dart | 6 +++---
 frontend/lib/utils/uri_utility.dart      | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/frontend/lib/utils/rest_api_utility.dart b/frontend/lib/utils/rest_api_utility.dart
index ab83ddf..991db87 100644
--- a/frontend/lib/utils/rest_api_utility.dart
+++ b/frontend/lib/utils/rest_api_utility.dart
@@ -32,7 +32,7 @@ class RestApiUtility {
     final effectiveBaseUrl = _getEffectiveBaseUrl(apiType);
     final response = await http.get(Uri.parse('$effectiveBaseUrl/$endpoint'));
     if (response.statusCode == 200) {
-      return json.decode(response.body);
+      return json.decode(utf8.decode(response.bodyBytes));
     } else {
       throw Exception('Failed to load data');
     }
@@ -48,7 +48,7 @@ class RestApiUtility {
       headers: {"Content-Type": "application/json"},
     );
     if (response.statusCode == 200 || response.statusCode == 201) {
-      return json.decode(response.body);
+      return json.decode(utf8.decode(response.bodyBytes));
     } else {
       // TODO: We are bubbling up the full response to show better errors on the UI.
       // Let's put some thought into how we would like to structure this.
@@ -66,7 +66,7 @@ class RestApiUtility {
       headers: {"Content-Type": "application/json"},
     );
     if (response.statusCode == 200 || response.statusCode == 201) {
-      return json.decode(response.body);
+      return json.decode(utf8.decode(response.bodyBytes));
     } else {
       throw Exception('Failed to update data with PUT request');
     }
diff --git a/frontend/lib/utils/uri_utility.dart b/frontend/lib/utils/uri_utility.dart
index ace65f0..5aebf10 100644
--- a/frontend/lib/utils/uri_utility.dart
+++ b/frontend/lib/utils/uri_utility.dart
@@ -69,7 +69,7 @@ class UriUtility {
       return false;
     }
 
-    var data = json.decode(response.body);
+    var data = json.decode(utf8.decode(response.bodyBytes));
     return data is Map && data['full_name'] == '$user/$repo';
   }
 }
-- 
2.45.2

@Swiftyos
Copy link
Contributor

@WangShaoyu1 Thank you for this change, we never managed to get it merged in dispite it being a great addition :(

We are going to be removing the agent protocol server very soon in favour of the work going on in the rnd folder.

If you are able to provide any help in making sure the rnd/autogpt_builder can support Chinese language we would really love the help!

@Swiftyos Swiftyos closed this Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants