Created
February 5, 2025 01:15
-
-
Save yoshimov/8e7e6ba4e062eaa6f813995f20758ebd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "02ed709b-5a9d-482e-8cbc-1df6b0c617fe", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"室内温度が24度で、外気温が1度なので、暖房を使用する必要があります。ただし、室内温度は快適範囲(23度から25度)にあるため、エアコンを止めることができます。\n", | |
"\n", | |
"制御用のJSONは以下の通りです。\n", | |
"```\n", | |
"{\n", | |
" \"mode\": 4,\n", | |
" \"pow\": 0,\n", | |
" \"stemp\": 21,\n", | |
" \"shum\": 50\n", | |
"}\n", | |
"```\n", | |
"暖房モード(mode: 4)に設定し、電源をオフ(pow: 0)にしています。設定温度は23度から2度低い21度に設定しています。\n", | |
"\n", | |
"外出中なので、エアコンの制御は自動で行われますが、快適範囲内にあるため、エアコンは止められています。\n" | |
] | |
} | |
], | |
"source": [ | |
"from langchain_core.prompts import ChatPromptTemplate\n", | |
"from langchain_ollama import OllamaLLM\n", | |
"\n", | |
"base_url = \"sumac.local:11434\"\n", | |
"\n", | |
"template = \"\"\"室内のエアコンの制御を行います。冷房、暖房、電源オフを判定して制御用のJSONを出力してください。JSONの形式は以下の通り。\n", | |
"- modeは3が冷房、4が暖房、0が電源オフ\n", | |
"- powは0が電源オフ、1が電源オン\n", | |
"- stempに設定温度を入れる。設定しない場合は20を指定する。\n", | |
"- shumは常に50を指定する。\n", | |
"\n", | |
"以下の条件で制御してください。\n", | |
"- 外気温に応じて、寒いときは暖房のみ、暑いときは冷房のみを使う。\n", | |
"- 室内の快適温度は23度から25度とする。\n", | |
"- エアコンの制御は室内温度から判断する。\n", | |
"- 暖房の設定温度は23度\n", | |
"- 冷房の設定温度は26度\n", | |
"- 人が外出中の時は、暖房は2度低く、冷房は1度高く設定する。\n", | |
"- 外出中に快適温度にある場合はエアコンを止める\n", | |
"\n", | |
"現在の状況は以下の通りです。\n", | |
"{situation}\n", | |
"\"\"\"\n", | |
"\n", | |
"prompt = ChatPromptTemplate.from_template(template)\n", | |
"\n", | |
"llm = OllamaLLM(base_url=base_url, model=\"schroneko/llama-3.1-swallow-8b-instruct-v0.1:latest\")\n", | |
"\n", | |
"chain = prompt | llm\n", | |
"\n", | |
"situation = \"\"\"\n", | |
"- 室温:24度\n", | |
"- 外気温:1度\n", | |
"- 日時:2/5\n", | |
"- 外出中\n", | |
"\"\"\"\n", | |
"\n", | |
"res = chain.invoke({\"situation\": situation})\n", | |
"print(res)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "d3981971-0218-4aa6-8342-f480055d4f7f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.13.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment