patch 20p
This commit is contained in:
@@ -1847,14 +1847,57 @@ final readonly class AgentRunner
|
||||
|
||||
$contextQuery = $this->buildContextFallbackShopQuery($question);
|
||||
|
||||
if ($contextQuery !== '' && !$this->isMetaOnlyShopQuery($contextQuery)) {
|
||||
if ($this->isUsableContextualShopQuery($contextQuery)) {
|
||||
return $contextQuery;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->extractContextualShopSearchQueryFromHistoryTurns($commerceHistoryContext);
|
||||
}
|
||||
|
||||
private function extractContextualShopSearchQueryFromHistoryTurns(string $commerceHistoryContext): string
|
||||
{
|
||||
foreach ($this->extractHistoryTurnsNewestFirst($commerceHistoryContext) as $turn) {
|
||||
$question = $this->extractQuestionFromHistoryTurn($turn);
|
||||
|
||||
if ($question !== '' && !$this->isMetaOnlyShopQuery($question)) {
|
||||
$contextQuery = $this->buildContextFallbackShopQuery($question);
|
||||
|
||||
if ($this->isUsableContextualShopQuery($contextQuery)) {
|
||||
return $contextQuery;
|
||||
}
|
||||
}
|
||||
|
||||
$modelAnchor = $this->extractFirstTestomatModelAnchor($turn);
|
||||
|
||||
if ($modelAnchor !== '' && !$this->isMetaOnlyShopQuery($modelAnchor)) {
|
||||
return mb_strtolower($modelAnchor, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function extractQuestionFromHistoryTurn(string $turn): string
|
||||
{
|
||||
if (preg_match($this->agentRunnerConfig->getFollowUpHistoryQuestionPattern(), $turn, $matches) !== 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->sanitizeHistoryQuestion((string) ($matches[1] ?? ''));
|
||||
}
|
||||
|
||||
private function isUsableContextualShopQuery(string $query): bool
|
||||
{
|
||||
$query = trim($query);
|
||||
|
||||
if ($query === '' || $this->isMetaOnlyShopQuery($query)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->tokenizeShopQueryCandidate($query) !== [];
|
||||
}
|
||||
|
||||
private function buildContextFallbackShopQuery(string $question): string
|
||||
{
|
||||
$tokens = $this->tokenizeShopQueryCandidate($question);
|
||||
|
||||
Reference in New Issue
Block a user