简单的对接 DeepSeek API
public function callDeepSeekApi($userMessage = ''): string {
$apiKey = '你申请的 api';
$url = 'https://api.deepseek.com/chat/completions';
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer '.$apiKey
];
$data = [
'model' => 'deepseek-chat',
'messages' => [['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => $userMessage]],
'stream' => false,
'frequency_penalty' => 0,
'response_format' => ['type' => 'text'],
'max_tokens' => 2048,
'presence_penalty' => 0,
'stop' => ,
=> ,
=> ,
=> ,
=> ,
=> ,
=> ,
=>
];
= ();
= ();
(, CURLOPT_URL, );
(, CURLOPT_CUSTOMREQUEST, );
(, CURLOPT_POSTFIELDS, );
(, CURLOPT_RETURNTRANSFER, );
(, CURLOPT_SSL_VERIFYPEER, );
(, CURLOPT_HTTPHEADER, );
= ();
= ();
() {
= ();
....PHP_EOL;
}
;
}