Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit f84aab6

Browse files
Remove unused summary/conclusion logic (#1179)
* remove unused summary/conclusion logic * Set timestamp when concluding answer * Restore line number offset logic in transcoder, fix tests --------- Co-authored-by: calyptobai <[email protected]>
1 parent 7f44f51 commit f84aab6

File tree

4 files changed

+46
-315
lines changed

4 files changed

+46
-315
lines changed

server/bleep/src/agent.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Drop for Agent {
9191
.with_payload("message", "request panicked"),
9292
);
9393
} else {
94-
self.last_exchange_mut().apply_update(Update::Cancel);
94+
self.last_exchange_mut().apply_update(Update::SetTimestamp);
9595

9696
self.track_query(
9797
EventData::output_stage("cancelled")
@@ -319,8 +319,8 @@ impl Agent {
319319

320320
let answer = match e.answer() {
321321
// NB: We intentionally discard the summary as it is redundant.
322-
Some((answer, _conclusion)) => {
323-
let encoded = transcoder::encode_summarized(answer, None, "gpt-3.5-turbo")?;
322+
Some(answer) => {
323+
let encoded = transcoder::encode_summarized(answer, "gpt-3.5-turbo")?;
324324
Some(llm_gateway::api::Message::function_return("none", &encoded))
325325
}
326326

server/bleep/src/agent/exchange.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::query::parser::SemanticQuery;
22
use std::fmt;
33

44
use chrono::prelude::{DateTime, Utc};
5-
use rand::seq::SliceRandom;
65

76
/// A continually updated conversation exchange.
87
///
@@ -59,25 +58,10 @@ impl Exchange {
5958
Update::Article(full_text) => {
6059
*self.answer.get_or_insert_with(String::new) = full_text;
6160
}
62-
Update::Conclude(conclusion) => {
63-
self.response_timestamp = Some(Utc::now());
64-
self.conclusion = Some(conclusion);
65-
}
6661
Update::Focus(chunk) => {
6762
self.focused_chunk = Some(chunk);
6863
}
69-
Update::Cancel => {
70-
let conclusion = [
71-
"The article wasn't completed. See what's available",
72-
"Your article stopped before completion. Check out the available content",
73-
"The content stopped generating early. Review the initial response",
74-
]
75-
.choose(&mut rand::thread_rng())
76-
.copied()
77-
.unwrap()
78-
.to_owned();
79-
80-
self.conclusion = Some(conclusion);
64+
Update::SetTimestamp => {
8165
self.response_timestamp = Some(Utc::now());
8266
}
8367
}
@@ -88,14 +72,11 @@ impl Exchange {
8872
self.query.target().map(|q| q.to_string())
8973
}
9074

91-
/// Get the answer and conclusion associated with this exchange, if a conclusion has been made.
75+
/// Get the answer associated with this exchange.
9276
///
93-
/// This returns a tuple of `(full_text, conclusion)`.
94-
pub fn answer(&self) -> Option<(&str, &str)> {
95-
match (&self.answer, &self.conclusion) {
96-
(Some(answer), Some(conclusion)) => Some((answer.as_str(), conclusion.as_str())),
97-
_ => None,
98-
}
77+
/// This returns a tuple of `full_text`.
78+
pub fn answer(&self) -> Option<&str> {
79+
return self.answer.as_deref();
9980
}
10081

10182
/// Return a copy of this exchange, with all function call responses redacted.
@@ -203,7 +184,6 @@ pub enum Update {
203184
StartStep(SearchStep),
204185
ReplaceStep(SearchStep),
205186
Article(String),
206-
Conclude(String),
207187
Focus(FocusedChunk),
208-
Cancel,
188+
SetTimestamp,
209189
}

server/bleep/src/agent/tools/answer.rs

+7-27
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{collections::HashMap, mem, ops::Range, pin::pin};
22

33
use anyhow::{anyhow, Context, Result};
44
use futures::StreamExt;
5-
use rand::{rngs::OsRng, seq::SliceRandom};
65
use tracing::{debug, info, instrument, trace};
76

87
use crate::{
@@ -77,32 +76,15 @@ impl Agent {
7776
let fragment = fragment?;
7877
response += &fragment;
7978

80-
let (article, summary) = transcoder::decode(&response);
79+
let article = transcoder::decode(&response);
8180
self.update(Update::Article(article)).await?;
82-
83-
if let Some(summary) = summary {
84-
self.update(Update::Conclude(summary)).await?;
85-
}
8681
}
8782

88-
// We re-decode one final time to catch cases where `summary` is `None`, and to log the
89-
// output as a trace.
90-
let (article, summary) = transcoder::decode(&response);
91-
let summary = summary.unwrap_or_else(|| {
92-
[
93-
"I hope that was useful, can I help with anything else?",
94-
"Is there anything else I can help you with?",
95-
"Can I help you with anything else?",
96-
]
97-
.choose(&mut OsRng)
98-
.copied()
99-
.unwrap()
100-
.to_owned()
101-
});
102-
103-
trace!(%article, "generated answer");
83+
if let Some(article) = self.last_exchange().answer() {
84+
trace!(%article, "generated answer");
85+
}
10486

105-
self.update(Update::Conclude(summary)).await?;
87+
self.update(Update::SetTimestamp).await?;
10688

10789
self.track_query(
10890
EventData::output_stage("answer_article")
@@ -223,10 +205,8 @@ impl Agent {
223205
content: q,
224206
});
225207

226-
let conclusion = e.answer().map(|(answer, conclusion)| {
227-
let encoded =
228-
transcoder::encode_summarized(answer, Some(conclusion), "gpt-4-0613")
229-
.unwrap();
208+
let conclusion = e.answer().map(|answer| {
209+
let encoded = transcoder::encode_summarized(answer, "gpt-4-0613").unwrap();
230210

231211
llm_gateway::api::Message::PlainText {
232212
role: "assistant".to_owned(),

0 commit comments

Comments
 (0)