Spaces:
Running
Running
File size: 39,754 Bytes
213da36 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | [
{
"question_id": "q001",
"question": "How do you define a path parameter in FastAPI?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.4,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.75,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 11451.030120020732,
"tokens_used": {
"input_tokens": 1025,
"output_tokens": 161,
"estimated_cost_usd": 0.00025035
},
"answer": "In FastAPI, path parameters are defined by capturing variable segments of a URL path and passing them directly to your route handler function. They are declared using curly braces `{}` in the route path string and must have a corresponding parameter in the function signature. \n\nHere is a basic example:\n\n```python\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/users/{user_id}\")\nasync def read_user(user_id: int):\n return {\"user_id\": user_id}\n```\n\nIn this example, `user_id` is a path parameter that will be captured from the URL when a request is made to `/users/{user_id}` [source: fastapi_path_params.md].",
"retrieved_sources": [
"fastapi_path_params.md",
"fastapi_request_body.md",
"fastapi_query_params.md",
"fastapi_path_params.md",
"fastapi_query_params.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q002",
"question": "What is the default page size for pagination in FastAPI and what is the maximum allowed?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.6,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 5951.742989942431,
"tokens_used": {
"input_tokens": 1136,
"output_tokens": 55,
"estimated_cost_usd": 0.00020339999999999998
},
"answer": "The default page size for pagination in FastAPI is 20 items, and the maximum allowed page size is 100 items per page [source: fastapi_pagination.md].",
"retrieved_sources": [
"fastapi_pagination.md",
"fastapi_pagination.md",
"fastapi_path_params.md",
"fastapi_websockets.md",
"fastapi_pagination.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q003",
"question": "How does FastAPI handle CORS and what is the default max_age for preflight caching?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 3878.671157057397,
"tokens_used": {
"input_tokens": 1075,
"output_tokens": 62,
"estimated_cost_usd": 0.00019844999999999997
},
"answer": "FastAPI handles CORS (Cross-Origin Resource Sharing) using the `CORSMiddleware`. The default `max_age` for preflight caching is set to 600 seconds [source: fastapi_middleware.md].",
"retrieved_sources": [
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q004",
"question": "What algorithm and expiry time does the FastAPI security example use for JWT tokens?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 4879.487166996114,
"tokens_used": {
"input_tokens": 1096,
"output_tokens": 57,
"estimated_cost_usd": 0.0001986
},
"answer": "The FastAPI security example uses the following settings for JWT tokens:\n\n- **Algorithm**: HS256\n- **Expiry Time**: 30 minutes [source: fastapi_security.md].",
"retrieved_sources": [
"fastapi_security.md",
"fastapi_security.md",
"fastapi_security.md",
"fastapi_security.md",
"fastapi_security.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q005",
"question": "What is the recommended formula for calculating the number of Gunicorn workers for a FastAPI deployment?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 0.6,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.5,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 7699.791015009396,
"tokens_used": {
"input_tokens": 1122,
"output_tokens": 176,
"estimated_cost_usd": 0.0002739
},
"answer": "The recommended formula for calculating the number of Gunicorn workers for a FastAPI deployment is to use the following command:\n\n```bash\ngunicorn main:app \\\n --workers 4 \\\n --worker-class uvicorn.workers.UvicornWorker \\\n --bind 0.0.0.0:8000 \\\n --timeout 120 \\\n --graceful-timeout 30 \\\n --keep-alive 5 \\\n --max-requests 1000 \\\n --max-requests-jitter 50 \\\n --access-logfile -\n```\n\nIn this example, `--workers 4` specifies the number of worker processes to be 4, which is a common starting point for production deployments [source: fastapi_deployment.md].",
"retrieved_sources": [
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_intro.md",
"fastapi_intro.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q006",
"question": "How does dependency caching work in FastAPI, and how can you disable it?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 8104.563120054081,
"tokens_used": {
"input_tokens": 1074,
"output_tokens": 175,
"estimated_cost_usd": 0.0002661
},
"answer": "In FastAPI, dependency caching works by caching the result of a dependency if it is used multiple times within a single request. This means that if the same dependency is called more than once (for example, both a route and a sub-dependency use `Depends(get_db)`), FastAPI will only call the dependency once and reuse the result for subsequent calls within that request.\n\nTo disable this caching behavior and force a fresh call to the dependency each time it is used, you can set the `use_cache` parameter to `False` when declaring the dependency. For example:\n\n```python\nDepends(get_db, use_cache=False)\n```\n\nThis will ensure that the dependency is executed anew each time it is needed, rather than using a cached result [source: fastapi_dependencies.md].",
"retrieved_sources": [
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q007",
"question": "If a paginated endpoint returns 20 items per page and there are 10,000 items total, how many total pages are there? And if the page size is changed to 30, how many pages would there be?",
"category": "calculation",
"difficulty": "medium",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.75,
"has_source_citation": false,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 2,
"latency_ms": 3421.634000958875,
"tokens_used": {
"input_tokens": 604,
"output_tokens": 110,
"estimated_cost_usd": 0.0001566
},
"answer": "If a paginated endpoint returns 20 items per page, there would be a total of 500 pages. If the page size is changed to 30, there would be approximately 333 pages (specifically, 333.33, which means 334 pages when rounded up).",
"retrieved_sources": [],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q008",
"question": "Does FastAPI support automatic Kubernetes deployment?",
"category": "out_of_scope",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.3333333333333333,
"has_source_citation": true,
"grounded_refusal": false,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 5193.1978890206665,
"tokens_used": {
"input_tokens": 1148,
"output_tokens": 46,
"estimated_cost_usd": 0.00019979999999999998
},
"answer": "The FastAPI documentation does not explicitly mention support for automatic Kubernetes deployment. Therefore, I cannot provide an answer based on the FastAPI Docs documentation.",
"retrieved_sources": [
"fastapi_configuration.md",
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q009",
"question": "How does FastAPI integrate with Apache Kafka for event streaming?",
"category": "out_of_scope",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.6666666666666666,
"has_source_citation": true,
"grounded_refusal": false,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 6947.794683976099,
"tokens_used": {
"input_tokens": 932,
"output_tokens": 53,
"estimated_cost_usd": 0.0001716
},
"answer": "The FastAPI Docs documentation does not contain any information regarding the integration of FastAPI with Apache Kafka for event streaming. Therefore, I cannot provide an answer to your question.",
"retrieved_sources": [
"fastapi_security.md",
"fastapi_intro.md",
"fastapi_intro.md",
"fastapi_websockets.md",
"fastapi_intro.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q010",
"question": "Can FastAPI generate GraphQL schemas natively?",
"category": "out_of_scope",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.3333333333333333,
"has_source_citation": true,
"grounded_refusal": false,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 4775.999667006545,
"tokens_used": {
"input_tokens": 1003,
"output_tokens": 52,
"estimated_cost_usd": 0.00018165
},
"answer": "The FastAPI documentation does not mention the capability to generate GraphQL schemas natively. Therefore, I cannot provide an answer to your question based on the FastAPI Docs documentation.",
"retrieved_sources": [
"fastapi_openapi.md",
"fastapi_openapi.md",
"fastapi_openapi.md",
"fastapi_response_model.md",
"fastapi_openapi.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q011",
"question": "What is the default Swagger UI endpoint in FastAPI?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.6,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.6666666666666666,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 4869.098415947519,
"tokens_used": {
"input_tokens": 1027,
"output_tokens": 39,
"estimated_cost_usd": 0.00017744999999999998
},
"answer": "The default Swagger UI endpoint in FastAPI is `/docs` [source: fastapi_openapi.md].",
"retrieved_sources": [
"fastapi_openapi.md",
"fastapi_openapi.md",
"fastapi_openapi.md",
"fastapi_intro.md",
"fastapi_intro.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q012",
"question": "How do you raise an HTTP error in a FastAPI route handler?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 6989.395670942031,
"tokens_used": {
"input_tokens": 1091,
"output_tokens": 176,
"estimated_cost_usd": 0.00026924999999999996
},
"answer": "To raise an HTTP error in a FastAPI route handler, you can use the `HTTPException` class. Here is an example of how to do this:\n\n```python\nfrom fastapi import FastAPI, HTTPException\n\napp = FastAPI()\n\n@app.get(\"/items/{item_id}\")\nasync def read_item(item_id: str):\n if item_id not in items:\n raise HTTPException(status_code=404, detail=\"Item not found\")\n return items[item_id]\n```\n\nWhen you raise `HTTPException`, it immediately terminates request processing and returns the specified status code and detail message. The `detail` parameter can be a string, list, or dictionary, and FastAPI will serialize it to JSON automatically [source: fastapi_error_handling.md].",
"retrieved_sources": [
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_dependencies.md",
"fastapi_error_handling.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q013",
"question": "How do you define a request body in FastAPI?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.4,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 8555.312847020105,
"tokens_used": {
"input_tokens": 1024,
"output_tokens": 207,
"estimated_cost_usd": 0.0002778
},
"answer": "In FastAPI, a request body is defined using Pydantic models. A request body typically contains data sent by the client to your API, often in JSON format for POST, PUT, or PATCH requests. Here\u2019s how you can define a request body:\n\n1. Import FastAPI and Pydantic's BaseModel.\n2. Create a Pydantic model that represents the structure of the request body.\n\nHere is an example:\n\n```python\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\napp = FastAPI()\n\nclass Item(BaseModel):\n name: str\n description: str | None = None\n price: float\n tax: float = 0.0\n```\n\nIn this example, the `Item` class is a Pydantic model that defines the expected fields in the request body, including their types and optional values [source: fastapi_request_body.md].",
"retrieved_sources": [
"fastapi_request_body.md",
"fastapi_request_body.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q014",
"question": "What testing tools does FastAPI use, and what class provides the test client?",
"category": "retrieval",
"difficulty": "easy",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.3333333333333333,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 7168.439702014439,
"tokens_used": {
"input_tokens": 1129,
"output_tokens": 72,
"estimated_cost_usd": 0.00021255
},
"answer": "FastAPI applications are tested using the `TestClient` class, which provides a synchronous interface for sending requests to your application without running an actual server. For asynchronous testing, you can use `httpx.AsyncClient` [source: fastapi_testing.md].",
"retrieved_sources": [
"fastapi_testing.md",
"fastapi_testing.md",
"fastapi_testing.md",
"fastapi_openapi.md",
"fastapi_testing.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q015",
"question": "How does FastAPI manage application configuration and environment variables?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 9010.0379610667,
"tokens_used": {
"input_tokens": 1072,
"output_tokens": 202,
"estimated_cost_usd": 0.000282
},
"answer": "FastAPI manages application configuration and environment variables using Pydantic's `BaseSettings` class. This allows for type-safe configuration with validation, default values, and automatic reading of environment variables and `.env` files. The priority order for reading configuration values is as follows:\n\n1. Constructor arguments passed directly to `Settings()`\n2. Environment variables\n3. Variables from the `.env` file\n4. Default values defined in the model\n\nAdditionally, FastAPI supports secrets management, where if `secrets_dir` is set, Pydantic looks for files named after each field, and the contents of these files become the field values. The priority order for secrets is:\n\n1. Constructor arguments\n2. Environment variables\n3. Secret files\n4. `.env` file\n5. Default values\n\nThis setup allows for flexible and secure management of application settings and secrets [source: fastapi_configuration.md].",
"retrieved_sources": [
"fastapi_configuration.md",
"fastapi_configuration.md",
"fastapi_configuration.md",
"fastapi_configuration.md",
"fastapi_intro.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q016",
"question": "What is the minimum response size for GZip compression middleware in FastAPI, and how do you enable it?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 7100.143527961336,
"tokens_used": {
"input_tokens": 1091,
"output_tokens": 110,
"estimated_cost_usd": 0.00022965
},
"answer": "The minimum response size for GZip compression middleware in FastAPI is set to 500 bytes by default. You can enable GZip compression by adding the middleware to your FastAPI application like this:\n\n```python\nfrom fastapi.middleware.gzip import GZipMiddleware\n\napp.add_middleware(GZipMiddleware, minimum_size=500)\n```\n\nResponses smaller than this threshold will be sent uncompressed [source: fastapi_middleware.md].",
"retrieved_sources": [
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q017",
"question": "How do yield dependencies work in FastAPI and what is the maximum number supported per request?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.75,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 6820.307894027792,
"tokens_used": {
"input_tokens": 1053,
"output_tokens": 134,
"estimated_cost_usd": 0.00023834999999999997
},
"answer": "In FastAPI, yield dependencies allow you to run setup code before the route handler executes and cleanup code after the response is sent. This is particularly useful for managing resources like database sessions. You can define a yield dependency using the `yield` statement in a function, which will execute the code before the `yield` when the dependency is called, and the code after the `yield` will run after the response is sent [source: fastapi_dependencies.md].\n\nFastAPI supports up to 32 yield dependencies per request by default [source: fastapi_dependencies.md].",
"retrieved_sources": [
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md",
"fastapi_dependencies.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q018",
"question": "What are the three documentation endpoints FastAPI exposes by default and what OpenAPI version does it use?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 6209.570198901929,
"tokens_used": {
"input_tokens": 1070,
"output_tokens": 105,
"estimated_cost_usd": 0.0002235
},
"answer": "FastAPI exposes three documentation-related endpoints by default:\n\n1. `/docs` - Swagger UI, an interactive API explorer.\n2. `/redoc` - ReDoc, an alternative documentation viewer.\n3. `/openapi.json` - Raw OpenAPI schema in JSON format.\n\nFastAPI uses OpenAPI version 3.1.0 for its schema generation [source: fastapi_openapi.md].",
"retrieved_sources": [
"fastapi_openapi.md",
"fastapi_openapi.md",
"fastapi_intro.md",
"fastapi_openapi.md",
"fastapi_openapi.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q019",
"question": "How does FastAPI handle WebSocket connections, and what must be called before sending data?",
"category": "retrieval",
"difficulty": "medium",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 0.75,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 6920.212193974294,
"tokens_used": {
"input_tokens": 1067,
"output_tokens": 109,
"estimated_cost_usd": 0.00022544999999999998
},
"answer": "FastAPI handles WebSocket connections using Starlette's WebSocket implementation, which allows for full-duplex, bidirectional communication. To set up a WebSocket endpoint, you use the `@app.websocket()` decorator. \n\nBefore sending or receiving any data, you must call `await ws.accept()`. This method sends the HTTP 101 Switching Protocols response to the client, establishing the WebSocket connection [source: fastapi_websockets.md].",
"retrieved_sources": [
"fastapi_websockets.md",
"fastapi_websockets.md",
"fastapi_websockets.md",
"fastapi_intro.md",
"fastapi_websockets.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q020",
"question": "For a server with 4 CPU cores, how many Gunicorn workers should be configured using the recommended formula?",
"category": "calculation",
"difficulty": "medium",
"retrieval_precision": 1.0,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": false,
"tool_calls_made": 1,
"latency_ms": 5531.007012003101,
"tokens_used": {
"input_tokens": 1099,
"output_tokens": 66,
"estimated_cost_usd": 0.00020444999999999998
},
"answer": "The recommended number of Gunicorn workers is calculated using the formula `(2 * CPU_CORES) + 1`. For a server with 4 CPU cores, this results in 9 workers [source: fastapi_deployment.md].",
"retrieved_sources": [
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md",
"fastapi_deployment.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q021",
"question": "If the CORS max_age is 600 seconds, how many minutes does the browser cache preflight results?",
"category": "calculation",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 1.0,
"has_source_citation": false,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 3345.2545889886096,
"tokens_used": {
"input_tokens": 507,
"output_tokens": 40,
"estimated_cost_usd": 0.00010004999999999999
},
"answer": "If the CORS max_age is 600 seconds, the browser caches preflight results for 10 minutes.",
"retrieved_sources": [],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q022",
"question": "How do route ordering and dependency injection interact when building a secure FastAPI application with scoped endpoints?",
"category": "retrieval",
"difficulty": "hard",
"retrieval_precision": 0.4,
"retrieval_recall": 0.3333333333333333,
"keyword_hit_rate": 0.25,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 4416.234942968003,
"tokens_used": {
"input_tokens": 1051,
"output_tokens": 65,
"estimated_cost_usd": 0.00019664999999999998
},
"answer": "The FastAPI documentation does not provide specific information on how route ordering and dependency injection interact when building a secure application with scoped endpoints. Therefore, I cannot answer your question based on the FastAPI Docs documentation.",
"retrieved_sources": [
"fastapi_dependencies.md",
"fastapi_websockets.md",
"fastapi_dependencies.md",
"fastapi_configuration.md",
"fastapi_intro.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q023",
"question": "How would you set up a FastAPI application with custom error handling, CORS middleware, and structured testing including dependency overrides?",
"category": "retrieval",
"difficulty": "hard",
"retrieval_precision": 1.0,
"retrieval_recall": 0.3333333333333333,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 3,
"latency_ms": 23753.096262924373,
"tokens_used": {
"input_tokens": 2536,
"output_tokens": 779,
"estimated_cost_usd": 0.0008478
},
"answer": "To set up a FastAPI application with custom error handling, CORS middleware, and structured testing including dependency overrides, you can follow these guidelines:\n\n### Custom Error Handling\nFastAPI allows you to handle errors using the `HTTPException` class and custom exception handlers. Here\u2019s how you can implement it:\n\n1. **Using `HTTPException`:**\n You can raise an `HTTPException` in your route handlers to return error responses.\n ```python\n from fastapi import FastAPI, HTTPException\n\n app = FastAPI()\n\n @app.get(\"/items/{item_id}\")\n async def read_item(item_id: str):\n if item_id not in items:\n raise HTTPException(status_code=404, detail=\"Item not found\")\n return items[item_id]\n ```\n\n2. **Custom Exception Handlers:**\n You can register custom handlers for specific exceptions.\n ```python\n from fastapi import FastAPI, Request\n from fastapi.responses import JSONResponse\n\n class ItemNotFoundException(Exception):\n def __init__(self, item_id: str):\n self.item_id = item_id\n\n @app.exception_handler(ItemNotFoundException)\n async def item_not_found_exception_handler(request: Request, exc: ItemNotFoundException):\n return JSONResponse(\n status_code=404,\n content={\"message\": f\"Item {exc.item_id} not found\"},\n )\n ``` \n [source: fastapi_error_handling.md]\n\n### CORS Middleware\nTo enable Cross-Origin Resource Sharing (CORS), you can use the `CORSMiddleware` provided by FastAPI. Here\u2019s how to set it up:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi.middleware.cors import CORSMiddleware\n\napp = FastAPI()\n\napp.add_middleware(\n CORSMiddleware,\n allow_origins=[\"https://example.com\", \"https://app.example.com\"],\n allow_credentials=True,\n allow_methods=[\"GET\", \"POST\", \"PUT\", \"DELETE\"],\n allow_headers=[\"Authorization\", \"Content-Type\"],\n expose_headers=[\"X-Custom-Header\"],\n max_age=600,\n)\n```\nThis configuration allows specified origins to access your API. [source: fastapi_middleware.md]\n\n### Structured Testing with Dependency Overrides\nFor testing, you can override dependencies to inject mock services or test databases. Here\u2019s an example:\n\n1. **Define your dependency:**\n ```python\n from fastapi import FastAPI, Depends\n\n app = FastAPI()\n\n async def get_db():\n db = ProductionDatabase()\n try:\n yield db\n finally:\n db.close()\n\n @app.get(\"/items/\")\n async def read_items(db=Depends(get_db)):\n return db.query_all_items()\n ```\n\n2. **Override the dependency in your tests:**\n ```python\n from fastapi.testclient import TestClient\n\n def get_test_db():\n db = TestDatabase()\n try:\n yield db\n finally:\n db.close()\n\n app.dependency_overrides[get_db] = get_test_db\n\n client = TestClient(app)\n\n def test_read_items():\n response = client.get(\"/items/\")\n assert response.status_code == 200\n\n # Clean up overrides after tests\n app.dependency_overrides.clear()\n ```\nThis setup allows you to test your application without relying on the production database. [source: fastapi_testing.md]",
"retrieved_sources": [
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_error_handling.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_middleware.md",
"fastapi_testing.md",
"fastapi_testing.md",
"fastapi_configuration.md",
"fastapi_testing.md",
"fastapi_dependencies.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q024",
"question": "Explain how to deploy a FastAPI app with Docker using Gunicorn workers, health checks, and environment-based configuration via Pydantic Settings.",
"category": "retrieval",
"difficulty": "hard",
"retrieval_precision": 0.8,
"retrieval_recall": 1.0,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 18227.398704970255,
"tokens_used": {
"input_tokens": 1111,
"output_tokens": 569,
"estimated_cost_usd": 0.00050805
},
"answer": "To deploy a FastAPI app with Docker using Gunicorn workers, health checks, and environment-based configuration via Pydantic Settings, follow these steps:\n\n1. **Dockerfile Setup**:\n Create a `Dockerfile` for your FastAPI application. You can use Gunicorn as the ASGI server. Here\u2019s a basic example:\n\n ```dockerfile\n FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9\n\n COPY ./app /app\n\n WORKDIR /app\n\n # Install dependencies\n RUN pip install -r requirements.txt\n\n # Command to run the app with Gunicorn\n CMD [\"gunicorn\", \"-w\", \"4\", \"-k\", \"uvicorn.workers.UvicornWorker\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"80\"]\n ```\n\n This configuration uses 4 Gunicorn workers with Uvicorn as the worker class [source: fastapi_deployment.md].\n\n2. **Health Check Endpoint**:\n Include a health check endpoint in your FastAPI application to allow container orchestrators to check the health of your app:\n\n ```python\n @app.get(\"/health\", status_code=200)\n async def health_check():\n return {\"status\": \"healthy\"}\n ```\n\n Additionally, configure the Docker health check in your `Dockerfile`:\n\n ```dockerfile\n HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=10s \\\n CMD curl -f http://localhost:80/health || exit 1\n ```\n\n This setup ensures that Docker can monitor the health of your application [source: fastapi_deployment.md].\n\n3. **Environment-Based Configuration with Pydantic Settings**:\n Use Pydantic's `BaseSettings` to manage your application configuration through environment variables. First, install the necessary package:\n\n ```bash\n pip install pydantic-settings\n ```\n\n Then, define your settings as follows:\n\n ```python\n from pydantic import BaseSettings\n\n class Settings(BaseSettings):\n database_password: str\n api_key: str\n jwt_secret: str\n\n class Config:\n env_file = \".env\"\n secrets_dir = \"/run/secrets\"\n ```\n\n This allows your application to read configuration values from a `.env` file or secrets management systems [source: fastapi_configuration.md].\n\nBy following these steps, you can effectively deploy a FastAPI application using Docker with Gunicorn workers, health checks, and environment-based configuration.",
"retrieved_sources": [
"fastapi_deployment.md",
"fastapi_configuration.md",
"fastapi_configuration.md",
"fastapi_request_body.md",
"fastapi_deployment.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q025",
"question": "How would you build a paginated API with cursor-based navigation, response model validation, and background task processing for analytics logging?",
"category": "retrieval",
"difficulty": "hard",
"retrieval_precision": 1.0,
"retrieval_recall": 0.6666666666666666,
"keyword_hit_rate": 1.0,
"has_source_citation": true,
"grounded_refusal": true,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 13523.346598027274,
"tokens_used": {
"input_tokens": 1161,
"output_tokens": 525,
"estimated_cost_usd": 0.00048915
},
"answer": "To build a paginated API with cursor-based navigation, response model validation, and background task processing for analytics logging in FastAPI, you can follow these guidelines:\n\n1. **Cursor-Based Pagination**: This method uses an opaque token (cursor) that points to the last item in the previous page, which helps maintain performance even with large datasets. Here's a basic implementation:\n\n ```python\n from fastapi import FastAPI, Query\n from typing import List\n\n app = FastAPI()\n\n @app.get(\"/items/\", response_model=PaginatedResponse[Item])\n async def list_items(cursor: str = None, limit: int = Query(default=20, ge=1, le=100)):\n # Logic to retrieve items based on cursor\n ...\n ```\n\n Cursor-based pagination is recommended for datasets exceeding 100,000 records or for real-time feeds where items may be inserted or deleted between page requests [source: fastapi_pagination.md].\n\n2. **Response Model Validation**: You can use Pydantic models to define the structure of your response. For example:\n\n ```python\n from pydantic import BaseModel\n from typing import List\n\n class Item(BaseModel):\n id: int\n name: str\n\n class PaginatedResponse(BaseModel):\n items: List[Item]\n total: int\n has_more: bool\n ```\n\n This ensures that the API responses conform to the expected structure [source: fastapi_pagination.md].\n\n3. **Background Task Processing**: FastAPI allows you to schedule tasks to run after the response has been sent. This is useful for logging analytics. Here\u2019s how you can implement it:\n\n ```python\n from fastapi import FastAPI, BackgroundTasks\n\n app = FastAPI()\n\n def write_log(message: str):\n with open(\"log.txt\", \"a\") as f:\n f.write(f\"{message}\\n\")\n\n @app.post(\"/items/\")\n async def create_item(item: Item, background_tasks: BackgroundTasks):\n background_tasks.add_task(write_log, f\"Item created: {item.name}\")\n return item\n ```\n\n This example shows how to log an event after the response is sent to the client [source: fastapi_background_tasks.md].\n\nBy combining these elements, you can create a robust API that efficiently handles large datasets, validates responses, and processes background tasks for logging or analytics.",
"retrieved_sources": [
"fastapi_pagination.md",
"fastapi_pagination.md",
"fastapi_background_tasks.md",
"fastapi_pagination.md",
"fastapi_pagination.md"
],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q026",
"question": "Does FastAPI have built-in support for database migrations like Alembic?",
"category": "out_of_scope",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.3333333333333333,
"has_source_citation": false,
"grounded_refusal": false,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 7161.384784965776,
"tokens_used": {
"input_tokens": 500,
"output_tokens": 30,
"estimated_cost_usd": 9.3e-05
},
"answer": "The answer is not in the FastAPI Docs documentation.",
"retrieved_sources": [],
"faithfulness": null,
"correctness": null
},
{
"question_id": "q027",
"question": "How does FastAPI handle automatic load balancing across multiple servers?",
"category": "out_of_scope",
"difficulty": "easy",
"retrieval_precision": 0.0,
"retrieval_recall": 0.0,
"keyword_hit_rate": 0.3333333333333333,
"has_source_citation": false,
"grounded_refusal": false,
"citation_accuracy": 1.0,
"calculator_used_correctly": true,
"tool_calls_made": 1,
"latency_ms": 5531.576726934873,
"tokens_used": {
"input_tokens": 495,
"output_tokens": 31,
"estimated_cost_usd": 9.285000000000001e-05
},
"answer": "The answer is not in the FastAPI Docs documentation.",
"retrieved_sources": [],
"faithfulness": null,
"correctness": null
}
] |