Merge pull request 'Clarify research results without price evidence' (#335) from codex/chat-semantic-inventory into main
CI / test (push) Successful in 1m17s
CI / test (push) Successful in 1m17s
This commit was merged in pull request #335.
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -747,7 +748,7 @@ func main() {
|
|||||||
PropositionKey: fmt.Sprintf("question:%s:%d", utterance.ID, index), Query: part,
|
PropositionKey: fmt.Sprintf("question:%s:%d", utterance.ID, index), Query: part,
|
||||||
})
|
})
|
||||||
cancelResearch()
|
cancelResearch()
|
||||||
reply, backed := renderResearchReply(result, researchErr)
|
reply, backed := renderResearchReply(part, result, researchErr)
|
||||||
if backed {
|
if backed {
|
||||||
researchBacked = true
|
researchBacked = true
|
||||||
}
|
}
|
||||||
@@ -1625,7 +1626,7 @@ func hasCapabilityHint(hints []string, wanted string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderResearchReply(result epistemics.ResearchResult, researchErr error) (string, bool) {
|
func renderResearchReply(query string, result epistemics.ResearchResult, researchErr error) (string, bool) {
|
||||||
if researchErr != nil {
|
if researchErr != nil {
|
||||||
return "Сейчас не удалось получить данные из подключённого источника. Попробую снова через доступный маршрут.", false
|
return "Сейчас не удалось получить данные из подключённого источника. Попробую снова через доступный маршрут.", false
|
||||||
}
|
}
|
||||||
@@ -1650,7 +1651,17 @@ func renderResearchReply(result epistemics.ResearchResult, researchErr error) (s
|
|||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
return "Проверяемых данных пока не найдено. Могу повторить поиск или уточнить, что именно проверить.", false
|
return "Проверяемых данных пока не найдено. Могу повторить поиск или уточнить, что именно проверить.", false
|
||||||
}
|
}
|
||||||
return strings.Join(lines, "\n"), true
|
reply := strings.Join(lines, "\n")
|
||||||
|
lowerQuery := strings.ToLower(query)
|
||||||
|
if (strings.Contains(lowerQuery, "цен") || strings.Contains(lowerQuery, "стоим")) && !containsPriceEvidence(reply) {
|
||||||
|
reply = "Актуальная цена в найденных фрагментах не указана, поэтому не буду придумывать сумму. Вот страницы, где её можно проверить:\n" + reply
|
||||||
|
}
|
||||||
|
return reply, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsPriceEvidence(value string) bool {
|
||||||
|
pricePattern := regexp.MustCompile(`(?i)(\d[\d\s.,]{2,})(?:\s*(?:₽|руб\.?|р\.?|usd|\$|€))`)
|
||||||
|
return pricePattern.MatchString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func reviewPreservesResearchEvidence(reviewed, draft string) bool {
|
func reviewPreservesResearchEvidence(reviewed, draft string) bool {
|
||||||
|
|||||||
@@ -48,6 +48,15 @@ func TestHumanMemoryInventoryUsesNewestPreference(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainsPriceEvidenceDistinguishesLinksFromPrices(t *testing.T) {
|
||||||
|
if containsPriceEvidence("RTX 4090 — market.yandex.ru") {
|
||||||
|
t.Fatal("a product link is not price evidence")
|
||||||
|
}
|
||||||
|
if !containsPriceEvidence("Цена: 189 990 ₽") {
|
||||||
|
t.Fatal("expected a currency amount to count as price evidence")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCognitiveChannelQuestionUsesHumanSafeHealthReply(t *testing.T) {
|
func TestCognitiveChannelQuestionUsesHumanSafeHealthReply(t *testing.T) {
|
||||||
reply := humanCognitiveChannelReply(interaction.InformationRequestCognitiveChannelStatus, interaction.SpeechActQuestion, capability.Health{State: capability.HealthAvailable, CapabilityID: "provider-secret-model"}, nil)
|
reply := humanCognitiveChannelReply(interaction.InformationRequestCognitiveChannelStatus, interaction.SpeechActQuestion, capability.Health{State: capability.HealthAvailable, CapabilityID: "provider-secret-model"}, nil)
|
||||||
if !strings.Contains(reply, "доступен") || strings.Contains(reply, "provider-secret-model") {
|
if !strings.Contains(reply, "доступен") || strings.Contains(reply, "provider-secret-model") {
|
||||||
|
|||||||
Reference in New Issue
Block a user