2
0

TestAI.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Http;
  5. class TestAI extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'test:ai';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. $url = 'https://api.moonshot.cn/v1/chat/completions';
  36. $param = [
  37. 'model' => 'moonshot-v1-8k',
  38. 'messages' => [
  39. ['role' => 'system', 'content' => '你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。'],
  40. ['role' => 'user', 'content' => '你好,我叫李雷,1+1等于多少?'],
  41. ],
  42. 'temperature' => 0.3,
  43. ];
  44. $response = Http::withToken('sk-kwjHIMh3PoWwUwQyKdT3KHvNe8Es19SUiujGrxtH09uDQCui')
  45. ->post($url, $param);
  46. if ($response->failed()) {
  47. $this->error('http request error'.$response->json('message'));
  48. } else {
  49. $this->info(json_encode($response->json()));
  50. }
  51. return 0;
  52. }
  53. }