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
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
16 changes: 13 additions & 3 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 All @@ -88,7 +98,7 @@

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_origins=["*"],
ntindle marked this conversation as resolved.
Show resolved Hide resolved
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
4 changes: 2 additions & 2 deletions forge/forge/agent_protocol/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TaskRequestBody(BaseModel):
description="Input prompt for the task.",
example="Write the words you receive to the file 'output.txt'.",
)
additional_input: dict[str, Any] = Field(default_factory=dict)
additional_input: Optional[dict[str, Any]] = Field(default_factory=dict)


class Task(TaskRequestBody):
Expand Down Expand Up @@ -55,7 +55,7 @@ class StepRequestBody(BaseModel):
input: str = Field(
..., description="Input prompt for the step.", example="Washington"
)
additional_input: dict[str, Any] = Field(default_factory=dict)
additional_input: Optional[dict[str, Any]] = Field(default_factory=dict)
ntindle marked this conversation as resolved.
Show resolved Hide resolved


class StepStatus(Enum):
Expand Down
2 changes: 1 addition & 1 deletion forge/forge/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@

def assert_config_has_openai_api_key(config: Config) -> None:
"""Check if the OpenAI API key is set in config.py or as an environment variable."""
key_pattern = r"^sk-(proj-)?\w{48}"
key_pattern = r"^sk-(?:proj-|wa-)?\w{48}"

Check warning on line 213 in forge/forge/config/config.py

View check run for this annotation

Codecov / codecov/patch

forge/forge/config/config.py#L213

Added line #L213 was not covered by tests
ntindle marked this conversation as resolved.
Show resolved Hide resolved
openai_api_key = (
config.openai_credentials.api_key.get_secret_value()
if config.openai_credentials
Expand Down
Loading