mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-24 16:42:15 +00:00
FIX: allow for blank fields in Google results (#255)
Under certain cases, for example: ``` there is this japanese band called kirimi, tell me more about them, try searching 3 times and at least 2 times in japanese before answering. ``` Results come back with blank snippets. This adds protection so this is allowed and code does not simply blow up.
This commit is contained in:
parent
b9d6179bfc
commit
f65e50bd9e
@ -55,7 +55,9 @@ module DiscourseAi::AiBot::Commands
|
|||||||
end
|
end
|
||||||
|
|
||||||
def minimize_field(result, field, max_tokens: 100)
|
def minimize_field(result, field, max_tokens: 100)
|
||||||
data = result[field].squish
|
data = result[field]
|
||||||
|
return "" if data.blank?
|
||||||
|
|
||||||
data = ::DiscourseAi::Tokenizer::BertTokenizer.truncate(data, max_tokens).squish
|
data = ::DiscourseAi::Tokenizer::BertTokenizer.truncate(data, max_tokens).squish
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||||||
|
|
||||||
json_text = {
|
json_text = {
|
||||||
searchInformation: {
|
searchInformation: {
|
||||||
totalResults: "1",
|
totalResults: "2",
|
||||||
},
|
},
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
@ -43,6 +43,13 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||||||
formattedUrl: "formattedUrl1",
|
formattedUrl: "formattedUrl1",
|
||||||
oops: "do no include me ... oops",
|
oops: "do no include me ... oops",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "title2",
|
||||||
|
link: "link2",
|
||||||
|
displayLink: "displayLink1",
|
||||||
|
formattedUrl: "formattedUrl1",
|
||||||
|
oops: "do no include me ... oops",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}.to_json
|
}.to_json
|
||||||
|
|
||||||
@ -60,10 +67,11 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||||||
|
|
||||||
info = google.process(query: "some search term").to_json
|
info = google.process(query: "some search term").to_json
|
||||||
|
|
||||||
expect(google.description_args[:count]).to eq(1)
|
expect(google.description_args[:count]).to eq(2)
|
||||||
expect(info).to include("title1")
|
expect(info).to include("title1")
|
||||||
expect(info).to include("snippet1")
|
expect(info).to include("snippet1")
|
||||||
expect(info).to include("some+search+term")
|
expect(info).to include("some+search+term")
|
||||||
|
expect(info).to include("title2")
|
||||||
expect(info).to_not include("oops")
|
expect(info).to_not include("oops")
|
||||||
|
|
||||||
google.invoke!
|
google.invoke!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user