{"id":20743,"date":"2025-02-10T19:11:53","date_gmt":"2025-02-10T11:11:53","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=20743"},"modified":"2025-02-10T19:17:31","modified_gmt":"2025-02-10T11:17:31","slug":"cong-pdf-daodongcha","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/ja\/cong-pdf-daodongcha\/","title":{"rendered":"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848"},"content":{"rendered":"<p>\u4e0a\u5468\uff0c<a href=\"https:\/\/www.kdjingpai.com\/gemini-20-jiazuzai\/\">Google DeepMind \u53d1\u5e03\u4e86 Gemini 2.0<\/a>\uff0c\u5176\u4e2d\u5305\u62ec <a href=\"https:\/\/www.kdjingpai.com\/pt\/geminibardgubu\/\">Gemini<\/a> 2.0 Flash\uff08\u5168\u9762\u53ef\u7528\uff09\u3001Gemini 2.0 Flash-Lite\uff08\u5168\u65b0\u9ad8\u6027\u4ef7\u6bd4\uff09\u548c Gemini 2.0 Pro\uff08\u5b9e\u9a8c\u6027\uff09\u3002\u6240\u6709\u6a21\u578b\u90fd\u652f\u6301\u81f3\u5c11 100 \u4e07 <a href=\"https:\/\/www.kdjingpai.com\/pt\/tokenization\/\">Token<\/a> \u7684\u8f93\u5165\u4e0a\u4e0b\u6587\u7a97\u53e3\uff0c\u5e76\u652f\u6301\u6587\u672c\u3001\u56fe\u50cf\u548c\u97f3\u9891\u4ee5\u53ca\u51fd\u6570\u8c03\u7528\/\u7ed3\u6784\u5316\u8f93\u51fa\u3002\u672c\u6587\u540c\u65f6\u4f5c\u4e3a\u00a0<a href=\"https:\/\/www.kdjingpai.com\/llm-ocr-dejuxianxing\/\">LLM OCR \u7684\u5c40\u9650\u6027\uff1a\u5149\u9c9c\u5916\u8868\u4e0b\u7684\u6587\u6863\u89e3\u6790\u96be\u9898<\/a> \u7684\u53c2\u8003\u9605\u8bfb\u8d44\u6599\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20745\" title=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/5669e56a8976882.jpg\" alt=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-1\" width=\"680\" height=\"360\" \/><\/p>\n<p>\u8fd9\u4e3a PDF \u5904\u7406\u5e26\u6765\u4e86\u7edd\u4f73\u7684\u7528\u4f8b\u3002\u5c06 PDF \u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u6216\u673a\u5668\u53ef\u8bfb\u7684\u6587\u672c\u4e00\u76f4\u662f\u4e00\u4e2a\u4e3b\u8981\u7684\u96be\u9898\u3002\u8bd5\u60f3\u4e00\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u5c06 PDF \u4ece\u6587\u6863\u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u6570\u636e\uff0c\u90a3\u5c06\u600e\u6837\uff1f\u8fd9\u5c31\u662f Gemini 2.0 \u80fd\u591f\u53d1\u6325\u4f5c\u7528\u7684\u5730\u65b9\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u8bfb\u8005\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 Gemini 2.0 \u76f4\u63a5\u4ece PDF \u6587\u6863\u4e2d\u63d0\u53d6\u7ed3\u6784\u5316\u4fe1\u606f\uff0c\u4f8b\u5982\u53d1\u7968\u53f7\u7801\u3001\u65e5\u671f\uff1a<\/p>\n<ol>\n<li>\u8bbe\u7f6e\u73af\u5883\u5e76\u521b\u5efa\u63a8\u7406\u5ba2\u6237\u7aef<\/li>\n<li>\u5904\u7406 PDF \u548c\u5176\u4ed6\u6587\u4ef6<\/li>\n<li>\u4f7f\u7528 Gemini 2.0 \u548c Pydantic \u5b9e\u73b0\u7ed3\u6784\u5316\u8f93\u51fa<\/li>\n<li>\u4f7f\u7528 Gemini 2.0 \u4ece PDF \u4e2d\u63d0\u53d6\u7ed3\u6784\u5316\u6570\u636e<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>1. \u8bbe\u7f6e\u73af\u5883\u5e76\u521b\u5efa\u63a8\u7406\u5ba2\u6237\u7aef<\/h2>\n<p>\u9996\u8981\u4efb\u52a1\u662f\u5b89\u88c5\u00a0<code>google-genai<\/code>\u00a0<a href=\"https:\/\/googleapis.github.io\/python-genai\/\">Python SDK<\/a>\u00a0\u5e76\u83b7\u53d6 API \u5bc6\u94a5\u3002\u5982\u679c\u8bfb\u8005\u8fd8\u6ca1\u6709 API \u5bc6\u94a5\uff0c\u53ef\u4ee5\u4ece <a href=\"https:\/\/www.kdjingpai.com\/pt\/google-ai-studioai\/\">Google AI Studio<\/a> \u83b7\u53d6\uff1a<a href=\"https:\/\/aistudio.google.com\/app\/apikey\">\u83b7\u53d6 Gemini API \u5bc6\u94a5<\/a>\u3002<\/p>\n<pre><code>%pip install \"google-genai&gt;=1\"\r\n<\/code><\/pre>\n<p>\u4e00\u65e6\u62e5\u6709 SDK \u548c API \u5bc6\u94a5\uff0c\u8bfb\u8005\u5c31\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5ba2\u6237\u7aef\u5e76\u5b9a\u4e49\u5c06\u8981\u4f7f\u7528\u7684\u6a21\u578b\uff0c\u5373\u65b0\u7684 Gemini 2.0 Flash \u6a21\u578b\uff0c\u8be5\u6a21\u578b\u901a\u8fc7\u514d\u8d39\u5c42\u7ea7\u63d0\u4f9b\uff0c\u6bcf\u5929 1,500 \u4e2a\u8bf7\u6c42\uff08\u622a\u81f3 2025 \u5e74 2 \u6708 6 \u65e5\uff09\u3002<\/p>\n<pre>from google import genai\r\n# Create a client\r\napi_key = \"XXXXX\"\r\nclient = genai.Client(api_key=api_key)\r\n \r\n# Define the model you are going to use\r\nmodel_id =  \"gemini-2.0-flash\" # or \"gemini-2.0-flash-lite-preview-02-05\"  , \"gemini-2.0-pro-exp-02-05\"<\/pre>\n<p><em>\u6ce8\u610f\uff1a\u5982\u679c\u8bfb\u8005\u60f3\u4f7f\u7528 Vertex AI\uff0c\u8bf7<a href=\"https:\/\/googleapis.github.io\/python-genai\/#create-a-client\">\u70b9\u51fb\u6b64\u5904<\/a>\u4e86\u89e3\u5982\u4f55\u521b\u5efa\u5ba2\u6237\u7aef<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>2. \u5904\u7406 PDF \u548c\u5176\u4ed6\u6587\u4ef6<\/h2>\n<p>Gemini \u6a21\u578b\u80fd\u591f\u5904\u7406<a href=\"https:\/\/ai.google.dev\/gemini-api\/docs\/vision?lang=python#image-input\">\u56fe\u50cf\u548c\u89c6\u9891<\/a>\uff0c\u8fd9\u53ef\u4ee5\u4e0e base64 \u5b57\u7b26\u4e32\u6216\u4f7f\u7528\u00a0<code>files<\/code>\u00a0API \u7ed3\u5408\u4f7f\u7528\u3002\u4e0a\u4f20\u6587\u4ef6\u540e\uff0c\u8bfb\u8005\u53ef\u4ee5\u76f4\u63a5\u5728\u8c03\u7528\u4e2d\u5305\u542b\u6587\u4ef6 URI\u3002Python API \u5305\u62ec\u00a0upload\u00a0\u548c\u00a0delete\u00a0\u65b9\u6cd5\u3002<\/p>\n<p>\u5bf9\u4e8e\u6b64\u793a\u4f8b\uff0c\u7528\u6237\u6709 2 \u4e2a PDF \u6837\u672c\uff0c\u4e00\u4e2a\u57fa\u672c\u53d1\u7968\u548c\u4e00\u4e2a\u5e26\u6709\u624b\u5199\u503c\u7684\u8868\u5355\u3002<\/p>\n<pre>!wget -q -O https:\/\/storage.googleapis.com\/generativeai-downloads\/data\/pdf_structured_outputs\/handwriting_form.pdf\r\n!wget -q -O https:\/\/storage.googleapis.com\/generativeai-downloads\/data\/pdf_structured_outputs\/invoice.pdf<\/pre>\n<p>\u73b0\u5728\u8bfb\u8005\u53ef\u4ee5\u4f7f\u7528\u5ba2\u6237\u7aef\u548c\u00a0<code>upload<\/code>\u00a0\u65b9\u6cd5\u4e0a\u4f20\u6587\u4ef6\u3002\u8ba9\u6211\u4eec\u5bf9\u5176\u4e2d\u4e00\u4e2a\u6587\u4ef6\u8fdb\u884c\u5c1d\u8bd5\u3002<\/p>\n<pre>invoice_pdf = client.files.upload(file=\"invoice.pdf\", config={'display_name': 'invoice'})<\/pre>\n<p><em>\u6ce8\u610f\uff1aFile API \u5141\u8bb8\u6bcf\u4e2a\u9879\u76ee\u6700\u591a\u5b58\u50a8 20 GB \u7684\u6587\u4ef6\uff0c\u6bcf\u4e2a\u6587\u4ef6\u6700\u5927\u5927\u5c0f\u4e3a 2 GB\u3002\u6587\u4ef6\u5b58\u50a8 48 \u5c0f\u65f6\u3002\u5728\u6b64\u671f\u95f4\uff0c\u53ef\u4ee5\u4f7f\u7528\u7528\u6237\u7684 API \u5bc6\u94a5\u8bbf\u95ee\u8fd9\u4e9b\u6587\u4ef6\uff0c\u4f46\u65e0\u6cd5\u4e0b\u8f7d\u3002\u6587\u4ef6\u4e0a\u4f20\u662f\u514d\u8d39\u7684\u3002<\/em><\/p>\n<p>\u6587\u4ef6\u4e0a\u4f20\u540e\uff0c\u8bfb\u8005\u53ef\u4ee5\u68c0\u67e5\u5b83\u88ab\u8f6c\u6362\u4e3a\u591a\u5c11 Token\u3002\u8fd9\u4e0d\u4ec5\u6709\u52a9\u4e8e\u7406\u89e3\u7528\u6237\u6b63\u5728\u5904\u7406\u7684\u4e0a\u4e0b\u6587\uff0c\u8fd8\u6709\u52a9\u4e8e\u8ddf\u8e2a\u6210\u672c\u3002<\/p>\n<pre>file_size = client.models.count_tokens(model=model_id,contents=invoice_pdf)\r\nprint(f'File: {invoice_pdf.display_name} equals to {file_size.total_tokens} tokens')\r\n# File: invoice equals to 821 <a href=\"https:\/\/www.kdjingpai.com\/pt\/tokenization\/\">tokens<\/a><\/pre>\n<p>&nbsp;<\/p>\n<h2>3. \u4f7f\u7528 Gemini 2.0 \u548c Pydantic \u5b9e\u73b0\u7ed3\u6784\u5316\u8f93\u51fa<\/h2>\n<p>\u7ed3\u6784\u5316\u8f93\u51fa\u662f\u4e00\u9879\u529f\u80fd\uff0c\u53ef\u786e\u4fdd Gemini \u59cb\u7ec8\u751f\u6210\u7b26\u5408\u9884\u5b9a\u4e49\u683c\u5f0f\uff08\u4f8b\u5982 JSON Schema\uff09\u7684\u54cd\u5e94\u3002\u8fd9\u610f\u5473\u7740\u7528\u6237\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u8f93\u51fa\u4ee5\u53ca\u5982\u4f55\u5c06\u5176\u96c6\u6210\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4fdd\u8bc1\u8fd4\u56de\u5177\u6709\u7528\u6237\u5b9a\u4e49\u7684 Schema \u7684\u6709\u6548 JSON \u5bf9\u8c61\u3002<\/p>\n<p>Gemini 2.0 \u5f53\u524d\u652f\u6301 3 \u79cd\u4e0d\u540c\u7684\u5b9a\u4e49 JSON Schema \u7684\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u5355\u4e2a Python \u7c7b\u578b\uff0c\u5c31\u50cf\u5728\u00a0<a href=\"https:\/\/docs.python.org\/3\/library\/typing.html\">typing annotation<\/a>\u00a0\u4e2d\u4f7f\u7528\u7684\u4e00\u6837\u3002<\/li>\n<li>Pydantic\u00a0<a href=\"https:\/\/docs.pydantic.dev\/latest\/concepts\/models\/\">BaseModel<\/a><\/li>\n<li><a href=\"https:\/\/googleapis.github.io\/python-genai\/genai.html#genai.types.Schema\">genai.types.Schema<\/a>\u00a0\/\u00a0<a href=\"https:\/\/docs.pydantic.dev\/latest\/concepts\/models\/\">Pydantic BaseModel<\/a>\u00a0\u7684\u5b57\u5178\u7b49\u4ef7\u7269<\/li>\n<\/ul>\n<p>\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u57fa\u4e8e\u6587\u672c\u7684\u5feb\u901f\u793a\u4f8b\u3002<\/p>\n<pre>from pydantic import BaseModel, Field\r\n \r\n# Define a Pydantic model\r\n# Use the Field class to add a description and default value to provide more context to the model\r\nclass Topic(BaseModel):\r\n    name: str = Field(description=\"The name of the topic\")\r\n \r\nclass Person(BaseModel):\r\n    first_name: str = Field(description=\"The first name of the person\")\r\n    last_name: str = Field(description=\"The last name of the person\")\r\n    age: int = Field(description=\"The age of the person, if not provided please return 0\")\r\n    work_topics: list[Topic] = Field(description=\"The fields of interest of the person, if not provided please return an empty list\")\r\n \r\n \r\n# Define the prompt\r\nprompt = \"Philipp Schmid is a Senior AI Developer Relations Engineer at Google DeepMind working on Gemini, Gemma with the mission to help every developer to build and benefit from AI in a responsible way.  \"\r\n \r\n# Generate a response using the Person model\r\nresponse = client.models.generate_content(model=model_id, contents=prompt, config={'response_mime_type': 'application\/json', 'response_schema': Person})\r\n \r\n# print the response as a json string\r\nprint(response.text)\r\n \r\n# sdk automatically converts the response to the pydantic model\r\nphilipp: Person = response.parsed\r\n \r\n# access an attribute of the json response\r\nprint(f\"First name is {philipp.first_name}\")<\/pre>\n<p>&nbsp;<\/p>\n<h2>4. \u4f7f\u7528 Gemini 2.0 \u4ece PDF \u4e2d\u63d0\u53d6\u7ed3\u6784\u5316\u6570\u636e<\/h2>\n<p>\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u7ed3\u5408 File API \u548c\u7ed3\u6784\u5316\u8f93\u51fa\uff0c\u4ece PDF \u4e2d\u63d0\u53d6\u4fe1\u606f\u3002\u7528\u6237\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u63a5\u53d7\u672c\u5730\u6587\u4ef6\u8def\u5f84\u548c Pydantic \u6a21\u578b\uff0c\u5e76\u4e3a\u7528\u6237\u8fd4\u56de\u7ed3\u6784\u5316\u6570\u636e\u3002\u8be5\u65b9\u6cd5\u5c06\uff1a<\/p>\n<ol>\n<li>\u5c06\u6587\u4ef6\u4e0a\u4f20\u5230 File API<\/li>\n<li>\u4f7f\u7528 <a href=\"https:\/\/www.kdjingpai.com\/pt\/google-ai-studioai\/\">Gemini API<\/a> \u751f\u6210\u7ed3\u6784\u5316\u54cd\u5e94<\/li>\n<li>\u5c06\u54cd\u5e94\u8f6c\u6362\u4e3a Pydantic \u6a21\u578b\u5e76\u8fd4\u56de<\/li>\n<\/ol>\n<pre>def extract_structured_data(file_path: str, model: BaseModel):\r\n    # Upload the file to the File API\r\n    file = client.files.upload(file=file_path, config={'display_name': file_path.split('\/')[-1].split('.')[0]})\r\n    # Generate a structured response using the Gemini API\r\n    prompt = f\"Extract the structured data from the following PDF file\"\r\n    response = client.models.generate_content(model=model_id, contents=[prompt, file], config={'response_mime_type': 'application\/json', 'response_schema': model})\r\n    # Convert the response to the pydantic model and return it\r\n    return response.parsed<\/pre>\n<p>\u5728\u793a\u4f8b\u4e2d\uff0c\u6bcf\u4e2a PDF \u5f7c\u6b64\u4e0d\u540c\u3002\u56e0\u6b64\uff0c\u7528\u6237\u9700\u8981\u4e3a\u6bcf\u4e2a PDF \u5b9a\u4e49\u552f\u4e00\u7684 Pydantic \u6a21\u578b\uff0c\u4ee5\u5c55\u793a Gemini 2.0 \u7684\u6027\u80fd\u3002\u5982\u679c\u7528\u6237\u6709\u975e\u5e38\u76f8\u4f3c\u7684 PDF \u5e76\u4e14\u60f3\u8981\u63d0\u53d6\u76f8\u540c\u7684\u4fe1\u606f\uff0c\u5219\u53ef\u4ee5\u5bf9\u6240\u6709 PDF \u4f7f\u7528\u76f8\u540c\u7684\u6a21\u578b\u3002<\/p>\n<ul>\n<li><code>Invoice.pdf<\/code>\uff1a\u63d0\u53d6\u53d1\u7968\u53f7\u7801\u3001\u65e5\u671f\u548c\u6240\u6709\u5217\u8868\u9879\uff0c\u5305\u62ec\u63cf\u8ff0\u3001\u6570\u91cf\u548c\u603b\u4ef7\u503c\u4ee5\u53ca\u603b\u603b\u4ef7\u503c<\/li>\n<li><code>handwriting_form.pdf<\/code>\uff1a\u63d0\u53d6\u8868\u5355\u53f7\u7801\u3001\u8ba1\u5212\u5f00\u59cb\u65e5\u671f\u4ee5\u53ca\u5e74\u521d\u548c\u5e74\u672b\u7684\u8ba1\u5212\u8d1f\u503a<\/li>\n<\/ul>\n<p><em>\u6ce8\u610f\uff1a\u4f7f\u7528 Pydantic \u529f\u80fd\uff0c\u7528\u6237\u53ef\u4ee5\u5411\u6a21\u578b\u6dfb\u52a0\u66f4\u591a\u4e0a\u4e0b\u6587\uff0c\u4f7f\u5176\u66f4\u51c6\u786e\uff0c\u5e76\u5bf9\u6570\u636e\u8fdb\u884c\u4e00\u4e9b\u9a8c\u8bc1\u3002\u6dfb\u52a0\u5168\u9762\u7684\u63cf\u8ff0\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002instructor\u00a0\u7b49\u5e93\u6dfb\u52a0\u4e86\u57fa\u4e8e\u9a8c\u8bc1\u9519\u8bef\u7684\u81ea\u52a8\u91cd\u8bd5\uff0c\u8fd9\u53ef\u80fd\u4f1a\u6709\u5f88\u5927\u5e2e\u52a9\uff0c\u4f46\u4f1a\u589e\u52a0\u989d\u5916\u7684\u8bf7\u6c42\u6210\u672c\u3002<\/em><\/p>\n<h3>Invoice.pdf<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-21361\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/e5f96ae00443877.png\" width=\"760\" height=\"1075\" alt=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-1\" title=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-1\" \/><\/p>\n<pre>from pydantic import BaseModel, Field\r\n \r\nclass Item(BaseModel):\r\n    description: str = Field(description=\"The description of the item\")\r\n    quantity: float = Field(description=\"The Qty of the item\")\r\n    gross_worth: float = Field(description=\"The gross worth of the item\")\r\n \r\nclass Invoice(BaseModel):\r\n    \"\"\"Extract the invoice number, date and all list items with description, quantity and gross worth and the total gross worth.\"\"\"\r\n    invoice_number: str = Field(description=\"The invoice number e.g. 1234567890\")\r\n    date: str = Field(description=\"The date of the invoice e.g. 2024-01-01\")\r\n    items: list[Item] = Field(description=\"The list of items with description, quantity and gross worth\")\r\n    total_gross_worth: float = Field(description=\"The total gross worth of the invoice\")\r\n \r\n \r\nresult = extract_structured_data(\"invoice.pdf\", Invoice)\r\nprint(type(result))\r\nprint(f\"Extracted Invoice: {result.invoice_number} on {result.date} with total gross worth {result.total_gross_worth}\")\r\nfor item in result.items:\r\n    print(f\"Item: {item.description} with quantity {item.quantity} and gross worth {item.gross_worth}\")<\/pre>\n<p>\u592a\u68d2\u4e86\uff01\u8be5\u6a21\u578b\u5728\u4ece\u53d1\u7968\u4e2d\u63d0\u53d6\u4fe1\u606f\u65b9\u9762\u505a\u5f97\u975e\u5e38\u51fa\u8272\u3002<\/p>\n<h3>handwriting_form.pdf<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-21362\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/20283c71cff4c9e.jpg\" width=\"612\" height=\"792\" alt=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-2\" title=\"\u4ece PDF \u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\uff1aGemini 2.0 \u7ed3\u6784\u5316\u8f93\u51fa\u65b9\u6848-2\" \/><\/p>\n<pre>class Form(BaseModel):\r\n    \"\"\"Extract the form number, fiscal start date, fiscal end date, and the plan liabilities beginning of the year and end of the year.\"\"\"\r\n    form_number: str = Field(description=\"The Form Number\")\r\n    start_date: str = Field(description=\"Effective Date\")\r\n    beginning_of_year: float = Field(description=\"The plan liabilities beginning of the year\")\r\n    end_of_year: float = Field(description=\"The plan liabilities end of the year\")\r\n \r\nresult = extract_structured_data(\"handwriting_form.pdf\", Form)\r\n \r\nprint(f'Extracted Form Number: {result.form_number} with start date {result.start_date}. \\nPlan liabilities beginning of the year {result.beginning_of_year} and end of the year {result.end_of_year}')\r\n# Extracted Form Number: CA530082 with start date 02\/05\/2022. \r\n# Plan liabilities beginning of the year 40000.0 and end of the year 55000.0<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6700\u4f73\u5b9e\u8df5\u548c\u5c40\u9650\u6027<\/h2>\n<p>\u5728\u4f7f\u7528 Gemini 2.0 \u8fdb\u884c PDF \u5904\u7406\u65f6\uff0c\u8bf7\u8bb0\u4f4f\u4ee5\u4e0b\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ol>\n<li>\u6587\u4ef6\u5927\u5c0f\u7ba1\u7406\uff1a\u867d\u7136 File API \u652f\u6301\u5927\u6587\u4ef6\uff0c\u4f46\u6700\u4f73\u5b9e\u8df5\u662f\u5728\u4e0a\u4f20\u4e4b\u524d\u4f18\u5316 PDF\u3002<\/li>\n<li>Token \u9650\u5236\uff1a\u5904\u7406\u5927\u578b\u6587\u6863\u65f6\uff0c\u8bf7\u68c0\u67e5 Token \u8ba1\u6570\uff0c\u4ee5\u786e\u4fdd\u7528\u6237\u4fdd\u6301\u5728\u6a21\u578b\u9650\u5236\u548c\u9884\u7b97\u8303\u56f4\u5185\u3002<\/li>\n<li>\u7ed3\u6784\u5316\u8f93\u51fa\u8bbe\u8ba1\uff1a\u4ed4\u7ec6\u8bbe\u8ba1\u7528\u6237\u7684 Pydantic \u6a21\u578b\uff0c\u4ee5\u6355\u83b7\u6240\u6709\u5fc5\u8981\u4fe1\u606f\uff0c\u540c\u65f6\u4fdd\u6301\u6e05\u6670\u5ea6\uff0c\u6dfb\u52a0\u63cf\u8ff0\u548c\u793a\u4f8b\u53ef\u4ee5\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/li>\n<li>\u9519\u8bef\u5904\u7406\uff1a\u4e3a\u6587\u4ef6\u4e0a\u4f20\u548c\u5904\u7406\u72b6\u6001\u5b9e\u65bd\u7a33\u5065\u7684\u9519\u8bef\u5904\u7406\uff0c\u5305\u62ec\u91cd\u8bd5\u548c\u5904\u7406\u6765\u81ea\u6a21\u578b\u7684\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p>Gemini 2.0 \u7684\u591a\u6a21\u6001\u529f\u80fd\u4e0e\u7ed3\u6784\u5316\u8f93\u51fa\u76f8\u7ed3\u5408\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5904\u7406\u548c\u63d0\u53d6 PDF \u548c\u5176\u4ed6\u6587\u4ef6\u4e2d\u7684\u4fe1\u606f\u3002\u8fd9\u53ef\u4ee5\u6d88\u9664\u590d\u6742\u4e14\u8017\u65f6\u8d39\u529b\u7684\u4eba\u5de5\u6216\u534a\u81ea\u52a8\u6570\u636e\u63d0\u53d6\u6d41\u7a0b\u3002\u65e0\u8bba\u7528\u6237\u662f\u6784\u5efa\u53d1\u7968\u5904\u7406\u7cfb\u7edf\u3001\u6587\u6863\u5206\u6790\u5de5\u5177\u8fd8\u662f\u4efb\u4f55\u5176\u4ed6\u4ee5\u6587\u6863\u4e3a\u4e2d\u5fc3\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u90fd\u5e94\u8be5\u5c1d\u8bd5 Gemini 2.0\uff0c\u56e0\u4e3a\u5b83\u6700\u521d\u53ef\u4ee5\u514d\u8d39\u6d4b\u8bd5\uff0c\u4e4b\u540e\u6bcf\u767e\u4e07\u8f93\u5165 Token \u4ec5\u9700 0.1 \u7f8e\u5143\u3002 \u8c37\u6b4c\u5f3a\u8c03 Gemini 2.0 \u521d\u671f\u6d4b\u8bd5\u514d\u8d39\uff0c\u4e4b\u540e\u6bcf\u767e\u4e07 Token \u4ec5\u9700 0.1 \u7f8e\u5143\uff0c\u8fd9\u65e0\u7591\u964d\u4f4e\u4e86\u7528\u6237\u5c1d\u8bd5\u65b0\u6280\u672f\u7684\u95e8\u69db\uff0c\u4f46\u957f\u671f\u6210\u672c\u6548\u76ca\u4ecd\u9700\u8fdb\u4e00\u6b65\u89c2\u5bdf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u5468\uff0cGoogle DeepMind \u53d1\u5e03\u4e86 Gemini 2.0\uff0c\u5176\u4e2d\u5305\u62ec Gemini 2.0 Flash\uff08\u5168\u9762\u53ef\u7528\uff09\u3001Gemini 2.0 Flash-Lite\uff08\u5168\u65b0\u9ad8\u6027\u4ef7\u6bd4\uff09\u548c Gemini 2.0 Pro\uff08\u5b9e\u9a8c\u6027\uff09\u3002\u6240\u6709\u6a21\u578b\u90fd\u652f\u6301&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-20743","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/20743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/comments?post=20743"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/20743\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/media?parent=20743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/categories?post=20743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/tags?post=20743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}