Skip to content

Implement the server#13

Merged
levilevente merged 12 commits intomainfrom
feature/implement-the-server
Dec 1, 2025
Merged

Implement the server#13
levilevente merged 12 commits intomainfrom
feature/implement-the-server

Conversation

@levilevente
Copy link
Owner

This pull request introduces a new FastAPI-based web server for the project, enabling an HTTP endpoint for chat interactions with the agent. It also adds data transfer objects (DTOs) for request and response validation, updates dependencies, and refactors the CLI entry point. The most important changes are grouped below:

API Server Implementation:

  • Added a FastAPI server in server/serve.py, exposing a /chat endpoint that accepts chat questions and returns structured responses. The server is runnable via the new galacticview_app entry point.
  • Implemented the chat_ask_question service function in server/service.py, which interacts with the agent and formats the output using the new DTOs.

Data Transfer Objects (DTOs):

  • Introduced ChatTypeIn and ChatTypeOut models in server/dto/chat_type_in.py and server/dto/chat_type_out.py, respectively, and updated server/dto/__init__.py for easier imports. These models validate and structure the chat request and response data. [1] [2] [3]

Dependency and Entry Point Updates:

  • Added fastapi[standard] to the dependencies in pyproject.toml and defined new CLI and app entry points (galacticview_cli and galacticview_app). The CLI entry point was refactored to point to galacticview_bot.cli:main.

Project Initialization:

  • Updated galacticview_bot/__init__.py to expose the app agent for use in the server and service layers.

RELATED ISSUE #6

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements a FastAPI-based web server for the GalacticView agent, enabling HTTP API access to the existing agent functionality. The implementation adds new server components, data transfer objects for request/response handling, and refactors the CLI to work alongside the new API.

Key Changes

  • FastAPI Server: Introduces a production-ready HTTP endpoint at /chat for interacting with the agent via REST API
  • Data Transfer Objects: Adds Pydantic models (ChatTypeIn, ChatTypeOut) for structured request validation and response formatting
  • Dual Entry Points: Refactors the project to support both CLI (galacticview_cli) and API server (galacticview_app) entry points

Reviewed changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
server/serve.py FastAPI application setup with /chat endpoint and uvicorn server configuration
server/service.py Business logic layer that processes chat requests by interacting with the agent
server/dto/chat_type_in.py Input DTO defining the structure for chat requests (question and datetime)
server/dto/chat_type_out.py Output DTO defining the structure for chat responses (title, content, key_metrics)
server/dto/__init__.py Package initialization exposing DTOs for easier imports
pyproject.toml Adds fastapi[standard] dependency and defines new CLI/app entry points
galacticview_bot/cli.py New CLI implementation moved from root, maintaining existing agent interaction logic
galacticview_bot/__init__.py Exports the agent app for use in server layer and adjusts logging setup formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 12 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 16 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +10
date: datetime = Field(default_factory=datetime.now)

Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The date field in ChatTypeIn is defined with Field(default_factory=datetime.now), but it's not being validated or used anywhere in the service layer. If the intention is to track when questions are asked, this should be renamed to clarify its purpose (e.g., timestamp or created_at), and the service should potentially log or store this information.

If this field is not needed, it should be removed to keep the API contract clean.

Suggested change
date: datetime = Field(default_factory=datetime.now)

Copilot uses AI. Check for mistakes.
)

try:
thread_id = f"aerospace-agent-thread-{uuid.uuid4()}"
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The thread ID generation uses a UUID which creates a new thread for every request. This means the agent has no conversation memory between requests - each question is treated as a completely new conversation.

If this is intentional (stateless API), consider documenting this behavior clearly. If conversation history is desired, you'll need to:

  1. Accept an optional thread_id in the request
  2. Store conversation state in a persistent backend (Redis, database, etc.)
  3. Return the thread_id in the response so clients can maintain context

The current implementation contradicts typical chat API patterns where context is maintained.

Copilot uses AI. Check for mistakes.
def chat_endpoint(request: Request, body: ChatTypeIn) -> ChatTypeOut:
"""
Process chat questions using the agent and return structured responses.
Rate limited to 7 requests per minute per IP.
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

[nitpick] The /chat endpoint lacks API documentation that would appear in FastAPI's automatic OpenAPI/Swagger docs. Consider adding a more detailed docstring with parameter descriptions and response examples:

@app.post("/chat")
@limiter.limit("7/minute")
def chat_endpoint(request: Request, body: ChatTypeIn) -> ChatTypeOut:
    """
    Process chat questions using the agent and return structured responses.
    
    Args:
        request: FastAPI request object (used for rate limiting)
        body: Chat input containing the user's question
        
    Returns:
        ChatTypeOut: Structured response with title, content, and key metrics
        
    Rate Limits:
        7 requests per minute per IP address
        
    Example:
        POST /chat
        {
            "question": "What is the latest news about Mars rovers?"
        }
    """

This improves API discoverability and developer experience.

Suggested change
Rate limited to 7 requests per minute per IP.
Parameters:
request (Request): FastAPI request object (used for rate limiting).
body (ChatTypeIn): Chat input containing the user's question.
Returns:
ChatTypeOut: Structured response containing the answer, title, and key metrics.
Rate Limits:
7 requests per minute per IP address.
Example request:
POST /chat
{
"question": "What is the latest news about Mars rovers?"
}
Example response:
{
"title": "Latest News About Mars Rovers",
"content": "NASA's Perseverance rover recently discovered...",
"metrics": {
"relevance": 0.98,
"sources": ["nasa.gov", "space.com"]
}
}

Copilot uses AI. Check for mistakes.

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The CORS middleware is configured with allow_origins=["*"], which allows requests from any origin. While this may be acceptable for development, it poses a security risk in production environments. Consider restricting this to specific allowed origins, especially since the README mentions this is intended to integrate with a specific frontend application.

Recommendation:

allow_origins=os.getenv("ALLOWED_ORIGINS", "*").split(",")

This allows configuration via environment variable while defaulting to "*" for development.

Suggested change
allow_origins=["*"],
allow_origins=os.getenv("ALLOWED_ORIGINS", "*").split(","),

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +54
uvicorn.run("server.serve:app", host=host, port=8000, reload=reload)

Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The server configuration binds to 0.0.0.0 in production mode, which is correct for containerized deployments. However, there's no configuration for:

  1. Port configuration: The port is hard-coded to 8000. This should be configurable via environment variable:

    port = int(os.getenv("PORT", "8000"))
  2. Worker processes: For production deployments, you typically want multiple worker processes to handle concurrent requests. Consider documenting the need to use a process manager like gunicorn or adding workers configuration:

    workers = int(os.getenv("WORKERS", "1"))
  3. SSL/TLS: No mention of HTTPS configuration. While this might be handled by a reverse proxy, it should be documented.

Suggested change
uvicorn.run("server.serve:app", host=host, port=8000, reload=reload)
# Port and worker configuration via environment variables
port = int(os.getenv("PORT", "8000"))
workers = int(os.getenv("WORKERS", "1"))
# Note: For production deployments, SSL/TLS should be handled by a reverse proxy (e.g., nginx, traefik).
if env == "prod":
uvicorn.run("server.serve:app", host=host, port=port, workers=workers)
else:
uvicorn.run("server.serve:app", host=host, port=port, reload=reload)

Copilot uses AI. Check for mistakes.
@levilevente levilevente mentioned this pull request Dec 1, 2025
@levilevente levilevente merged commit e21dd3a into main Dec 1, 2025
4 checks passed
@levilevente levilevente linked an issue Dec 14, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the server

2 participants