Reputation: 159
I am having problems getting my command line curl command to work with PHP.
working command line curl below
curl http://localhost:11434/api/chat -d '{"model":"deepseek-r1:1.5b","messages":[{"role":"user","content":"what is your name"}]}'
PHP curl not working. code below
<?php
$url = 'http://localhost:11434/api/chat -d';
$question = $_GET["q"];
$model = 'deepseek-r1:1.5b';
$data = array(
"model" => $model,
"messages" => array(
array(
"role" => "user",
"content" => $question,
)
),
);
$payload = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
echo $response;
?>
Your guidance is greatly appreciated!
Upvotes: 0
Views: 22