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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
14 changes: 12 additions & 2 deletions autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from uuid import uuid4

import orjson
from fastapi import APIRouter, FastAPI, UploadFile
from typing import Callable
from fastapi import APIRouter, FastAPI, UploadFile, FastAPI, Request, Response

Check warning on line 10 in autogpt/autogpt/app/agent_protocol_server.py

View check run for this annotation

Codecov / codecov/patch

autogpt/autogpt/app/agent_protocol_server.py#L9-L10

Added lines #L9 - L10 were not covered by tests
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse, StreamingResponse
from fastapi.staticfiles import StaticFiles
Expand Down Expand Up @@ -40,6 +41,15 @@
logger = logging.getLogger(__name__)


def create_middleware(app: FastAPI):
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

Check warning on line 48 in autogpt/autogpt/app/agent_protocol_server.py

View check run for this annotation

Codecov / codecov/patch

autogpt/autogpt/app/agent_protocol_server.py#L44-L48

Added lines #L44 - L48 were not covered by tests

app.middleware("http")(add_custom_header)

Check warning on line 50 in autogpt/autogpt/app/agent_protocol_server.py

View check run for this annotation

Codecov / codecov/patch

autogpt/autogpt/app/agent_protocol_server.py#L50

Added line #L50 was not covered by tests
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



class AgentProtocolServer:
_task_budgets: dict[str, ModelProviderBudget]

Expand Down Expand Up @@ -76,7 +86,7 @@
"Modified version of The Agent Protocol.",
version="v0.4",
)

create_middleware(app)

Check warning on line 89 in autogpt/autogpt/app/agent_protocol_server.py

View check run for this annotation

Codecov / codecov/patch

autogpt/autogpt/app/agent_protocol_server.py#L89

Added line #L89 was not covered by tests
ntindle marked this conversation as resolved.
Show resolved Hide resolved
# Configure CORS middleware
default_origins = [f"http://localhost:{port}"] # Default only local access
configured_origins = [
Expand Down
Loading