{"id":122,"date":"2025-07-25T10:40:11","date_gmt":"2025-07-25T01:40:11","guid":{"rendered":"https:\/\/i-third.org\/blog\/?p=122"},"modified":"2025-07-25T10:40:11","modified_gmt":"2025-07-25T01:40:11","slug":"gemini-api%e3%82%92%e6%b4%bb%e7%94%a8%ef%bc%81web-api%e3%82%92%e6%a7%8b%e7%af%89%e3%81%97%e3%81%a6%e9%96%8b%e7%99%ba%e5%8a%b9%e7%8e%87%e3%82%92%e5%8a%87%e7%9a%84%e3%81%ab%e4%b8%8a%e3%81%92%e3%82%8b3","status":"publish","type":"post","link":"https:\/\/i-third.org\/blog\/?p=122","title":{"rendered":"Gemini API\u3092\u6d3b\u7528\uff01Web API\u3092\u69cb\u7bc9\u3057\u3066\u958b\u767a\u52b9\u7387\u3092\u5287\u7684\u306b\u4e0a\u3052\u308b3\u3064\u306e\u30b9\u30c6\u30c3\u30d7"},"content":{"rendered":"<p>\nIT\u696d\u754c\u306e\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u3068\u3057\u3066\u6d3b\u52d5\u3057\u3066\u3044\u308b\u7686\u3055\u3093\u3001\u65e5\u3005\u306e\u958b\u767a\u696d\u52d9\u3067\u300c\u3082\u3063\u3068\u52b9\u7387\u5316\u3067\u304d\u306a\u3044\u304b\u300d\u300c\u65b0\u3057\u3044\u6280\u8853\u3092\u3069\u306e\u3088\u3046\u306b\u53d6\u308a\u5165\u308c\u308c\u3070\u826f\u3044\u304b\u300d\u3068\u60a9\u3093\u3067\u3044\u307e\u305b\u3093\u304b\uff1f<br \/>\n\u7279\u306bAI\u6280\u8853\u306e\u9032\u5316\u306f\u76ee\u899a\u307e\u3057\u304f\u3001\u305d\u306e\u4e2d\u3067\u3082Google\u304c\u63d0\u4f9b\u3059\u308b\u300cGemini API\u300d\u306f\u3001\u69d8\u3005\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5f37\u529b\u306aAI\u6a5f\u80fd\u3092\u3082\u305f\u3089\u3059\u53ef\u80fd\u6027\u3092\u79d8\u3081\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u306e\u4f5c\u6210\u65b9\u6cd5\u3092\u3001\u5177\u4f53\u7684\u306a\u624b\u9806\u3068\u5b9f\u8df5\u4f8b\u3092\u4ea4\u3048\u306a\u304c\u3089\u5fb9\u5e95\u89e3\u8aac\u3057\u307e\u3059\u3002\u3042\u306a\u305f\u306e\u958b\u767a\u30ea\u30bd\u30fc\u30b9\u3092\u30e9\u30a4\u30d6\u30e9\u30ea\u5316\u3057\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u751f\u7523\u6027\u3092\u98db\u8e8d\u7684\u306b\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306e\u9053\u7b4b\u3092\u793a\u3057\u307e\u3059\u3002\n<\/p>\n<hr>\n<h2>\u76ee\u6b21<\/h2>\n<ul>\n<li><a href=\"#section-1\">\u306a\u305c\u4eca\u3001Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u304c\u5fc5\u8981\u306a\u306e\u304b\uff1f<\/a><\/li>\n<li><a href=\"#section-2\">Gemini API\u3092\u4f7f\u3063\u305fWeb API\u4f5c\u6210\u306e\u524d\u63d0\u77e5\u8b58<\/a><\/li>\n<li><a href=\"#section-3\">Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u4f5c\u6210\u306e3\u30b9\u30c6\u30c3\u30d7<\/a><\/li>\n<ul>\n<li><a href=\"#step-1\">\u30b9\u30c6\u30c3\u30d71\uff1a\u958b\u767a\u74b0\u5883\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3068Gemini API\u30ad\u30fc\u306e\u53d6\u5f97<\/a><\/li>\n<li><a href=\"#step-2\">\u30b9\u30c6\u30c3\u30d72\uff1aWeb API\u306e\u8a2d\u8a08\u3068\u57fa\u672c\u7684\u306a\u5b9f\u88c5<\/a><\/li>\n<li><a href=\"#step-3\">\u30b9\u30c6\u30c3\u30d73\uff1a\u5b9f\u8df5\uff01\u7c21\u5358\u306a\u30c1\u30e3\u30c3\u30c8API\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3088\u3046<\/a><\/li>\n<\/ul>\n<li><a href=\"#section-4\">\u307e\u3068\u3081\uff1aGemini API\u3067\u672a\u6765\u306e\u958b\u767a\u3092\u5207\u308a\u62d3\u304f<\/a><\/li>\n<li><a href=\"#section-5\">\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3078\uff1a\u3055\u3089\u306a\u308b\u63a2\u6c42<\/a><\/li>\n<\/ul>\n<hr>\n<h2 id=\"section-1\">\u306a\u305c\u4eca\u3001Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u304c\u5fc5\u8981\u306a\u306e\u304b\uff1f<\/h2>\n<p>\n\u73fe\u4ee3\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u306b\u304a\u3044\u3066\u3001AI\u306e\u6d3b\u7528\u306f\u3082\u306f\u3084\u9078\u629e\u80a2\u3067\u306f\u306a\u304f\u5fc5\u9808\u306e\u8981\u7d20\u3068\u306a\u308a\u3064\u3064\u3042\u308a\u307e\u3059\u3002\u7279\u306b\u5927\u898f\u6a21\u8a00\u8a9e\u30e2\u30c7\u30eb\uff08LLM\uff09\u306f\u3001\u81ea\u7136\u8a00\u8a9e\u51e6\u7406\u3001\u30b3\u30f3\u30c6\u30f3\u30c4\u751f\u6210\u3001\u30c7\u30fc\u30bf\u5206\u6790\u306a\u3069\u3001\u591a\u5c90\u306b\u308f\u305f\u308b\u30bf\u30b9\u30af\u3067\u305d\u306e\u80fd\u529b\u3092\u767a\u63ee\u3057\u307e\u3059\u3002Gemini API\u3092\u6d3b\u7528\u3057\u305fWeb API\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30ea\u30c3\u30c8\u3092\u3082\u305f\u3089\u3057\u307e\u3059\u3002\n<\/p>\n<ul>\n<li><strong>\u958b\u767a\u52b9\u7387\u306e\u5411\u4e0a:<\/strong> \u5171\u901a\u306eAI\u6a5f\u80fd\u3092Web API\u3068\u3057\u3066\u30ab\u30d7\u30bb\u30eb\u5316\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u6570\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3084\u30b5\u30fc\u30d3\u30b9\u304b\u3089\u5bb9\u6613\u306b\u518d\u5229\u7528\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5404\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306eAI\u6a5f\u80fd\u306e\u5b9f\u88c5\u30b3\u30b9\u30c8\u3092\u524a\u6e1b\u3057\u3001\u958b\u767a\u671f\u9593\u3092\u77ed\u7e2e\u3067\u304d\u307e\u3059\u3002<\/li>\n<li><strong>\u4fdd\u5b88\u6027\u306e\u5411\u4e0a:<\/strong> AI\u6a5f\u80fd\u304cWeb API\u3068\u3057\u3066\u72ec\u7acb\u3057\u3066\u3044\u308b\u305f\u3081\u3001AI\u30e2\u30c7\u30eb\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3084\u8a2d\u5b9a\u5909\u66f4\u304c\u3042\u3063\u3066\u3082\u3001\u5404\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5074\u306e\u30b3\u30fc\u30c9\u306b\u5927\u304d\u306a\u5f71\u97ff\u3092\u4e0e\u3048\u308b\u3053\u3068\u306a\u304f\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002<\/li>\n<li><strong>\u30b9\u30b1\u30fc\u30e9\u30d3\u30ea\u30c6\u30a3\u306e\u78ba\u4fdd:<\/strong> Web API\u3068\u3057\u3066\u516c\u958b\u3059\u308b\u3053\u3068\u3067\u3001AI\u51e6\u7406\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u96c6\u4e2d\u7ba1\u7406\u3057\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30b9\u30b1\u30fc\u30eb\u30a2\u30a6\u30c8\u3059\u308b\u3053\u3068\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<li><strong>\u30d3\u30b8\u30cd\u30b9\u4fa1\u5024\u306e\u5275\u51fa:<\/strong> \u65e2\u5b58\u306e\u30b5\u30fc\u30d3\u30b9\u306bAI\u6a5f\u80fd\u3092\u8fc5\u901f\u306b\u7d44\u307f\u8fbc\u3080\u3053\u3068\u3067\u3001\u30e6\u30fc\u30b6\u30fc\u4f53\u9a13\u306e\u5411\u4e0a\u3084\u65b0\u3057\u3044\u30d3\u30b8\u30cd\u30b9\u30e2\u30c7\u30eb\u306e\u5275\u51fa\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u81ea\u52d5\u8981\u7d04\u3001\u30c1\u30e3\u30c3\u30c8\u30dc\u30c3\u30c8\u3001\u30b3\u30f3\u30c6\u30f3\u30c4\u751f\u6210\u652f\u63f4\u306a\u3069\u3001\u69d8\u3005\u306a\u5fdc\u7528\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/li>\n<\/ul>\n<hr>\n<h2 id=\"section-2\">Gemini API\u3092\u4f7f\u3063\u305fWeb API\u4f5c\u6210\u306e\u524d\u63d0\u77e5\u8b58<\/h2>\n<p>\nGemini API\u3092\u5229\u7528\u3057\u305fWeb API\u306e\u4f5c\u6210\u3092\u59cb\u3081\u308b\u524d\u306b\u3001\u3044\u304f\u3064\u304b\u57fa\u672c\u7684\u306a\u77e5\u8b58\u3092\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\n<\/p>\n<ul>\n<li><strong>Web API\u306e\u57fa\u790e:<\/strong> RESTful API\u306e\u6982\u5ff5\u3001HTTP\u30e1\u30bd\u30c3\u30c9\uff08GET, POST\u306a\u3069\uff09\u3001JSON\u5f62\u5f0f\u3067\u306e\u30c7\u30fc\u30bf\u9001\u53d7\u4fe1\u306e\u7406\u89e3\u304c\u5fc5\u9808\u3067\u3059\u3002<\/li>\n<li><strong>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e:<\/strong> Java (Spring Boot) \u3092\u4e2d\u5fc3\u306b\u89e3\u8aac\u3057\u307e\u3059\u304c\u3001Python (Flask\/Django) \u3084Node.js (Express) \u306a\u3069\u3001Web API\u958b\u767a\u306b\u9069\u3057\u305f\u8a00\u8a9e\u3067\u3042\u308c\u3070\u5fdc\u7528\u53ef\u80fd\u3067\u3059\u3002<\/li>\n<li><strong>AI\/LLM\u306e\u57fa\u790e\u77e5\u8b58:<\/strong> \u5927\u898f\u6a21\u8a00\u8a9e\u30e2\u30c7\u30eb\uff08LLM\uff09\u306e\u57fa\u672c\u7684\u306a\u4ed5\u7d44\u307f\u3001\u30d7\u30ed\u30f3\u30d7\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u306e\u6982\u5ff5\u3092\u7406\u89e3\u3057\u3066\u3044\u308b\u3068\u3001\u3088\u308a\u52b9\u679c\u7684\u306aAPI\u3092\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002<\/li>\n<li><strong>\u30af\u30e9\u30a6\u30c9\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306e\u5229\u7528\u7d4c\u9a13\uff08\u63a8\u5968\uff09:<\/strong> Google Cloud Platform (GCP) \u306e\u5229\u7528\u7d4c\u9a13\u304c\u3042\u308b\u3068\u3001API\u30ad\u30fc\u306e\u7ba1\u7406\u3084\u30c7\u30d7\u30ed\u30a4\u304c\u30b9\u30e0\u30fc\u30ba\u306b\u9032\u307f\u307e\u3059\u3002<\/li>\n<\/ul>\n<hr>\n<h2 id=\"section-3\">Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u4f5c\u6210\u306e3\u30b9\u30c6\u30c3\u30d7<\/h2>\n<p>\n\u3053\u3053\u304b\u3089\u306f\u3001\u5177\u4f53\u7684\u306aWeb API\u4f5c\u6210\u306e\u624b\u9806\u30923\u3064\u306e\u30b9\u30c6\u30c3\u30d7\u306b\u5206\u3051\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002\u4eca\u56de\u306fJava\u306eSpring Boot\u3092\u4f8b\u306b\u3001\u7c21\u5358\u306a\u30c1\u30e3\u30c3\u30c8API\u3092\u4f5c\u6210\u3059\u308b\u30b1\u30fc\u30b9\u3067\u9032\u3081\u307e\u3059\u3002\n<\/p>\n<hr>\n<h3 id=\"step-1\">\u30b9\u30c6\u30c3\u30d71\uff1a\u958b\u767a\u74b0\u5883\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3068Gemini API\u30ad\u30fc\u306e\u53d6\u5f97<\/h3>\n<h4>\u524d\u63d0\u77e5\u8b58<\/h4>\n<ul>\n<li>Java\u958b\u767a\u30ad\u30c3\u30c8\uff08JDK 17\u4ee5\u4e0a\uff09\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<li>Maven\u307e\u305f\u306fGradle\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/li>\n<li>\u304a\u597d\u307f\u306eIDE\uff08IntelliJ IDEA, VS Code\u306a\u3069\uff09<\/li>\n<\/ul>\n<h4>\u5177\u4f53\u7684\u306a\u624b\u9806<\/h4>\n<ol>\n<li><strong>Gemini API\u30ad\u30fc\u306e\u53d6\u5f97:<\/strong>\n<p>Google AI Studio\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001Google\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002<br \/>\n\u300cAPI\u30ad\u30fc\u3092\u53d6\u5f97\u300d\u307e\u305f\u306f\u300c\u65b0\u3057\u3044API\u30ad\u30fc\u3092\u4f5c\u6210\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001API\u30ad\u30fc\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30ad\u30fc\u306f\u5927\u5207\u306b\u4fdd\u7ba1\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\n\u53c2\u8003: <a href=\"[https:\/\/ai.google.dev\/docs\/get_started_for_web?hl=ja](https:\/\/www.google.com\/search?q=https:\/\/ai.google.dev\/docs\/get_started_for_web%3Fhl%3Dja)\" target=\"_blank\" rel=\"noopener\">Google AI Studio\u3067Gemini API\u30ad\u30fc\u3092\u53d6\u5f97\u3059\u308b<\/a>\n<\/p>\n<\/li>\n<li><strong>Spring Boot\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210:<\/strong>\n<p>Spring Initializr (<a href=\"[https:\/\/start.spring.io\/](https:\/\/start.spring.io\/)\" target=\"_blank\" rel=\"noopener\">[https:\/\/start.spring.io\/](https:\/\/start.spring.io\/)<\/a>) \u3092\u5229\u7528\u3057\u3066\u3001\u65b0\u3057\u3044Spring Boot\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>Spring Web (RESTful API\u7528)<\/li>\n<li>Spring Boot DevTools (\u958b\u767a\u52b9\u7387\u5411\u4e0a\u7528\u3001\u4efb\u610f)<\/li>\n<\/ul>\n<p>\u751f\u6210\u5f8c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092IDE\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li><strong>Gemini Java SDK\u306e\u8ffd\u52a0:<\/strong>\n<p><code>pom.xml<\/code> (Maven\u306e\u5834\u5408) \u306b\u4ee5\u4e0b\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-xml\">\n&lt;dependency&gt;\n&lt;groupId&gt;com.google.cloud&lt;\/groupId&gt;\n&lt;artifactId&gt;google-cloud-vertexai&lt;\/artifactId&gt;\n&lt;version&gt;0.1.0&lt;\/version&gt; &lt;!-- \u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044 --&gt;\n&lt;\/dependency&gt;\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<hr>\n<h3 id=\"step-2\">\u30b9\u30c6\u30c3\u30d72\uff1aWeb API\u306e\u8a2d\u8a08\u3068\u57fa\u672c\u7684\u306a\u5b9f\u88c5<\/h3>\n<h4>\u524d\u63d0\u77e5\u8b58<\/h4>\n<ul>\n<li>Spring Boot\u306eController, Service, Entity\u306e\u57fa\u672c\u7684\u306a\u5f79\u5272<\/li>\n<li>RESTful API\u306e\u8a2d\u8a08\u539f\u5247<\/li>\n<\/ul>\n<h4>\u5177\u4f53\u7684\u306a\u624b\u9806<\/h4>\n<ol>\n<li><strong><code>application.properties<\/code>\u306e\u8a2d\u5b9a:<\/strong>\n<p>\u53d6\u5f97\u3057\u305fGemini API\u30ad\u30fc\u3092<code>src\/main\/resources\/application.properties<\/code>\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-properties\">\nspring.ai.gemini.api-key=YOUR_GEMINI_API_KEY\n<\/code><\/pre>\n<\/li>\n<li><strong>\u30ea\u30af\u30a8\u30b9\u30c8\/\u30ec\u30b9\u30dd\u30f3\u30b9DPO\u306e\u5b9a\u7fa9:<\/strong>\n<p>API\u306e\u5165\u51fa\u529b\u3068\u306a\u308b\u30c7\u30fc\u30bf\u8ee2\u9001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 (DTO) \u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u30c1\u30e3\u30c3\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3068\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-java\">\n\/\/ ChatRequest.java\npublic class ChatRequest {\nprivate String message;\n\/\/ \u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30bb\u30c3\u30b7\u30e7\u30f3ID\u306a\u3069\u3092\u8ffd\u52a0\npublic String getMessage() { return message; }\npublic void setMessage(String message) { this.message = message; }\n}\n\n\/\/ ChatResponse.java\npublic class ChatResponse {\nprivate String reply;\n\/\/ \u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30b9\u30c6\u30fc\u30bf\u30b9\u60c5\u5831\u306a\u3069\u3092\u8ffd\u52a0\npublic String getReply() { return reply; }\npublic void setReply(String reply) { this.reply = reply; }\n}\n<\/code><\/pre>\n<\/li>\n<li><strong>ChatService\u306e\u5b9f\u88c5:<\/strong>\n<p>Gemini API\u3068\u306e\u9023\u643a\u30ed\u30b8\u30c3\u30af\u3092<code>Service<\/code>\u30af\u30e9\u30b9\u306b\u5b9f\u88c5\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u7c21\u5358\u306a\u30c6\u30ad\u30b9\u30c8\u751f\u6210\u3092\u4f8b\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-java\">\nimport com.google.cloud.vertexai.VertexAI;\nimport com.google.cloud.vertexai.api.GenerateContentResponse;\nimport com.google.cloud.vertexai.generativeai.GenerativeModel;\nimport com.google.cloud.vertexai.generativeai.ResponseHandler;\nimport org.springframework.stereotype.Service;\nimport java.io.IOException;\n\n@Service\npublic class ChatService {\n\n```\nprivate final String projectId = &quot;YOUR_GCP_PROJECT_ID&quot;; \/\/ \u3042\u306a\u305f\u306eGCP\u30d7\u30ed\u30b8\u30a7\u30af\u30c8ID\nprivate final String location = &quot;us-central1&quot;; \/\/ Gemini\u30e2\u30c7\u30eb\u304c\u5229\u7528\u53ef\u80fd\u306a\u30ea\u30fc\u30b8\u30e7\u30f3\n\npublic String getGeminiReply(String userMessage) throws IOException {\n    try (VertexAI vertexAi = new VertexAI(projectId, location)) {\n        GenerativeModel model = new GenerativeModel(&quot;gemini-pro&quot;, vertexAi);\n        GenerateContentResponse response = model.generateContent(userMessage);\n        return ResponseHandler.getText(response);\n    }\n}\n```\n\n}\n<\/code><\/pre>\n<p>&#8220;`\n<\/li>\n<li><strong>ChatController\u306e\u5b9f\u88c5:<\/strong>\n<p>REST\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u5b9a\u7fa9\u3057\u3001<code>ChatService<\/code>\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>&#8220;`<\/p>\n<pre><code class=\"language-java\">\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\n@RequestMapping(\"\/api\/chat\")\npublic class ChatController {\n\n```\nprivate final ChatService chatService;\n\npublic ChatController(ChatService chatService) {\n    this.chatService = chatService;\n}\n\n@PostMapping(&quot;\/send&quot;)\npublic ChatResponse sendMessage(@RequestBody ChatRequest request) {\n    ChatResponse response = new ChatResponse();\n    try {\n        String geminiReply = chatService.getGeminiReply(request.getMessage());\n        response.setReply(geminiReply);\n    } catch (IOException e) {\n        response.setReply(&quot;Error: &quot; + e.getMessage());\n    }\n    return response;\n}\n```\n\n}\n<\/code><\/pre>\n<p>&#8220;`\n<\/li>\n<p>&#8220;`<\/p>\n<\/ol>\n<hr>\n<h3 id=\"step-3\">\u30b9\u30c6\u30c3\u30d73\uff1a\u5b9f\u8df5\uff01\u7c21\u5358\u306a\u30c1\u30e3\u30c3\u30c8API\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3088\u3046<\/h3>\n<h4>\u5b9f\u8df5\u4f8b<\/h4>\n<p>\n\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5\u3057\u3001Spring Boot\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"language-bash\">\nmvn spring-boot:run\n<\/code><\/pre>\n<p>\n\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u8d77\u52d5\u3057\u305f\u3089\u3001Postman\u3084curl\u306a\u3069\u306e\u30c4\u30fc\u30eb\u3092\u4f7f\u3063\u3066API\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\n<\/p>\n<h4>Postman\u3067\u306e\u30c6\u30b9\u30c8\u4f8b<\/h4>\n<p>\n<strong>\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8:<\/strong> <code>POST http:\/\/localhost:8080\/api\/chat\/send<\/code><br \/>\n<strong>Headers:<\/strong> <code>Content-Type: application\/json<\/code><br \/>\n<strong>Body (raw JSON):<\/strong>\n<\/p>\n<pre><code class=\"language-json\">\n{\n\"message\": \"\u4eca\u65e5\u306e\u5929\u6c17\u306f\u3069\u3046\u3067\u3059\u304b\uff1f\"\n}\n<\/code><\/pre>\n<p>\n<strong>\u671f\u5f85\u3055\u308c\u308b\u30ec\u30b9\u30dd\u30f3\u30b9:<\/strong>\n<\/p>\n<pre><code class=\"language-json\">\n{\n\"reply\": \"\u672c\u65e5\u306f\u6674\u5929\u3067\u3001\u6c17\u6e29\u306f25\u5ea6\u3068\u4e88\u60f3\u3055\u308c\u3066\u3044\u307e\u3059\u3002\" \/\/ Gemini\u304b\u3089\u306e\u8fd4\u7b54\n}\n<\/code><\/pre>\n<p>\n\u3053\u306e\u3088\u3046\u306b\u3001\u3054\u304f\u30b7\u30f3\u30d7\u30eb\u306aAPI\u3067\u3059\u304c\u3001Gemini\u306e\u5f37\u529b\u306a\u30c6\u30ad\u30b9\u30c8\u751f\u6210\u80fd\u529b\u3092Web API\u3068\u3057\u3066\u516c\u958b\u3057\u3001\u69d8\u3005\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304b\u3089\u5229\u7528\u3067\u304d\u308b\u57fa\u76e4\u304c\u3067\u304d\u307e\u3057\u305f\u3002\u3053\u3053\u304b\u3089\u3001\u4f1a\u8a71\u5c65\u6b74\u306e\u7ba1\u7406\u3001\u30d7\u30ed\u30f3\u30d7\u30c8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u9069\u7528\u3001\u30b9\u30c8\u30ea\u30fc\u30df\u30f3\u30b0\u51fa\u529b\u306a\u3069\u3001\u6a5f\u80fd\u3092\u62e1\u5f35\u3057\u3066\u3044\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n<\/p>\n<hr>\n<h2 id=\"section-4\">\u307e\u3068\u3081\uff1aGemini API\u3067\u672a\u6765\u306e\u958b\u767a\u3092\u5207\u308a\u62d3\u304f<\/h2>\n<p>\n\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001IT\u696d\u754c\u306e\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u3068\u3057\u3066\u3001Gemini API\u3092\u5229\u7528\u3057\u305fWeb API\u3092\u69cb\u7bc9\u3059\u308b\u610f\u7fa9\u3068\u5177\u4f53\u7684\u306a\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002\u958b\u767a\u30ea\u30bd\u30fc\u30b9\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u5316\u306f\u3001\u5358\u306a\u308b\u30b3\u30fc\u30c9\u306e\u6574\u7406\u306b\u7559\u307e\u3089\u305a\u3001\u958b\u767a\u52b9\u7387\u306e\u5411\u4e0a\u3001\u4fdd\u5b88\u6027\u306e\u78ba\u4fdd\u3001\u305d\u3057\u3066\u65b0\u3057\u3044\u30d3\u30b8\u30cd\u30b9\u4fa1\u5024\u306e\u5275\u51fa\u306b\u76f4\u7d50\u3057\u307e\u3059\u3002\n<\/p>\n<p>\nGemini API\u3092\u4f7f\u3063\u305fWeb API\u306f\u3001\u3042\u306a\u305f\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5f37\u529b\u306aAI\u6a5f\u80fd\u3092\u3082\u305f\u3089\u3057\u3001\u958b\u767a\u306e\u53ef\u80fd\u6027\u3092\u7121\u9650\u306b\u5e83\u3052\u308b\u3067\u3057\u3087\u3046\u3002\u305c\u3072\u4eca\u65e5\u304b\u3089\u3053\u306e\u65b0\u3057\u3044\u6280\u8853\u3092\u53d6\u308a\u5165\u308c\u3001\u672a\u6765\u306e\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u3092\u5207\u308a\u62d3\u3044\u3066\u304f\u3060\u3055\u3044\u3002\n<\/p>\n<hr>\n<h2 id=\"section-5\">\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3078\uff1a\u3055\u3089\u306a\u308b\u63a2\u6c42<\/h2>\n<ul>\n<li><strong>\u4f1a\u8a71\u5c65\u6b74\u306e\u7ba1\u7406:<\/strong> <code>ChatService<\/code>\u306b\u30bb\u30c3\u30b7\u30e7\u30f3ID\u3068\u4f1a\u8a71\u5c65\u6b74\u3092\u4fdd\u5b58\u3059\u308b\u30ed\u30b8\u30c3\u30af\u3092\u8ffd\u52a0\u3057\u3001\u9023\u7d9a\u3057\u305f\u5bfe\u8a71\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n<li><strong>\u30d7\u30ed\u30f3\u30d7\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0:<\/strong> Gemini API\u306e\u5fdc\u7b54\u7cbe\u5ea6\u3092\u9ad8\u3081\u308b\u305f\u3081\u306b\u3001\u52b9\u679c\u7684\u306a\u30d7\u30ed\u30f3\u30d7\u30c8\u306e\u8a2d\u8a08\u3084\u30d7\u30ed\u30f3\u30d7\u30c8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u6d3b\u7528\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n<li><strong>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u30ed\u30ae\u30f3\u30b0:<\/strong> \u5b9f\u904b\u7528\u3092\u8003\u616e\u3057\u3001API\u547c\u3073\u51fa\u3057\u6642\u306e\u30a8\u30e9\u30fc\u51e6\u7406\u3084\u8a73\u7d30\u306a\u30ed\u30ae\u30f3\u30b0\u6a5f\u69cb\u3092\u5c0e\u5165\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n<li><strong>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3:<\/strong> API\u30ad\u30fc\u306e\u5b89\u5168\u306a\u7ba1\u7406\u3084\u3001\u8a8d\u8a3c\u30fb\u8a8d\u53ef\u306e\u4ed5\u7d44\u307f\uff08\u4f8b: JWT\uff09\u3092\u7d44\u307f\u8fbc\u3080\u3053\u3068\u3092\u691c\u8a0e\u3057\u307e\u3057\u3087\u3046\u3002<\/li>\n<\/ul>\n<p>\n\u3053\u308c\u3089\u306e\u30b9\u30c6\u30c3\u30d7\u3092\u901a\u3058\u3066\u3001\u3088\u308a\u5805\u7262\u3067\u5b9f\u7528\u7684\u306aGemini API\u3092\u6d3b\u7528\u3057\u305fWeb API\u3092\u69cb\u7bc9\u3057\u3001\u3042\u306a\u305f\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u6b21\u306e\u30ec\u30d9\u30eb\u3078\u3068\u5f15\u304d\u4e0a\u3052\u3066\u304f\u3060\u3055\u3044\u3002\n<\/p>\n<p>\n\u3054\u8cea\u554f\u3084\u3054\u610f\u898b\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u304a\u6c17\u8efd\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>IT\u696d\u754c\u306e\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u3068\u3057\u3066\u6d3b\u52d5\u3057\u3066\u3044\u308b\u7686\u3055\u3093\u3001\u65e5\u3005\u306e\u958b\u767a\u696d\u52d9\u3067\u300c\u3082\u3063\u3068\u52b9\u7387\u5316\u3067\u304d\u306a\u3044\u304b\u300d\u300c\u65b0\u3057\u3044\u6280\u8853\u3092\u3069\u306e\u3088\u3046\u306b\u53d6\u308a\u5165\u308c\u308c\u3070\u826f\u3044\u304b\u300d\u3068\u60a9\u3093\u3067\u3044\u307e\u305b\u3093\u304b\uff1f \u7279\u306bAI\u6280\u8853\u306e\u9032\u5316\u306f\u76ee\u899a\u307e\u3057\u304f\u3001\u305d\u306e\u4e2d\u3067\u3082Google\u304c\u63d0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":124,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-7"],"_links":{"self":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=122"}],"version-history":[{"count":1,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":123,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/124"}],"wp:attachment":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}