はじめに
WSL2のllama.cppでQwen3.5-27Bを実行しました。
方法はこちらです。 touch-sp.hatenablog.com
./build/bin/llama-server -m /home/hoge/models/Qwen3.5-27B-Q4_K_M.gguf --host 127.0.0.1 --port 8888
課題
算数パズルを解かせてみました。
「9 9 9 9」という4つの数字の間に四則演算の記号を追加して計算結果が10になるようにするという問題です。
正解の一例は (9×9+9)÷9 = 10 です。
クライアント側のPythonスクリプト
from openai import OpenAI client = OpenAI( base_url="http://localhost:8888/v1", api_key="EMPTY" ) prompt = """「9 9 9 9」という4桁の数字があります。数字と数字の間に四則演算の記号を追加して計算結果が10になるようにして下さい。 数字と数字の間に少数点を追加することは禁止されています。 隣あう数字をまとめて2桁以上の数字とみなすことは禁止されています。 括弧を使うことは可能です。 以下に例を示します。 ~~~ 「1 2 3 4」なら1+2+3+4が解答の一例です。 「4 5 4 2」なら(4*5)/(4-2)が解答の一例です。 ~~~""" response = client.chat.completions.create( model="local", messages=[ {"role": "user", "content": prompt} ], stream=True ) for chunk in response: delta = chunk.choices[0].delta extra = delta.model_extra or {} reasoning = extra.get("reasoning_content", "") if reasoning: print(reasoning, end="", flush=True) if delta.content: print(delta.content, end="", flush=True) print()
結果
thinkingは省略しています。
`(9 * 9 + 9) / 9 = 10` **計算の流れ:** 1. 括弧の中を計算します。 `9 * 9 = 81` `81 + 9 = 90` 2. 残りの 9 で割ります。 `90 / 9 = 10` これにより、4 つの 9 をすべて使い、禁止事項(少数点、数字の連結)に違反せず、計算結果を 10 にすることができます。
正解にたどりつきました。