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
|
||||
|
||||
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
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||
|
||||
json_text = {
|
||||
searchInformation: {
|
||||
totalResults: "1",
|
||||
totalResults: "2",
|
||||
},
|
||||
items: [
|
||||
{
|
||||
|
@ -43,6 +43,13 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||
formattedUrl: "formattedUrl1",
|
||||
oops: "do no include me ... oops",
|
||||
},
|
||||
{
|
||||
title: "title2",
|
||||
link: "link2",
|
||||
displayLink: "displayLink1",
|
||||
formattedUrl: "formattedUrl1",
|
||||
oops: "do no include me ... oops",
|
||||
},
|
||||
],
|
||||
}.to_json
|
||||
|
||||
|
@ -60,10 +67,11 @@ RSpec.describe DiscourseAi::AiBot::Commands::GoogleCommand do
|
|||
|
||||
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("snippet1")
|
||||
expect(info).to include("some+search+term")
|
||||
expect(info).to include("title2")
|
||||
expect(info).to_not include("oops")
|
||||
|
||||
google.invoke!
|
||||
|
|
Loading…
Reference in New Issue