Skip to content

web search done right

Summarization feature somewhat finished

Mikkel Denker20d95f5104ae
diff --git a/core/src/summarizer.rs b/core/src/summarizer.rs
index 45a69ae1..a4e9f52b 100644
--- a/core/src/summarizer.rs
+++ b/core/src/summarizer.rs
@@ -420,8 +420,9 @@ impl Iterator for BeamGenerator {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
- self.state.take().and_then(|state| {
- match state.step(Arc::clone(&self.model), &self.config) {
+ self.state
+ .take()
+ .and_then(|state| match state.step(&self.model, &self.config) {
Ok((state, res)) => {
self.state = Some(state);
res
@@ -430,8 +431,7 @@ impl Iterator for BeamGenerator {
tracing::error!("Encountered an error while generating summary: {err}");
None
}
- }
- })
+ })
}
}
@@ -836,13 +836,13 @@ impl BeamState {
fn step(
mut self,
- model: Arc<AbstractiveModel>,
+ model: &AbstractiveModel,
config: &GenerationConfig,
) -> Result<(Self, Option<<BeamGenerator as Iterator>::Item>)> {
loop {
match self {
BeamState::Encoding { text } => {
- self = Self::encode_step(model.as_ref(), text)?;
+ self = Self::encode_step(model, text)?;
}
BeamState::Decoding {
encoder_hidden_states,
@@ -850,7 +850,7 @@ impl BeamState {
} => {
let ids = vec![model.begin_decoder_token as i64, model.bos_token_id as i64];
let decoder_output = Self::run_decoder_model(
- model.as_ref(),
+ model,
&ids,
encoder_hidden_states.clone(),
attention_mask.clone(),
@@ -918,7 +918,7 @@ impl BeamState {
}
let decoder_output = Self::run_decoder_model_with_past(
- model.as_ref(),
+ model,
&beams,
&encoder_hidden_states,
&attention_mask,
@@ -944,11 +944,7 @@ impl BeamState {
.iter()
.all(|beam| beam.is_finished(model.eos_token_id as i64))
{
- self = Self::output_from_best(
- model.as_ref(),
- new_beams,
- beam_token_agreement_idx,
- );
+ self = Self::output_from_best(model, new_beams, beam_token_agreement_idx);
} else {
self = BeamState::DecodingWithPast {
encoder_hidden_states,
diff --git a/frontend/src/components/SearchModal.astro b/frontend/src/components/SearchModal.astro
index 262cba1f..53128d33 100644
--- a/frontend/src/components/SearchModal.astro
+++ b/frontend/src/components/SearchModal.astro
@@ -75,8 +75,13 @@ import Hero from "./Hero.astro";
}
#summarize-btn {
- @apply rounded-full px-2 py-1 border bg-white hover:border-brand hover:text-brand;
+ @apply rounded-full px-2 py-1 border bg-white;
}
+
+ #summarize-btn:not(:disabled) {
+ @apply hover:border-brand hover:text-brand;
+ }
+
#summarize-btn.active {
@apply border-brand text-brand;
}
@@ -94,6 +99,7 @@ import Hero from "./Hero.astro";
var currentSite = "";
var currentUrl = "";
var currentIdx = null;
+ var currentHasCleanBody = false;
const BLOCKED = 0;
const LESS = 1;
@@ -109,11 +115,14 @@ import Hero from "./Hero.astro";
// This is called from search.astro
// Do not delete!
- function updateModal(idx, site, url) {
+ function updateModal(idx, site, url, hasCleanBody) {
siteLabel.innerHTML = site;
currentSite = site;
currentUrl = url;
currentIdx = idx;
+ currentHasCleanBody = hasCleanBody;
+
+ btnSummarize.disabled = !currentHasCleanBody;
updateSelection();
updateSummaryBtn();
diff --git a/frontend/src/pages/search.astro b/frontend/src/pages/search.astro
index 7112d36e..971cbfb0 100644
--- a/frontend/src/pages/search.astro
+++ b/frontend/src/pages/search.astro
@@ -114,6 +114,7 @@ import { askama } from "../askama";
data-site="{{ item.site }}"
data-url="{{ item.url }}"
data-idx="{{ loop.index0 }}"
+ data-has-clean-body="{{ !item.body.is_empty() }}"
>
<Hero class="w-6" icon="adjustments" />
</div>
@@ -230,8 +231,9 @@ import { askama } from "../askama";
event.stopPropagation();
const elem = event.target;
+ const hasCleanBody = (elem.dataset.hasCleanBody === "true");
- updateModal(elem.dataset.idx, elem.dataset.site, elem.dataset.url);
+ updateModal(elem.dataset.idx, elem.dataset.site, elem.dataset.url, hasCleanBody);
const rect = elem.getBoundingClientRect();
modal.style.left = rect.left + rect.width + 5 + "px";