サンプルコード
ollamaをインストールし設定を変更していなければ、11434ポートでアクセス可能。
$client = new \GuzzleHttp\Client();
$prompts = [];
$prompts[] = ["role" => "user", "content" => "日本で1番高い山を教えて下さい"];
$response = $client->post('http://localhost:11434/api/chat', [
'json' => [
'model' => 'gemma3:12b',
'messages' => $prompts,
'stream' => false,
'raw' => true
]
]);
$rawBody = $response->getBody()->getContents();
$result = json_decode($rawBody, true);
dd($result['message']['content']);
回答結果
回答結果
日本で一番高い山は、**富士山(ふじさん)**です。
標高は3,776.24メートルです。