Skip to content

Commit

Permalink
test: add test for record and chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
taskingaijc committed May 28, 2024
1 parent 1b68146 commit 1fa1abd
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 107 deletions.
20 changes: 11 additions & 9 deletions backend/app/routes/inference/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ async def api_chat_completion(
if not model.allow_streaming():
raise_request_validation_error(f"Model {model.model_id} does not support streaming.")

async def generator():
async for chunk_dict in await stream_chat_completion(
model=model,
messages=messages,
configs=data.configs,
function_call=data.function_call,
functions=functions,
):
async def generator(sse_chunk_dicts):
async for chunk_dict in sse_chunk_dicts:
yield f"data: {json.dumps(chunk_dict)}\n\n"
yield SSE_DONE_MSG

sse_chunk_dicts = await stream_chat_completion(
model=model,
messages=messages,
configs=data.configs,
function_call=data.function_call,
functions=functions,
)

return StreamingResponse(
generator(),
generator(sse_chunk_dicts),
media_type="text/event-stream",
)

Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ markdown==3.6
pytest==7.4.3
pytest-asyncio==0.21.1
pytest-ordering==0.6
pytest-assume==2.4.3
pytest-assume==2.4.3
pytest-rerunfailures==13.0
2 changes: 1 addition & 1 deletion backend/run_api_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ parent_dir="$(dirname "$(pwd)")"
export PYTHONPATH="${PYTHONPATH}:${parent_dir}"

echo "Starting tests..."
pytest ./tests/services_tests -m "api_test" -q --tb=no
pytest ./tests/services_tests -m "api_test" -q --tb=no --reruns 3 --reruns-delay 2
echo "Tests completed."
2 changes: 1 addition & 1 deletion backend/run_web_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e
parent_dir="$(dirname "$(pwd)")"
export PYTHONPATH="${PYTHONPATH}:${parent_dir}"
echo "Starting tests..."
pytest ./tests/services_tests -m "web_test or api_test"
pytest ./tests/services_tests -m "web_test or api_test" -q --tb=no --reruns 3 --reruns-delay 2
echo "Tests completed."
Loading

0 comments on commit 1fa1abd

Please sign in to comment.