正在显示
3 个修改的文件
包含
55 行增加
和
22 行删除
| @@ -119,24 +119,23 @@ class GeoQuestionRes extends Command | @@ -119,24 +119,23 @@ class GeoQuestionRes extends Command | ||
| 119 | $hit_data = array_merge($url, $title, $hit_data); | 119 | $hit_data = array_merge($url, $title, $hit_data); |
| 120 | } | 120 | } |
| 121 | $hit = 0; | 121 | $hit = 0; |
| 122 | - //todo::与预期结果是否复合 | ||
| 123 | - if(!empty($taskInfo['expect_result'])){ | ||
| 124 | - $str = "客户提出的问题:{$question},客户得到的回复:{$result['text']},客户需要预期:{$taskInfo['expect_result']},请分析得到的回复和预期是否一致,仅回复我是或者否"; | ||
| 125 | - $strResult = $geo_service->getChatResult($str, 'gpt-4o-mini'); | ||
| 126 | - if(isset($strResult['text']) && !empty($strResult['text'])){ | ||
| 127 | - switch ($strResult['text']){ | ||
| 128 | - case '是': | ||
| 129 | - $is_match = 1; | ||
| 130 | - $hit++; | ||
| 131 | - break; | ||
| 132 | - case '否': | ||
| 133 | - $is_match = 2; | ||
| 134 | - break; | ||
| 135 | - default: | ||
| 136 | $is_match = 0; | 122 | $is_match = 0; |
| 137 | - break; | ||
| 138 | - } | 123 | + $cosine = 0; |
| 124 | + $similarity = []; | ||
| 125 | + // TODO 有预期结果,分析答案和预期结果 | ||
| 126 | + if(FALSE == empty($taskInfo['expect_result'])){ | ||
| 127 | + $cosine_result = $geo_service->cosineSimilarity($taskInfo['expect_result'], $result['text']); | ||
| 128 | + // 语义是否一致 | ||
| 129 | + if (FALSE == empty($cosine_result['judgement'])) { | ||
| 130 | + $is_match = $cosine_result['judgement'] == '语义相近' ? 1 : 2; | ||
| 131 | + $hit++; | ||
| 139 | } | 132 | } |
| 133 | + // 余弦相似度 | ||
| 134 | + if (FALSE == empty($cosine_result['similarity'])) | ||
| 135 | + $cosine = intval($cosine_result['similarity'] * 10000) / 100; | ||
| 136 | + // 语句拆解结果 | ||
| 137 | + if (FALSE == empty($cosine_result['split_results'])) | ||
| 138 | + $similarity = $cosine_result['split_results']; | ||
| 140 | } | 139 | } |
| 141 | $hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data); | 140 | $hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data); |
| 142 | if (!empty($hit_keyword['keywords'])) { | 141 | if (!empty($hit_keyword['keywords'])) { |
| @@ -165,6 +164,8 @@ class GeoQuestionRes extends Command | @@ -165,6 +164,8 @@ class GeoQuestionRes extends Command | ||
| 165 | 'url_num'=>$url_num ?? [], | 164 | 'url_num'=>$url_num ?? [], |
| 166 | 'is_match'=>$is_match ?? 0, | 165 | 'is_match'=>$is_match ?? 0, |
| 167 | 'label'=>$taskInfo['label'] ?? null, | 166 | 'label'=>$taskInfo['label'] ?? null, |
| 167 | + 'cosine' => $cosine, | ||
| 168 | + 'similarity' => json_encode($similarity, true), | ||
| 168 | 'created_at'=>date('Y-m-d H:i:s'), | 169 | 'created_at'=>date('Y-m-d H:i:s'), |
| 169 | 'updated_at'=>date('Y-m-d H:i:s'), | 170 | 'updated_at'=>date('Y-m-d H:i:s'), |
| 170 | ]; | 171 | ]; |
| @@ -33,6 +33,7 @@ class CreateProject extends Command | @@ -33,6 +33,7 @@ class CreateProject extends Command | ||
| 33 | protected $description = '创建项目'; | 33 | protected $description = '创建项目'; |
| 34 | 34 | ||
| 35 | public function handle(){ | 35 | public function handle(){ |
| 36 | + dd(1); | ||
| 36 | return $this->sync(); | 37 | return $this->sync(); |
| 37 | } | 38 | } |
| 38 | 39 | ||
| @@ -42,10 +43,12 @@ class CreateProject extends Command | @@ -42,10 +43,12 @@ class CreateProject extends Command | ||
| 42 | * @throws \Exception | 43 | * @throws \Exception |
| 43 | */ | 44 | */ |
| 44 | public function sync($is_update = 0){ | 45 | public function sync($is_update = 0){ |
| 45 | - $company = '济南市莱芜凤城铝合金有限公司'; | ||
| 46 | - $mobile = '13806340552'; | ||
| 47 | - $plan = '标准版'; | ||
| 48 | - $cooperate_date = '2019-11-19'; | 46 | + $company = '山东临磨数控机床装备有限公司(自建站)'; |
| 47 | + $mobile = '18663004388'; | ||
| 48 | + $lead_name = '18663004388'; | ||
| 49 | + $plan = '商务版'; | ||
| 50 | + $cooperate_date = '2025-08-21'; | ||
| 51 | +// $channel = '{"user_id": "732", "zone_id": "1", "channel_id": "95"}'; | ||
| 49 | $channel = '{"user_id": "1989", "zone_id": "4", "channel_id": "13"}'; | 52 | $channel = '{"user_id": "1989", "zone_id": "4", "channel_id": "13"}'; |
| 50 | 53 | ||
| 51 | $title = date('Ymd') . '-' . $company; | 54 | $title = date('Ymd') . '-' . $company; |
| @@ -53,7 +56,7 @@ class CreateProject extends Command | @@ -53,7 +56,7 @@ class CreateProject extends Command | ||
| 53 | 'project'=>[ | 56 | 'project'=>[ |
| 54 | 'title' => $title, | 57 | 'title' => $title, |
| 55 | 'company' => $company, | 58 | 'company' => $company, |
| 56 | - 'lead_name' => $mobile, | 59 | + 'lead_name' => $lead_name, |
| 57 | 'mobile' => $mobile, | 60 | 'mobile' => $mobile, |
| 58 | 'mysql_id'=>Project::MYSQL_ID, | 61 | 'mysql_id'=>Project::MYSQL_ID, |
| 59 | 'serve_id'=>9, | 62 | 'serve_id'=>9, |
| @@ -61,7 +64,7 @@ class CreateProject extends Command | @@ -61,7 +64,7 @@ class CreateProject extends Command | ||
| 61 | 'channel' => $channel, | 64 | 'channel' => $channel, |
| 62 | 'requirement' => '', | 65 | 'requirement' => '', |
| 63 | 'cooperate_date' => $cooperate_date, | 66 | 'cooperate_date' => $cooperate_date, |
| 64 | - 'from_order_id' => '', | 67 | + 'from_order_id' => uniqid(), |
| 65 | 'type' => $is_update, | 68 | 'type' => $is_update, |
| 66 | 'is_upgrade'=>$is_update, | 69 | 'is_upgrade'=>$is_update, |
| 67 | ], | 70 | ], |
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Services\Geo; | 10 | namespace App\Services\Geo; |
| 11 | 11 | ||
| 12 | +use Illuminate\Support\Facades\Http; | ||
| 13 | + | ||
| 12 | class GeoService | 14 | class GeoService |
| 13 | { | 15 | { |
| 14 | public $api_key = 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6'; | 16 | public $api_key = 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6'; |
| @@ -108,4 +110,31 @@ class GeoService | @@ -108,4 +110,31 @@ class GeoService | ||
| 108 | $data = http_post($url,json_encode($message,true),$header); | 110 | $data = http_post($url,json_encode($message,true),$header); |
| 109 | return $data; | 111 | return $data; |
| 110 | } | 112 | } |
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * 获取语句余弦相似度 | ||
| 116 | + * $text 会被拆解语句, 分析预警传$text | ||
| 117 | + * @param string $standard 标准答案 | ||
| 118 | + * @param string $text 需要分析的语句 | ||
| 119 | + * @param string $embedding_model | ||
| 120 | + * @param string $similarity_method | ||
| 121 | + * @return \Illuminate\Http\Client\Response | ||
| 122 | + */ | ||
| 123 | + public function cosineSimilarity($standard, $text, $embedding_model = 'text-embedding-3-small', $similarity_method = 'cosine') | ||
| 124 | + { | ||
| 125 | + $url = 'http://knowledge_base.zabbix.waimaoq.com/v1/crud/split_similarity'; | ||
| 126 | + $header = [ | ||
| 127 | + 'accept: application/json', | ||
| 128 | + 'Content-Type: application/json' | ||
| 129 | + ]; | ||
| 130 | + $param = [ | ||
| 131 | + 'text1' => $standard, | ||
| 132 | + 'text2' => $text, | ||
| 133 | + 'embedding_model' => $embedding_model, | ||
| 134 | + 'similarity_method' => $similarity_method | ||
| 135 | + ]; | ||
| 136 | + | ||
| 137 | + $result = Http::post($url, $param); | ||
| 138 | + return $result->json(); | ||
| 139 | + } | ||
| 111 | } | 140 | } |
-
请 注册 或 登录 后发表评论