Scribble at 2026-04-19 21:58:41 Last modified: unmodified
llama.cpp は正しく起動して動いている。モデルは、既に LM Studio でダウンロードしてある Gemma4 E4B-it Q4_K_M という GGUF 形式のファイルへパスを通して、
% llama-server -m path-to-gemma-4-E4B-it-Q4_K_M.gguf --port 8080
のようにサーバを起動してからブラウザで 127.0.0.1:8080 にアクセスすれば、上の画面のように ChatGPT 風のフロント・エンドが表示される。試しに使うだけなら非常に簡単に導入出来て、gpt4all でひたすら思いモデルを動かしていたのが3年前だったとは思えないほどだ(まぁ、それだけのスペックがあるマシンを買ったからでもあるが)。
ということで、サーバを立ち上げるまではバッチ・ファイルを書けばいいわけで、あとは PHP でアクセスしてレスポンスを受けるだけだ。もちろん、その方法も llama.cpp (Gemma4) 自身に聞けばよい。
% How to use you (the server of llama.cpp) from PHP script?
この後の展開は、みなさん自身が適当なモデルに質問すれば分かることなので引用しないが、cURL 関数を使って POST をリクエストする方法と、Guzzle という PHP 用の HTTP クライアント・ライブラリを使う方法がある。もちろん、何かあると Apache が起動しない元凶の一つになりがちな(DLL を読み込んでいるのにパスが通らない)cURL なんてレガシーな部品とはおさらばして、新しいライブラリを使ってみた。当事者(llama.cpp)と暫くやりとして、ようやく20分後にプロンプトを自動でランダムなテーマから選んで生成するスクリプトが動いた。
"A black and white photography of snap shot at hagrid hut tea conversation scene, in style of Daido Moriyama, with deep blacks, wide-angle distortion, blown highlights. aridity and lushness clash, emphasizing textural juxtaposition. Focus on a foreground plane of sun-bleached, cracked earth, overlaid with scattered, desiccated detritus. Behind this, the compositional break occurs: an abrupt vertical rise revealing the dense, overhanging plane of deep, saturated grasses and shadowed foliage. Leading lines formed by the cracked earth direct the eye towards the abrupt vertical plane. The composition is dominated by the textural clash between the matte, low-key tones of the foreground grit and the high-frequency detail of the shadowed, overhanging meadow plane. Use a telephoto compression effect across the transition zone, flattening the visual gap. Foreground elements partially obscure the view, adding layered depth. The lighting suggests a strong overhead source, creating deep, hard-edged shadows that articulate the vertical relief of the grasses. The depth of field is shallow, allowing the immediate foreground grit to retain high spatial frequency detail, while the background foliage dissolves into a creamy, smooth bokeh."
こんな感じの自然文のプロンプトを1分ていどで30個ほど生成する。ただ、戻ってくる文字列に余計な改行が多いことと、プロンプトの長さにかなりばらつきがあるので、これは明日以降に調整しよう。