1:"$Sreact.fragment" 2:I[31,[],""] 3:I[3331,[],""] 5:I[6045,[],"OutletBoundary"] 7:I[923,[],"AsyncMetadataOutlet"] 9:I[6045,[],"ViewportBoundary"] b:I[6045,[],"MetadataBoundary"] c:"$Sreact.suspense" e:I[4293,[],""] :HL["/_next/static/css/2361be48fe3f9cd5.css","style"] 0:{"P":null,"b":"m5tNwFFaXp3ebnJp_wTaz","p":"","c":["","blog","0001"],"i":false,"f":[[["",{"children":["blog",{"children":[["slug","0001","d"],{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true]}],["",["$","$1","c",{"children":[null,["$","$L2",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L3",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":404}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],[]],"forbidden":"$undefined","unauthorized":"$undefined"}]]}],{"children":["blog",["$","$1","c",{"children":[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/2361be48fe3f9cd5.css","precedence":"next","crossOrigin":"$undefined","nonce":"$undefined"}]],["$","html",null,{"children":["$","body",null,{"children":["$","$L2",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L3",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","forbidden":"$undefined","unauthorized":"$undefined"}]}]}]]}],{"children":[["slug","0001","d"],["$","$1","c",{"children":[null,["$","$L2",null,{"parallelRouterKey":"children","error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L3",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","forbidden":"$undefined","unauthorized":"$undefined"}]]}],{"children":["__PAGE__",["$","$1","c",{"children":["$L4",null,["$","$L5",null,{"children":["$L6",["$","$L7",null,{"promise":"$@8"}]]}]]}],{},null,false]},null,false]},null,false]},null,false],["$","$1","h",{"children":[null,[["$","$L9",null,{"children":"$La"}],null],["$","$Lb",null,{"children":["$","div",null,{"hidden":true,"children":["$","$c",null,{"fallback":null,"children":"$Ld"}]}]}]]}],false]],"m":"$undefined","G":["$e",[]],"s":false,"S":true} f:I[4742,["742","static/chunks/742-371c6136941b441c.js","953","static/chunks/app/blog/%5Bslug%5D/page-597c8504c0e17404.js"],""] 4:["$","div",null,{"className":"text-black bg-zinc-200","children":[["$","div",null,{"className":"pt-2 pb-2 pl-3 pr-3 ","children":["$","$Lf",null,{"href":"/","className":"hover:text-gray-500","children":["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-house","aria-hidden":"true","children":[["$","path","5wwlr5",{"d":"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"}],["$","path","1d0kgt",{"d":"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}],"$undefined"]}]}]}],["$","div",null,{"className":"p-3","children":[["$","div",null,{"className":"text-center text-3xl","children":"🤖"}],["$","div",null,{"className":"text-4xl font-bold text-center pt-2 pb-2","children":"PythonでOpenAI APIを使ってみる"}],["$","div",null,{"className":"text-right pb-3","children":[["$","div",null,{"children":["公開日 ","2025/07/28"]}],["$","div",null,{"children":["更新日 ","2025/07/28"]}]]}],["$","div",null,{"data-slot":"card","className":"flex flex-col gap-6 rounded-xl border py-6 shadow-sm text-black bg-zinc-100 border-none","children":[["$","div",null,{"data-slot":"card-header","className":"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6","children":["$","div",null,{"className":"flex w-full flex-wrap gap-2","children":[["$","span","0",{"data-slot":"badge","className":"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden border-transparent [a&]:hover:bg-secondary/90 bg-teal-600 text-white dark:bg-blue-600","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-badge-check","aria-hidden":"true","children":[["$","path","3c2336",{"d":"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z"}],["$","path","dzmm74",{"d":"m9 12 2 2 4-4"}],"$undefined"]}],"プログラミング"]}],["$","span","1",{"data-slot":"badge","className":"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden border-transparent [a&]:hover:bg-secondary/90 bg-teal-600 text-white dark:bg-blue-600","children":[["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-badge-check","aria-hidden":"true","children":[["$","path","3c2336",{"d":"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z"}],["$","path","dzmm74",{"d":"m9 12 2 2 4-4"}],"$undefined"]}],"Python"]}],["$","span","2",{"data-slot":"badge","className":"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden border-transparent [a&]:hover:bg-secondary/90 bg-teal-600 text-white dark:bg-blue-600","children":["$L10","AI"]}]]}]}],"$L11","$L12"]}]]}],"$L13"]}] 10:["$","svg",null,{"ref":"$undefined","xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-badge-check","aria-hidden":"true","children":[["$","path","3c2336",{"d":"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z"}],["$","path","dzmm74",{"d":"m9 12 2 2 4-4"}],"$undefined"]}] 11:["$","div",null,{"data-slot":"card-content","className":"px-6","children":["$","div",null,{"className":"pl-2 pr-2","children":[["$","div",null,{"className":"p-1","children":"Pythonを使ってOpenAI APIを実行する方法の一例をまとめる。"}],"\n",["$","div",null,{"className":"p-1","children":"目的としては、\r\n今後LLMを使った様々なシステムやアプリの開発をしていきたいと考えており、\r\nベースとなる構造を1つでも用意する事でそこからパターンを増やしていくことです。"}],"\n",["$","div",null,{"className":"p-1","children":"なるべくシンプルなファイル構造にしており、\r\n今後のPoC開発などでも流用しやすくしています。"}],"\n",["$","h2",null,{"className":"text-xl font-bold pt-3 pb-3","children":"ファイル一覧"}],"\n",["$","div",null,{"className":"p-1","children":"今回重要なファイルは以下の通りである。"}],"\n",["$","ul",null,{"className":"pt-2 pb-2","children":["\n",["$","li",null,{"className":"list-disc list-inside pl-2","children":[["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"main.py"}]," : Pythonの実行ファイル。"]}],"\n",["$","li",null,{"className":"list-disc list-inside pl-2","children":[["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"requirements.txt"}]," : Pythonで必要となるライブラリが列挙されているファイル。"]}],"\n",["$","li",null,{"className":"list-disc list-inside pl-2","children":[["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":".env"}]," : 環境変数などを設定するファイル。"]}],"\n"]}],"\n",["$","div",null,{"className":"p-1","children":"また、Dockerで実行環境を構築させたい場合は以下のファイルも用意することをお勧めします。"}],"\n",["$","ul",null,{"className":"pt-2 pb-2","children":["\n",["$","li",null,{"className":"list-disc list-inside pl-2","children":[["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"docker-compose.yml"}]," : Docker Composeの設定ファイル。"]}],"\n",["$","li",null,{"className":"list-disc list-inside pl-2","children":[["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"Dockerfile"}]," : Dockerファイル。"]}],"\n"]}],"\n",["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-sh","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{},"children":["C:.\r\n"]}],"│ docker-compose.yml\r\n","│\r\n","└─app\r\n"," .env\r\n"," Dockerfile\r\n"," main.py\r\n",["$","span","code-segement7",{"className":"$undefined","style":{},"children":[" requi"]}],["$","span","code-segement8",{"className":"$undefined","style":{"color":"#888"},"children":["rements.txt"]}]]]}]}]}]}],"\n",["$","h3",null,{"className":"text-lg font-bold pt-2 pb-2","children":"main.py"}],"\n",["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-py","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["import"]}],["$","span","code-segement1",{"className":"$undefined","style":{},"children":[" os\r\n"]}],["$","span","code-segement2",{"className":"$undefined","style":{},"children":[""]}],["$","span","code-segement3",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["import"]}],["$","span","code-segement4",{"className":"$undefined","style":{},"children":[" openai\r\n"]}],["$","span","code-segement5",{"className":"$undefined","style":{},"children":[""]}],["$","span","code-segement6",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["from"]}],["$","span","code-segement7",{"className":"$undefined","style":{},"children":[" dotenv "]}],["$","span","code-segement8",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["import"]}],["$","span","code-segement9",{"className":"$undefined","style":{},"children":[" load_dotenv\r\n"]}],"\r\n",["$","span","code-segement11",{"className":"$undefined","style":{},"children":[""]}],["$","span","code-segement12",{"className":"$undefined","style":{"color":"#888"},"children":["# .env ファイルからAPIキーを取得"]}],["$","span","code-segement13",{"className":"$undefined","style":{},"children":["\r\n"]}],"load_dotenv()\r\n",["$","span","code-segement15",{"className":"$undefined","style":{},"children":["OPENAI_API_KEY = os.getenv("]}],["$","span","code-segement16",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"OPENAI_API_KEY\""]}],["$","span","code-segement17",{"className":"$undefined","style":{},"children":[")\r\n"]}],"openai_client = openai.OpenAI(api_key=OPENAI_API_KEY)\r\n","\r\n","\r\n","$L14","$L15","$L16","$L17","$L18","$L19","$L1a","$L1b","$L1c","$L1d","$L1e","$L1f","$L20","$L21","$L22","$L23","$L24","$L25","$L26","$L27","$L28"," response = openai_client.chat.completions.create(\r\n","$L29","$L2a","$L2b"," messages=[\r\n","$L2c","$L2d","$L2e","$L2f","$L30","$L31","$L32","$L33","$L34","$L35","$L36","$L37","$L38","$L39","$L3a","$L3b","$L3c","$L3d","$L3e","$L3f"," ]\r\n"," )\r\n","$L40","$L41","$L42","\r\n","$L43","$L44","$L45","$L46","$L47","$L48","$L49","$L4a","$L4b","\r\n","\r\n","$L4c","$L4d","$L4e","$L4f","$L50","$L51","$L52","$L53"]]}]}]}]}],"\n","$L54","\n","$L55","\n","$L56","\n","$L57","\n","$L58","\n","$L59","\n","$L5a","\n","$L5b","\n","$L5c","\n","$L5d","\n","$L5e","\n","$L5f","\n","$L60","\n","$L61"]}]}] 12:["$","div",null,{"data-slot":"card-footer","className":"flex items-center px-6 [.border-t]:pt-6"}] 13:["$","footer",null,{"className":"bg-neutral-800 text-white mt-16 py-6","children":["$","div",null,{"className":"container mx-auto px-4","children":["$","div",null,{"className":"flex flex-col md:flex-row justify-between items-center","children":[["$","div",null,{"className":"flex space-x-4 mb-4 md:mb-0"}],["$","p",null,{"className":"text-sm text-gray-400","children":"© 2025 Shinjo Syntax. All rights reserved."}]]}]}]}] 14:["$","span","code-segement21",{"className":"$undefined","style":{},"children":[""]}] 15:["$","span","code-segement22",{"className":"hljs-function","style":{"color":"#fcc28c"},"children":["def"]}] 16:["$","span","code-segement23",{"className":"hljs-function","style":{},"children":[" "]}] 17:["$","span","code-segement24",{"className":"hljs-function","style":{"color":"#ffa"},"children":["say_hello"]}] 18:["$","span","code-segement25",{"className":"hljs-function","style":{},"children":["("]}] 19:["$","span","code-segement26",{"className":"hljs-function hljs-params","style":{},"children":["prompt: "]}] 1a:["$","span","code-segement27",{"className":"hljs-function hljs-params","style":{"color":"#ffa"},"children":["str"]}] 1b:["$","span","code-segement28",{"className":"hljs-function","style":{},"children":[") -> "]}] 1c:["$","span","code-segement29",{"className":"hljs-function","style":{"color":"#ffa"},"children":["dict"]}] 1d:["$","span","code-segement30",{"className":"hljs-function","style":{},"children":[":"]}] 1e:["$","span","code-segement31",{"className":"$undefined","style":{},"children":["\r\n"]}] 1f:["$","span","code-segement32",{"className":"$undefined","style":{},"children":[" "]}] 20:["$","span","code-segement33",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"\"\"\r\n"]}] 21:["$","span","code-segement34",{"className":"$undefined","style":{"color":"#a2fca2"},"children":[" OpenAI APIのLLMを使って解答を取得する。\r\n"]}] 22:["$","span","code-segement35",{"className":"$undefined","style":{"color":"#a2fca2"},"children":[" \"\"\""]}] 23:["$","span","code-segement36",{"className":"$undefined","style":{},"children":["\r\n"]}] 24:["$","span","code-segement37",{"className":"$undefined","style":{},"children":[" "]}] 25:["$","span","code-segement38",{"className":"$undefined","style":{"color":"#ffa"},"children":["print"]}] 26:["$","span","code-segement39",{"className":"$undefined","style":{},"children":["("]}] 27:["$","span","code-segement40",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"say hello\""]}] 28:["$","span","code-segement41",{"className":"$undefined","style":{},"children":[")\r\n"]}] 29:["$","span","code-segement43",{"className":"$undefined","style":{},"children":[" model="]}] 2a:["$","span","code-segement44",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"gpt-4o-mini\""]}] 2b:["$","span","code-segement45",{"className":"$undefined","style":{},"children":[",\r\n"]}] 2c:["$","span","code-segement47",{"className":"$undefined","style":{},"children":[" {"]}] 2d:["$","span","code-segement48",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"role\""]}] 2e:["$","span","code-segement49",{"className":"$undefined","style":{},"children":[": "]}] 2f:["$","span","code-segement50",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"system\""]}] 30:["$","span","code-segement51",{"className":"$undefined","style":{},"children":[", "]}] 31:["$","span","code-segement52",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"content\""]}] 32:["$","span","code-segement53",{"className":"$undefined","style":{},"children":[": "]}] 33:["$","span","code-segement54",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"以下の回答に英語でこたえてください。\""]}] 34:["$","span","code-segement55",{"className":"$undefined","style":{},"children":["},\r\n"]}] 35:["$","span","code-segement56",{"className":"$undefined","style":{},"children":[" {"]}] 36:["$","span","code-segement57",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"role\""]}] 37:["$","span","code-segement58",{"className":"$undefined","style":{},"children":[": "]}] 38:["$","span","code-segement59",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"user\""]}] 39:["$","span","code-segement60",{"className":"$undefined","style":{},"children":[", "]}] 3a:["$","span","code-segement61",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"content\""]}] 3b:["$","span","code-segement62",{"className":"$undefined","style":{},"children":[": "]}] 3c:["$","span","code-segement63",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["f\"質問: "]}] 3d:["$","span","code-segement64",{"className":"hljs-subst","style":{"color":"#a2fca2"},"children":["{prompt}"]}] 3e:["$","span","code-segement65",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\""]}] 3f:["$","span","code-segement66",{"className":"$undefined","style":{},"children":["}\r\n"]}] 40:["$","span","code-segement69",{"className":"$undefined","style":{},"children":[" "]}] 41:["$","span","code-segement70",{"className":"$undefined","style":{"color":"#ffa"},"children":["print"]}] 42:["$","span","code-segement71",{"className":"$undefined","style":{},"children":["(response)\r\n"]}] 43:["$","span","code-segement73",{"className":"$undefined","style":{},"children":[" message_content = response.choices["]}] 44:["$","span","code-segement74",{"className":"$undefined","style":{"color":"#d36363"},"children":["0"]}] 45:["$","span","code-segement75",{"className":"$undefined","style":{},"children":["].message.content\r\n"]}] 46:["$","span","code-segement76",{"className":"$undefined","style":{},"children":[" "]}] 47:["$","span","code-segement77",{"className":"$undefined","style":{"color":"#ffa"},"children":["print"]}] 48:["$","span","code-segement78",{"className":"$undefined","style":{},"children":["(message_content)\r\n"]}] 49:["$","span","code-segement79",{"className":"$undefined","style":{},"children":[" "]}] 4a:["$","span","code-segement80",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["return"]}] 4b:["$","span","code-segement81",{"className":"$undefined","style":{},"children":[" {}\r\n"]}] 4c:["$","span","code-segement84",{"className":"$undefined","style":{},"children":[""]}] 4d:["$","span","code-segement85",{"className":"$undefined","style":{"color":"#fcc28c"},"children":["if"]}] 4e:["$","span","code-segement86",{"className":"$undefined","style":{},"children":[" __name__ == "]}] 4f:["$","span","code-segement87",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"__main__\""]}] 50:["$","span","code-segement88",{"className":"$undefined","style":{},"children":[":\r\n"]}] 51:["$","span","code-segement89",{"className":"$undefined","style":{},"children":[" say_hello("]}] 52:["$","span","code-segement90",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["\"挨拶をしましょう!\""]}] 53:["$","span","code-segement91",{"className":"$undefined","style":{},"children":[")"]}] 54:["$","h3",null,{"className":"text-lg font-bold pt-2 pb-2","children":"requirements.txt"}] 55:["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-txt","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{"color":"#ffa"},"children":["openai\r\n"]}],["$","span","code-segement1",{"className":"$undefined","style":{"color":"#ffa"},"children":["dotenv"]}]]]}]}]}]}] 56:["$","h3",null,{"className":"text-lg font-bold pt-2 pb-2","children":".env"}] 57:["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-env","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{"color":"#888"},"children":["# OpenAI API"]}],["$","span","code-segement1",{"className":"$undefined","style":{},"children":["\r\n"]}],"OPENAI_API_KEY="]]}]}]}]}] 58:["$","h3",null,{"className":"text-lg font-bold pt-2 pb-2","children":"Dockerfile"}] 59:["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-text","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{},"children":["# Python 3.11.8 ベースイメージを指定\r\n"]}],"FROM python:3.11.8-slim\r\n","\r\n","# システムパッケージのインストール\r\n","RUN apt-get update\r\n","\r\n","# 作業ディレクトリ\r\n","WORKDIR /app\r\n","\r\n","# 依存ファイルをコピーしてインストール\r\n","COPY requirements.txt .\r\n","\r\n","# pip更新\r\n","RUN pip install --upgrade pip && \\\r\n"," pip install --no-cache-dir -r requirements.txt\r\n","\r\n","# アプリケーションコードをコピー\r\n","COPY . /app\r\n","\r\n","# Dopplerで環境変数を注入してアプリを起動\r\n","CMD [\"python\", \"main.py\"]"]]}]}]}]}] 5a:["$","h3",null,{"className":"text-lg font-bold pt-2 pb-2","children":"docker-compose.yml"}] 5b:["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-yml","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{"color":"#d36363"},"children":["version:"]}],["$","span","code-segement1",{"className":"$undefined","style":{},"children":[" "]}],["$","span","code-segement2",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'3.9'"]}],["$","span","code-segement3",{"className":"$undefined","style":{},"children":["\r"]}],["$","span","code-segement4",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement5",{"className":"$undefined","style":{"color":"#d36363"},"children":["\r\n"]}],["$","span","code-segement6",{"className":"$undefined","style":{"color":"#d36363"},"children":["services:"]}],["$","span","code-segement7",{"className":"$undefined","style":{},"children":["\r"]}],["$","span","code-segement8",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement9",{"className":"$undefined","style":{"color":"#d36363"},"children":[" app:"]}],["$","span","code-segement10",{"className":"$undefined","style":{},"children":["\r"]}],["$","span","code-segement11",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement12",{"className":"$undefined","style":{"color":"#d36363"},"children":[" build:"]}],["$","span","code-segement13",{"className":"$undefined","style":{},"children":["\r"]}],["$","span","code-segement14",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement15",{"className":"$undefined","style":{"color":"#d36363"},"children":[" context:"]}],["$","span","code-segement16",{"className":"$undefined","style":{},"children":[" app/.\r"]}],["$","span","code-segement17",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement18",{"className":"$undefined","style":{"color":"#d36363"},"children":[" dockerfile:"]}],["$","span","code-segement19",{"className":"$undefined","style":{},"children":[" Dockerfile\r"]}],["$","span","code-segement20",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement21",{"className":"$undefined","style":{"color":"#d36363"},"children":[" container_name:"]}],["$","span","code-segement22",{"className":"$undefined","style":{},"children":[" llm-test\r"]}],["$","span","code-segement23",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement24",{"className":"$undefined","style":{"color":"#d36363"},"children":[" volumes:"]}],["$","span","code-segement25",{"className":"$undefined","style":{},"children":["\r\n"]}],["$","span","code-segement26",{"className":"$undefined","style":{},"children":[" - ./app:/app\r"]}],["$","span","code-segement27",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement28",{"className":"$undefined","style":{"color":"#d36363"},"children":[" environment:"]}],["$","span","code-segement29",{"className":"$undefined","style":{},"children":["\r"]}],["$","span","code-segement30",{"className":"$undefined","style":{"color":"#d36363"},"children":["\n"]}],["$","span","code-segement31",{"className":"$undefined","style":{"color":"#d36363"},"children":[" PYTHONUNBUFFERED:"]}],["$","span","code-segement32",{"className":"$undefined","style":{},"children":[" "]}],["$","span","code-segement33",{"className":"$undefined","style":{"color":"#d36363"},"children":["1"]}]]]}]}]}]}] 5c:["$","h2",null,{"className":"text-xl font-bold pt-3 pb-3","children":"実行結果"}] 5d:["$","pre",null,{"children":["$","div",null,{"className":"pt-3 pb-3","children":["$","pre",null,{"style":{"display":"block","overflowX":"auto","padding":"0.5em","background":"#333","color":"white"},"children":["$","code",null,{"className":"language-bash","style":{"whiteSpace":"pre"},"children":[false,[["$","span","code-segement0",{"className":"$undefined","style":{},"children":["llm-test | say hello\r\n"]}],["$","span","code-segement1",{"className":"$undefined","style":{},"children":["llm-test | ChatCompletion(id="]}],["$","span","code-segement2",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'chatcmpl-By8jgKnjxiWytox8NtsCYTtARImO0'"]}],["$","span","code-segement3",{"className":"$undefined","style":{},"children":[", choices=[Choice(finish_reason="]}],["$","span","code-segement4",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'stop'"]}],["$","span","code-segement5",{"className":"$undefined","style":{},"children":[", index=0, logprobs=None, message=ChatCompletionMessage(content="]}],["$","span","code-segement6",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'Hello! How are you today?'"]}],["$","span","code-segement7",{"className":"$undefined","style":{},"children":[", refus(content="]}],["$","span","code-segement8",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'Hello! How are you today?'"]}],["$","span","code-segement9",{"className":"$undefined","style":{},"children":[", refusal=None, role="]}],["$","span","code-segement10",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["'assistant'"]}],["$","span","code-segement11",{"className":"$undefined","style":{},"children":[", annotations=[], audio=None, function_call=None, tool_calls=None))], created=1753672960, modelpletion"]}],["$","span","code-segement12",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', service_tier='"]}],["$","span","code-segement13",{"className":"$undefined","style":{},"children":["default"]}],["$","span","code-segement14",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', system_fi='"]}],["$","span","code-segement15",{"className":"$undefined","style":{},"children":["gpt-4o-mini-2024-07-18"]}],["$","span","code-segement16",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', object='"]}],["$","span","code-segement17",{"className":"$undefined","style":{},"children":["chat.completion"]}],["$","span","code-segement18",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', service_tier='"]}],["$","span","code-segement19",{"className":"$undefined","style":{},"children":["default"]}],["$","span","code-segement20",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', system_fingerprint='"]}],["$","span","code-segement21",{"className":"$undefined","style":{},"children":["fp_62a23a81ef"]}],["$","span","code-segement22",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["', usage=CompletionUsage(completion_tokens=7, prompt__prediction_tokens=0, audio_tokens=0, reasotokens=33, total_tokens=40, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))\r\n"]}],["$","span","code-segement23",{"className":"$undefined","style":{"color":"#a2fca2"},"children":["llm-test | Hello! How are you today?"]}]]]}]}]}]}] 5e:["$","h2",null,{"className":"text-xl font-bold pt-3 pb-3","children":"まとめ"}] 5f:["$","div",null,{"className":"p-1","children":"シンプルなファイル構成とコードでOpenAI APIを使用する事が出来ました。"}] 60:["$","div",null,{"className":"p-1","children":["今後はこれを流用して",["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"MCPサーバー"}],"や",["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"RAG"}],"など色々と試していきたい事に挑戦していきます。"]}] 61:["$","div",null,{"className":"p-1","children":["また、今回は割と格安のモデルである",["$","strong",null,{"className":"bg-stone-300 text-stone-800 text-sm px-2 py-0.5 rounded-full","children":"gpt-4o-mini"}],"を使用していますが、\r\nこれを変えるだけでも出力結果が変わってくるはずなので、\r\n予算に余裕を持つことが出来たら色々と試してみたいですね。"]}] a:[["$","meta","0",{"charSet":"utf-8"}],["$","meta","1",{"name":"viewport","content":"width=device-width, initial-scale=1"}]] 6:null 62:I[8723,[],"IconMark"] 8:{"metadata":[["$","title","0",{"children":"PythonでOpenAI APIを使ってみる"}],["$","meta","1",{"name":"description","content":"Generated by Next.js"}],["$","link","2",{"rel":"icon","href":"/icon.png?6322cf53d61108b8","type":"image/png","sizes":"256x256"}],["$","$L62","3",{}]],"error":null,"digest":"$undefined"} d:"$8:metadata"