Skip to content

Commit b3091f4

Browse files
authored
Merge pull request #10 from drod75/david
Edited paths
2 parents 8edf127 + 419db1b commit b3091f4

6 files changed

Lines changed: 45 additions & 81 deletions

File tree

src/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
__all__ = ["main"]
2-
3-
from . import main

src/api/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
__all__ = ["main"]
2-
3-
from . import main

src/api/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from .routers.algebra import algebra_router
2-
from .routers.basic_math import basic_math_router
3-
from .routers.calculus import calculus_router
4-
from .routers.linear_algebra import linear_algebra_router
5-
from .routers.probability import probability_router
6-
from .routers.statistics import statistics_router
7-
from .routers.trigonometry import trigonometry_router
1+
from src.api.routers.algebra import algebra_router
2+
from src.api.routers.basic_math import basic_math_router
3+
from src.api.routers.calculus import calculus_router
4+
from src.api.routers.linear_algebra import linear_algebra_router
5+
from src.api.routers.probability import probability_router
6+
from src.api.routers.statistics import statistics_router
7+
from src.api.routers.trigonometry import trigonometry_router
88
from fastapi import APIRouter
99

10-
router_app = APIRouter()
10+
router_app = APIRouter(prefix="/api")
1111
router_app.include_router(algebra_router)
1212
router_app.include_router(basic_math_router)
1313
router_app.include_router(calculus_router)

src/api/routers/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +0,0 @@
1-
__all__ = [
2-
"algebra",
3-
"basic_math",
4-
"calculus",
5-
"linear_algebra",
6-
"probability",
7-
"statistics",
8-
"trigonometry",
9-
]
10-
11-
from . import algebra
12-
from . import basic_math
13-
from . import calculus
14-
from . import linear_algebra
15-
from . import probability
16-
from . import statistics
17-
from . import trigonometry

src/api/routers/basic_math.py

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from fastapi import APIRouter, Query, HTTPException
2-
from typing import Annotated, List, Union
1+
from fastapi import APIRouter, HTTPException
2+
from typing import List
33
import numpy as np
44

55
basic_math_router = APIRouter(
@@ -11,78 +11,64 @@
1111

1212
@basic_math_router.get("/addition")
1313
async def addition(
14-
q: Annotated[
15-
List[Union[int, float]],
16-
Query(alias="numerical-array", title="List of numerical values"),
17-
],
14+
q: List[int | float],
1815
):
19-
"""This Python function calculates the sum of a list of numerical values provided as a query parameter.
16+
"""Calculate the sum of a list of numbers.
17+
18+
This endpoint takes a query parameter `q` which is a list of numbers
19+
and returns their sum.
2020
2121
Parameters
2222
----------
23-
q : Annotated[
24-
List[Union[int, float]],
25-
Query(alias="numerical-array", title="List of numerical values"),
26-
]
27-
The parameter `q` is a list of numerical values that are passed as a query parameter to the
28-
endpoint `/addition`. The values in the list can be integers or floats. The endpoint calculates the
29-
sum of all the numerical values in the list using NumPy's `np.sum` function.
23+
q : List[int | float]
24+
A list of numbers (integers or floats) to be added together.
3025
3126
Returns
3227
-------
33-
The code defines a route for performing addition operation on a list of numerical values provided
34-
as a query parameter. The function takes a list of numerical values as input, converts it to a NumPy
35-
array, calculates the sum of the array elements, and returns the result.
28+
float
29+
The sum of all the numbers in the input list.
3630
31+
Raises
32+
------
33+
HTTPException
34+
If any error occurs during the summation process.
3735
"""
3836
try:
39-
array = np.array(q)
40-
return np.sum(array)
37+
return np.sum(q)
4138
except Exception as E:
4239
raise HTTPException(status_code=400, detail=f"{E}")
4340

4441

4542
@basic_math_router.get("/subtraction")
4643
async def subtraction(
47-
q1: Annotated[
48-
List[Union[int, float]],
49-
Query(alias="numerical-array-1", title="List of numerical values 1."),
50-
],
51-
q2: Annotated[
52-
List[Union[int, float]],
53-
Query(alias="numerical-array-2", title="List of numerical values 2"),
54-
],
44+
q1: List[int | float],
45+
q2: List[int | float],
5546
):
56-
"""This Python function performs subtraction on two arrays of numerical values provided as input.
47+
"""Perform element-wise subtraction of two lists of numbers.
48+
49+
This endpoint takes two query parameters, `q1` and `q2`, which are two lists
50+
of numbers. It performs element-wise subtraction (q1 - q2).
5751
5852
Parameters
5953
----------
60-
q1 : Annotated[
61-
List[Union[int, float]],
62-
Query(alias="numerical-array-1", title="List of numerical values 1."),
63-
]
64-
The parameter `q2` in the code snippet represents a list of numerical values 1. It is defined as a
65-
query parameter with an alias of "numerical-array-1" and a title of "List of numerical values 1".
66-
This parameter is expected to be a list containing elements that are either floats or ints.
67-
q2 : Annotated[
68-
List[Union[int, float]],
69-
Query(alias="numerical-array-2", title="List of numerical values 2"),
70-
]
71-
The parameter `q2` in the code snippet represents a list of numerical values 2. It is defined as a
72-
query parameter with an alias of "numerical-array-2" and a title of "List of numerical values 2".
73-
This parameter is expected to be a list containing elements that are either floats or ints.
54+
q1 : List[int | float]
55+
A list of numbers from which to subtract.
56+
q2 : List[int | float]
57+
A list of numbers to subtract.
7458
7559
Returns
7660
-------
77-
The code snippet defines an endpoint for subtraction operation where it takes two lists of
78-
numerical values as input and returns the result of subtracting the elements of the second list from
79-
the elements of the first list. The result returned is the element-wise subtraction of the two input
80-
arrays.
61+
npt.NDArray[np.number]
62+
An array of numbers representing the result of the subtraction.
63+
This is serialized to a JSON list.
8164
65+
Raises
66+
------
67+
HTTPException
68+
If any error occurs during the subtraction, for example, if the
69+
lists have different lengths.
8270
"""
8371
try:
84-
array1 = np.array(q1)
85-
array2 = np.array(q2)
86-
return np.subtract(array1, array2)
72+
return np.subtract(q1, q2)
8773
except Exception as E:
8874
raise HTTPException(status_code=400, detail=f"{E}")

src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from api.main import router_app
1+
from src.api.main import router_app
22
from fastapi import FastAPI
33
from fastapi_mcp import FastApiMCP
44

@@ -10,4 +10,5 @@
1010
"Math MCP Server",
1111
"An MCP server that allows LLM's to use math formulas and operations!",
1212
)
13+
1314
mcp.mount()

0 commit comments

Comments
 (0)