Skip to content

chat_workflow

django_spire.ai.chat.intelligence.workflows.chat_workflow

SpireChatWorkflow

Bases: BaseWorkflow

process classmethod

Source code in django_spire/ai/chat/intelligence/workflows/chat_workflow.py
@classmethod
@recorder_to_html_file('spire_chat_workflow')
def process(
        cls,
        request: WSGIRequest,
        user_input: str,
        message_history: MessageHistory | None = None
) -> BaseMessageIntel:
    intent_map = cls._generate_intent_map(request)
    intents = intent_map.process(user_input, max_return_values=1)

    if intents[0] is None:
        response = LlmBot.process(
            prompt=user_input,
            message_history=message_history,
            postfix_system_prompt=organization_prompt()
        )

        return DefaultMessageIntel(text=response.text)

    response = LlmBot.process(
        prompt=(
            Prompt()
            .text(f'User Input: {user_input}')
            .line_break()
            .text(
                'Use the following information to the answer the user\'s question '
                'or concern.'
            )
            .line_break()
            .text(intents[0].process(user_input))
        ),
        message_history=message_history,
        postfix_system_prompt=organization_prompt()
    )

    return DefaultMessageIntel(text=response.text)