Acebots-AI / my-tiny-service

0 stars 1 forks source link

Add new endpoint for exponentiation #67

Closed artmoskvin closed 3 months ago

artmoskvin commented 3 months ago

The endpoint should take 2 numbers A and B and return A^B.

acebots-ai-local[bot] commented 3 months ago

To add a new endpoint for exponentiation in the project, here's a detailed plan:

  1. Update maths.py in the my_tiny_service/api/routers directory:

    • Add a new endpoint for exponentiation by creating a function similar to the existing mathematical operations. This function will take two numbers, A and B, and return A^B.
    • The function signature will be something like this:
      @router.post(
       "/exponentiation",
       summary="Calculate the exponentiation of a base number to a power",
       response_model=MathsResult,
      )
      def exponentiation(maths_input: MathsIn) -> MathsResult:
       """Calculates the exponentiation of a base number to a power."""
       result = maths_input.a ** maths_input.b
       return MathsResult(result=result)
    • Ensure that the MathsIn class in maths.py can accept the two numbers A and B as input for this operation.
  2. Update the Pydantic models if necessary:

    • Check if the existing MathsIn and MathsResult classes in maths.py need any modifications to support the new endpoint. If the classes are designed to accept two numbers and return a result, no changes might be needed.
  3. Update tests in test_api.py:

    • Add a new test function to tests/test_api.py to ensure the exponentiation endpoint works as expected. The test should send a request to the /exponentiation endpoint with two numbers and verify the response.
    • Example test function:
      def test_exponentiation(client: starlette.testclient.TestClient) -> None:
       """Test that the exponentiation endpoint correctly calculates the power of a number."""
       response = client.post("/exponentiation", json={"a": 2, "b": 3})
       assert response.status_code == 200
       assert response.json() == {"result": 8}
  4. Ensure all changes are backward compatible and do not break existing functionality:

    • Make sure that the addition of this new endpoint does not interfere with the existing endpoints and their functionality.
    • Run all existing tests to ensure they pass with the new changes.

This plan focuses on adding the new endpoint in a way that is consistent with the existing codebase structure and practices. The choice to add the endpoint in maths.py is based on the observation that this file already contains similar mathematical operation endpoints, making it the logical place for the new exponentiation endpoint.

artmoskvin commented 3 months ago

@acedev-dev-ai looks good, proceed with implementation

acebots-ai-local[bot] commented 3 months ago

The implementation for adding a new endpoint for exponentiation has been completed, and a pull request has been created. You can review and merge the changes via the following link: Pull Request #68.

This pull request includes:

Please review the changes, and if everything looks good, you can merge the pull request. If there are any further adjustments needed, feel free to let me know!