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

Method send_message

crates/chat-cli/src/api_client/mod.rs:384–492  ·  view source on GitHub ↗
(
        &self,
        conversation: ConversationState,
    )

Source from the content-addressed store, hash-verified

382 }
383
384 pub async fn send_message(
385 &self,
386 conversation: ConversationState,
387 ) -> Result<SendMessageOutput, ConverseStreamError> {
388 debug!("Sending conversation: {:#?}", conversation);
389
390 let ConversationState {
391 conversation_id,
392 user_input_message,
393 history,
394 } = conversation;
395
396 let model_id_opt: Option<String> = user_input_message.model_id.clone();
397
398 if let Some(client) = &self.streaming_client {
399 let conversation_state = amzn_codewhisperer_streaming_client::types::ConversationState::builder()
400 .set_conversation_id(conversation_id)
401 .current_message(
402 amzn_codewhisperer_streaming_client::types::ChatMessage::UserInputMessage(
403 user_input_message.into(),
404 ),
405 )
406 .chat_trigger_type(amzn_codewhisperer_streaming_client::types::ChatTriggerType::Manual)
407 .set_history(
408 history
409 .map(|v| v.into_iter().map(|i| i.try_into()).collect::<Result<Vec<_>, _>>())
410 .transpose()?,
411 )
412 .build()
413 .expect("building conversation should not fail");
414
415 match client
416 .generate_assistant_response()
417 .conversation_state(conversation_state)
418 .set_profile_arn(self.profile.as_ref().map(|p| p.arn.clone()))
419 .send()
420 .await
421 {
422 Ok(response) => Ok(SendMessageOutput::Codewhisperer(response)),
423 Err(err) => {
424 let request_id = err
425 .as_service_error()
426 .and_then(|err| err.meta().request_id())
427 .map(|s| s.to_string());
428 let status_code = err.raw_response().map(|res| res.status().as_u16());
429
430 let body = err
431 .raw_response()
432 .and_then(|resp| resp.body().bytes())
433 .unwrap_or_default();
434 Err(ConverseStreamError::new(
435 classify_error_kind(status_code, body, model_id_opt.as_deref(), &err),
436 Some(err),
437 )
438 .set_request_id(request_id)
439 .set_status_code(status_code))
440 },
441 }

Callers 1

test_mockFunction · 0.45

Calls 15

classify_error_kindFunction · 0.85
mapMethod · 0.80
to_stringMethod · 0.80
bytesMethod · 0.80
bodyMethod · 0.80
set_status_codeMethod · 0.80
UserInputMessageClass · 0.70
cloneMethod · 0.45
buildMethod · 0.45
set_historyMethod · 0.45
chat_trigger_typeMethod · 0.45

Tested by 1

test_mockFunction · 0.36