小更新,expert库的领域
This commit is contained in:
5
.env
5
.env
@@ -85,6 +85,11 @@ citation_chat_model = qwen2.5:7b
|
|||||||
citation_chat_api_key =
|
citation_chat_api_key =
|
||||||
citation_chat_timeout = 120
|
citation_chat_timeout = 120
|
||||||
|
|
||||||
|
[expert_country]
|
||||||
|
chat_url_local = http://125.39.141.154:10002/v1/chat/completions
|
||||||
|
chat_url_remote = http://chat.taimed.cn/v1/chat/completions
|
||||||
|
context_limit = 2000
|
||||||
|
|
||||||
[scopus]
|
[scopus]
|
||||||
api_key = 54f915fc96e86b94ae8722ce7fdd69c7
|
api_key = 54f915fc96e86b94ae8722ce7fdd69c7
|
||||||
|
|
||||||
|
|||||||
@@ -85,14 +85,13 @@ class ExpertFinder extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动国家解析:同时启动两条链,分别用不同模型并行处理。
|
* 启动国家解析链:只需调一次,链式执行直到全部处理完。
|
||||||
* 只需调一次,两条链各自链式执行直到全部处理完。
|
* 每条任务在 fillExpertCountry 内按 affiliation 上下文长度动态选择模型地址。
|
||||||
*/
|
*/
|
||||||
public function batchFillCountry(){
|
public function batchFillCountry(){
|
||||||
$service = new ExpertFinderService();
|
$service = new ExpertFinderService();
|
||||||
|
|
||||||
// $chain1 = $service->enqueueNextCountryFill(0, 'FetchExpertCity', '');
|
$started = $service->enqueueNextCountryFill(0, 'FetchExpertCityOne', '');
|
||||||
$chain2 = $service->enqueueNextCountryFill(0, 'FetchExpertCityOne', 'http://125.39.141.154:10002/v1/chat/completions');
|
|
||||||
|
|
||||||
$pending = Db::name('expert')
|
$pending = Db::name('expert')
|
||||||
->where('affiliation', '<>', '')
|
->where('affiliation', '<>', '')
|
||||||
@@ -101,8 +100,7 @@ class ExpertFinder extends Base
|
|||||||
->count();
|
->count();
|
||||||
|
|
||||||
return jsonSuccess([
|
return jsonSuccess([
|
||||||
// 'chain1_started' => $chain1,
|
'chain_started' => $started,
|
||||||
'chain2_started' => $chain2,
|
|
||||||
'pending' => $pending,
|
'pending' => $pending,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ use think\queue\Job;
|
|||||||
use app\common\ExpertFinderService;
|
use app\common\ExpertFinderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 队列任务:用本地大模型从 affiliation 推断国家,写入 expert.country_id / country。
|
* 队列任务:用大模型从 affiliation 推断国家,写入 expert.country_id / country。
|
||||||
* 处理完当前专家后,自动找下一个推入同一队列(链式执行),直到全部处理完。
|
* 处理完当前专家后,自动找下一个推入同一队列(链式执行),直到全部处理完。
|
||||||
*
|
*
|
||||||
* 支持多队列并行:通过 $data['queue'] 和 $data['chat_url'] 区分不同的链/模型。
|
* 模型地址:默认不传 chat_url,由 ExpertFinderService::fillExpertCountry
|
||||||
|
* 按 affiliation 长度在本地/远程模型间动态选择;显式传入 chat_url 时强制使用。
|
||||||
*
|
*
|
||||||
* 单条任务受本地 LLM 响应时间影响(一般 2-10s),常驻 worker 由 QueueJob
|
* 单条任务受 LLM 响应时间影响(一般 2-10s),常驻 worker 由 QueueJob
|
||||||
* 在进程超 6h 或遇致命 DB 错误时主动 exit(1) 让 supervisor 拉起新进程。
|
* 在进程超 6h 或遇致命 DB 错误时主动 exit(1) 让 supervisor 拉起新进程。
|
||||||
*/
|
*/
|
||||||
class FillExpertCountry
|
class FillExpertCountry
|
||||||
@@ -19,10 +20,10 @@ class FillExpertCountry
|
|||||||
|
|
||||||
public function fire(Job $job, $data)
|
public function fire(Job $job, $data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
|
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
|
||||||
$affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : '';
|
$affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : '';
|
||||||
$queue = isset($data['queue']) ? (string)$data['queue'] : 'FetchExperts';
|
$queue = isset($data['queue']) ? (string)$data['queue'] : 'FetchExperts';
|
||||||
|
// 留空则每条任务按上下文长度自行选模型,不要把上一条的 URL 固定传下去
|
||||||
$chatUrl = isset($data['chat_url']) ? (string)$data['chat_url'] : '';
|
$chatUrl = isset($data['chat_url']) ? (string)$data['chat_url'] : '';
|
||||||
|
|
||||||
$service = new ExpertFinderService();
|
$service = new ExpertFinderService();
|
||||||
@@ -32,7 +33,7 @@ class FillExpertCountry
|
|||||||
}
|
}
|
||||||
$job->delete();
|
$job->delete();
|
||||||
|
|
||||||
// 链式:处理完当前专家立刻拉下一个进来
|
// 链式:下一条也不透传固定 URL,继续按条动态选模型
|
||||||
$service->enqueueNextCountryFill(1, $queue, $chatUrl);
|
$service->enqueueNextCountryFill(1, $queue, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1293,7 +1293,7 @@ function getArticleType(){
|
|||||||
['name' => 'CASE SERIES','value' => 'CS'],
|
['name' => 'CASE SERIES','value' => 'CS'],
|
||||||
['name' => 'RETRACTION','value' => 'RT'],
|
['name' => 'RETRACTION','value' => 'RT'],
|
||||||
['name' => 'MINI REVIEW','value' => 'MR'],
|
['name' => 'MINI REVIEW','value' => 'MR'],
|
||||||
// ['name' => 'PERSPECTIVE','value' => 'PERSP'],
|
['name' => 'PERSPECTIVE','value' => 'PERSP'],
|
||||||
['name' => 'OTHERS','value' => 'O']
|
['name' => 'OTHERS','value' => 'O']
|
||||||
],
|
],
|
||||||
'supplement' => [
|
'supplement' => [
|
||||||
|
|||||||
@@ -668,7 +668,7 @@ class ExpertFinderService
|
|||||||
*
|
*
|
||||||
* @param int $delay 延迟秒数
|
* @param int $delay 延迟秒数
|
||||||
* @param string $queue 队列名(不同队列跑不同 worker,互不阻塞)
|
* @param string $queue 队列名(不同队列跑不同 worker,互不阻塞)
|
||||||
* @param string $chatUrl 该链使用的模型地址(为空则用默认)
|
* @param string $chatUrl 强制指定模型地址;为空则由 fillExpertCountry 按上下文长度动态选择
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function enqueueNextCountryFill($delay = 1, $queue = 'FetchExperts', $chatUrl = '')
|
public function enqueueNextCountryFill($delay = 1, $queue = 'FetchExperts', $chatUrl = '')
|
||||||
@@ -705,6 +705,11 @@ class ExpertFinderService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 对单个专家执行国家解析(同步),由队列 Job FillExpertCountry 调用,也可直接调用测试。
|
* 对单个专家执行国家解析(同步),由队列 Job FillExpertCountry 调用,也可直接调用测试。
|
||||||
|
*
|
||||||
|
* 模型地址按上下文长度动态选择:
|
||||||
|
* - affiliation 字符数 <= 阈值 → 本地模型(默认 125.39.141.154:10002)
|
||||||
|
* - 超过阈值 → 远程模型(默认 chat.taimed.cn)
|
||||||
|
* 若调用方显式传入 $chatUrl,则优先使用该地址(调试用)。
|
||||||
*/
|
*/
|
||||||
public function fillExpertCountry($expertId, $affiliation, $chatUrl = '')
|
public function fillExpertCountry($expertId, $affiliation, $chatUrl = '')
|
||||||
{
|
{
|
||||||
@@ -714,8 +719,10 @@ class ExpertFinderService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultUrl = trim((string)Env::get('expert_country_chat_url', Env::get('citation_chat_url', 'http://chat.taimed.cn/v1/chat/completions')));
|
$url = trim((string)$chatUrl);
|
||||||
$url = ($chatUrl !== '') ? $chatUrl : $defaultUrl;
|
if ($url === '') {
|
||||||
|
$url = $this->resolveCountryChatUrl($affiliation);
|
||||||
|
}
|
||||||
|
|
||||||
$resolver = new CountryResolverService([
|
$resolver = new CountryResolverService([
|
||||||
'chat_url' => $url,
|
'chat_url' => $url,
|
||||||
@@ -752,15 +759,49 @@ class ExpertFinderService
|
|||||||
'country_id' => $countryId,
|
'country_id' => $countryId,
|
||||||
'country' => $enName,
|
'country' => $enName,
|
||||||
]);
|
]);
|
||||||
|
$this->log('[CountryFill] expert_id=' . $expertId . ' ok country=' . $enName . ' url=' . $url);
|
||||||
} else {
|
} else {
|
||||||
// country_id = -1 表示「已尝试但未识别」,避免链式执行时反复卡在同一条
|
// country_id = -1 表示「已尝试但未识别」,避免链式执行时反复卡在同一条
|
||||||
Db::name('expert')->where('expert_id', intval($expertId))->update([
|
Db::name('expert')->where('expert_id', intval($expertId))->update([
|
||||||
'country_id' => -1,
|
'country_id' => -1,
|
||||||
]);
|
]);
|
||||||
$this->log('[CountryFill] expert_id=' . $expertId . ' unresolved, code=' . ($result['code'] ?? '') . ' en_name=' . ($result['en_name'] ?? ''));
|
$this->log('[CountryFill] expert_id=' . $expertId . ' unresolved, code=' . ($result['code'] ?? '') . ' en_name=' . ($result['en_name'] ?? '') . ' url=' . $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按 affiliation 上下文长度选择国家解析模型地址。
|
||||||
|
*
|
||||||
|
* 环境变量([expert_country] 段,也兼容扁平 key):
|
||||||
|
* chat_url_local / expert_country_chat_url_local
|
||||||
|
* chat_url_remote / expert_country_chat_url_remote
|
||||||
|
* context_limit / expert_country_context_limit (字符数,默认 2000)
|
||||||
|
*/
|
||||||
|
public function resolveCountryChatUrl($affiliation)
|
||||||
|
{
|
||||||
|
$localUrl = trim((string)Env::get(
|
||||||
|
'expert_country.chat_url_local',
|
||||||
|
Env::get('expert_country_chat_url_local', 'http://125.39.141.154:10002/v1/chat/completions')
|
||||||
|
));
|
||||||
|
$remoteUrl = trim((string)Env::get(
|
||||||
|
'expert_country.chat_url_remote',
|
||||||
|
Env::get(
|
||||||
|
'expert_country_chat_url_remote',
|
||||||
|
Env::get('expert_country_chat_url', 'http://chat.taimed.cn/v1/chat/completions')
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$limit = max(1, intval(Env::get(
|
||||||
|
'expert_country.context_limit',
|
||||||
|
Env::get('expert_country_context_limit', 2000)
|
||||||
|
)));
|
||||||
|
|
||||||
|
$len = mb_strlen(trim((string)$affiliation), 'UTF-8');
|
||||||
|
if ($len > $limit) {
|
||||||
|
return $remoteUrl !== '' ? $remoteUrl : $localUrl;
|
||||||
|
}
|
||||||
|
return $localUrl !== '' ? $localUrl : $remoteUrl;
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== Text Helpers ====================
|
// ==================== Text Helpers ====================
|
||||||
|
|
||||||
private function extractEmailFromText($text)
|
private function extractEmailFromText($text)
|
||||||
|
|||||||
Reference in New Issue
Block a user