Skip to content

Commit

Permalink
adding ask_gpt4 function
Browse files Browse the repository at this point in the history
  • Loading branch information
paraskuk committed Apr 6, 2024
1 parent b0dd920 commit 2ac5567
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ This application is built using FastAPI for the API and JavaScript ,HTML and CSS
2. Navigate to `http://localhost:8000/` on your browser to access the application.
3. Enter your query in the input field and click on the `Submit` button to generate a response.

## Testing the Application with Curl
`curl -X POST http://127.0.0.1:8000/ask_gpt4/ -H "Content-Type: application/json" -d "{\"user_input\": \"Create a function that adds 2 numbers\", \"model\": \"gpt-4\"}"`

## Note

Make sure to set the `OPEN_AI_KEY` environment variable before running the application, as this is required for the OpenAI API to function properly.
Expand Down
29 changes: 29 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,32 @@ async def test_redis_session_middleware():
assert 'session_id' in response.cookies

assert mock_set.called


@pytest.mark.asyncio
async def test_ask_gpt4_endpoint_gpt4():
"""
Function to test the ask_gpt4 endpoint with AsyncClient
:return: boolean, True if the expected response is returned and matches the actual response from GPT-4
response is not necessary deterministic so the test might fail
"""
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.post("/ask_gpt4/", json={
"model": "gpt-4",
"user_input": "What is the result of the python function sum([3,5])? Provide only the result with a "
"single number only.For user level estimation and sentiment analysis estimation use only "
"one word starting with a capital letter."
})

assert response.status_code == 200
response_data = response.json()

expected_response = (
"8\n\nUser Level Estimation: Beginner\n\nSentiment Analysis: Neutral"
)


assert response_data["response"] in expected_response



0 comments on commit 2ac5567

Please sign in to comment.