GeoService.php 3.9 KB
<?php
/**
 * @remark :
 * @name   :GeoService.php
 * @author :lyh
 * @method :post
 * @time   :2025/7/3 14:21
 */

namespace App\Services\Geo;

use Illuminate\Support\Facades\Http;

class GeoService
{
    public $api_key = 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6';

    public $api_url = 'https://api.cmer.com/';

    /**
     * 获取AI平台数据
     * @param $content
     * @param $platform
     * @return mixed|string
     */
    public function getAiPlatformResult($content,$platform)
    {
        $url = $this->api_url . 'v1/websearch_chat';
        $header = [
            'accept: application/json',
            'X-CmerApi-Host: llm-chat.p.cmer.com',
            'apikey: '.$this->api_key,
            'Content-Type: application/json'
        ];
        $message = [
            'messages'=>[
                    [
                    'content'=>$content,
                    'role'=>'user'
                    ],
                ],
            'platform' => $platform,
            'security_check' => true
        ];
        $data = http_post($url,json_encode($message,true),$header,true,180);
        return $data;
    }

    /**
     * 获取Google数据
     * @param $search
     * @param int $lum_json 默认1 不只是什么参数
     * @return mixed|string
     */
    public function getGooglePlatformResult($search)
    {
        $url = 'https://api.cmer.com/ai-overviews';
        $header = [
            'accept: application/json',
            'apikey: UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
            'Content-Type: application/json',
            'X-CmerApi-Host:ai-overviews.p.cmer.com'
        ];
        $param = [
            'q' => $search,
            'location' => 'New York, United States',
            'gl' => 'us',
            'hl'=>'en'
        ];
        $url = $url . '?' . http_build_query($param);
        return http_get($url, $header);
    }

    /**
     * 请求chat会话, 自定义模型
     * @param $content
     * @param string $model
     * @return mixed|string
     */
    public function getChatResult($content, $model = 'deepseek-r1'){
        $url = $this->api_url . 'v1/chat';
        switch ($model){
            case 'deepseek-r1':
                $supplier = 'bailian';
                break;
            case 'gpt-4o-mini':
                $supplier = 'azure';
                break;
            default:
                $supplier = '';
                break;
        }
        $header = [
            'accept: application/json',
            'X-CmerApi-Host: llm-chat.p.cmer.com',
            'apikey: '.$this->api_key,
            'Content-Type: application/json'
        ];
        $message = [
            'messages'=>[
                [
                    'content'=>$content,
                    'role'=>'user'
                ],
            ],
            'model' => $model,
            "supplier"=> $supplier,
            'security_check' => true
        ];
        $data = http_post($url,json_encode($message,true),$header);
        return $data;
    }

    /**
     * 获取语句余弦相似度
     * $text 会被拆解语句, 分析预警传$text
     * @param string $standard             标准答案
     * @param string $text                 需要分析的语句
     * @param string $embedding_model
     * @param string $similarity_method
     * @return \Illuminate\Http\Client\Response
     */
    public function cosineSimilarity($standard, $text, $embedding_model = 'text-embedding-3-small', $similarity_method = 'cosine')
    {
        $url = 'http://knowledge_base.zabbix.waimaoq.com/v1/crud/split_similarity';
        $header = [
            'accept: application/json',
            'Content-Type: application/json'
        ];
        $param = [
            'text1' => $standard,
            'text2' => $text,
            'embedding_model' => $embedding_model,
            'similarity_method' => $similarity_method
        ];

        $result = Http::post($url, $param);
        return $result->json();
    }
}