Chat Command
Simplified chat command implementation.
- ALWAYS_LEGAL_MESSAGE = 'Always review AI-generated content prior to use.'
Always good to have legal message.
- DEFAULT_CHAT_DESCRIPTION = 'Default Command Line Assistant Chat.'
Default chat description when none is given
- DEFAULT_CHAT_NAME = 'default'
Default chat name when none is given
- class InputSource(question, stdin, attachment, attachment_mimetype, terminal_output)[source]
Input source for the chat command.
- Parameters:
-
attachment:
str
-
attachment_mimetype:
str
- get_input_source()[source]
Determine and return the appropriate input source based on combination rules.
-
question:
str
-
stdin:
str
-
terminal_output:
str
- LEGAL_NOTICE = "This feature uses AI technology. Do not include any personal information or other sensitive information in your input. Interactions may be used to improve Red Hat's products or services."
Legal notice that we need to output once per user
- MAX_QUESTION_SIZE: int = 32000
Max input size we want to allow to be submitted to the backend. This corresponds to 32KB (32000 bytes)
- _compose_message_input(render, context, input_source)[source]
Compose the final message that will be sent to the API.
- Return type:
Question- Parameters:
render (RenderUtils) – The render utility.
context (CommandContext) – The command context.
input_source (InputSource) – The input source.
- Returns:
The composed message input.
- Return type:
Question
- _create_chat_session(dbus, user_id, name, description)[source]
Create a new chat session for a given conversation.
- _delete_all_chats(render, dbus, user_id)[source]
Delete all chats operation.
- _delete_chat(render, dbus, user_id, chat_name)[source]
Delete a specific chat operation.
- _display_response(renderer, response)[source]
Display message to the terminal.
- _gather_input_sources(args)[source]
Gather input sources from command-line arguments.
- Return type:
InputSource- Parameters:
args (Namespace) – The command-line arguments.
- Returns:
The gathered input sources.
- Return type:
InputSource
- _get_response(dbus, message_input, user_id)[source]
Get the response from the chat session.
- _handle_legal_message()[source]
Handle legal message screen output
- _interactive_chat(render, dbus, context, args, user_id, name, description)[source]
Interactive chat operation.
- Return type:
- Parameters:
- Returns:
The exit code.
- Return type:
- _list_chats(render, dbus, user_id)[source]
List all chats operation.
- _parse_attachment_file(attachment=None)[source]
Parse attachment file and read its contents.
- _read_last_terminal_output(index)[source]
Read the last terminal output by index.
- _single_question(render, dbus, context, args, user_id, name, description)[source]
Single question operation.
- Return type:
- Parameters:
- Returns:
The exit code.
- Return type:
- _submit_question(dbus, user_id, chat_id, message_input, plain)[source]
Submit the question over dbus.
- _trim_message_size(render, question)[source]
Trim the message size to fit within the maximum allowed size.