MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / content_with_context

Method content_with_context

crates/chat-cli/src/cli/chat/message.rs:292–329  ·  view source on GitHub ↗

Returns a formatted [String] containing [Self::additional_context], [Self::timestamp], and [Self::prompt].

(&self)

Source from the content-addressed store, hash-verified

290 /// Returns a formatted [String] containing [Self::additional_context], [Self::timestamp], and
291 /// [Self::prompt].
292 fn content_with_context(&self) -> String {
293 let mut content = String::new();
294
295 if let Some(ts) = self.timestamp {
296 let weekday = match ts.weekday() {
297 chrono::Weekday::Mon => "Monday",
298 chrono::Weekday::Tue => "Tuesday",
299 chrono::Weekday::Wed => "Wednesday",
300 chrono::Weekday::Thu => "Thursday",
301 chrono::Weekday::Fri => "Friday",
302 chrono::Weekday::Sat => "Saturday",
303 chrono::Weekday::Sun => "Sunday",
304 };
305 // Format the time with iso8601 format using a timezone offset.
306 let timestamp = ts.to_rfc3339_opts(chrono::SecondsFormat::Millis, false);
307 content.push_str(&format!(
308 "{}Current time: {}, {}\n{}",
309 CONTEXT_ENTRY_START_HEADER, weekday, timestamp, CONTEXT_ENTRY_END_HEADER,
310 ));
311 }
312
313 if !self.additional_context.is_empty() {
314 content.push_str(&self.additional_context);
315 content.push('\n');
316 }
317
318 // Only add special delimiters around the user's prompt if there is no timestamp or
319 // additional context to add.
320 match (content.is_empty(), self.prompt()) {
321 (false, Some(p)) => {
322 content.push_str(&format!("{}{}{}", USER_ENTRY_START_HEADER, p, USER_ENTRY_END_HEADER));
323 },
324 (true, Some(p)) => content.push_str(p),
325 _ => (),
326 };
327
328 content.trim().to_string()
329 }
330}
331
332#[derive(Debug, Clone, Serialize, Deserialize)]

Callers 2

into_history_entryMethod · 0.80

Calls 3

to_stringMethod · 0.80
is_emptyMethod · 0.45
promptMethod · 0.45

Tested by

no test coverage detected