02 05 strategy chat interface - VforVitorio/F1_Strat_Manager GitHub Wiki

Strategy Chat Interface

Relevant source files

  • scripts/app/components/strategy_chat.py
  • scripts/app/utils/data_loader.py The Strategy Chat Interface is an LLM-powered conversational component of the F1 Strategy Manager that enables users to interact with the system through natural language. It provides a ChatGPT-style interface where users can ask questions, seek explanations about race strategy, and analyze F1-related data including uploaded images such as charts and graphs. This interface serves as a complementary tool to the other specialized data visualization views in the system (see Strategy Recommendations View, Gap Analysis View, Radio Analysis View, and Time Predictions View). While those components provide structured visualizations of specific data types, the Strategy Chat Interface offers a more flexible, conversational way to explore F1 strategy concepts.

Component Architecture

Data Flow

2. Key Components

2.1 Chat Interface Components

The Streamlit-based interface is divided into three main areas:

  1. Chat History Display: Shows the conversation history with user and assistant messages
  2. Message Input Area: Allows users to enter text messages and upload images
  3. Sidebar Management Panel: Provides chat session management and model configuration options

2.2 Message Structure

The system handles multiple message types (text and images) and maintains them in a standardized format within the session state.

Field Description Example
role Message author "user" or "assistant"
type Content type "text" or "image"
content Message content Text string or image data

3. Functionality

3.1 Formula 1 Strategic Assistant

The chat interface is specialized for Formula 1 strategy assistance through a carefully crafted system prompt that defines its scope and capabilities:

  • Race strategy analysis and recommendations
  • Interpretation of F1 data visualizations (charts, tables, etc.)
  • Historical race data, driver information, and technical context
  • Analysis of uploaded images including lap time charts, tire degradation graphs, and race statistics The system prompt directs the model to focus exclusively on F1-related topics and to use appropriate F1 terminology.

3.2 Image Analysis Capabilities

The interface supports multimodal interaction through image uploads, allowing users to:

  1. Upload charts, graphs, or other F1-related images
  2. Ask specific questions about the visuals
  3. Receive detailed analysis from the F1 strategy assistant This feature is particularly useful for analyzing complex race data visualizations and getting expert interpretations.

3.3 Chat Session Management

Users can manage multiple chat sessions through the sidebar interface:

  • Create new chats with the "New chat" button
  • Browse and load saved chat sessions
  • Delete the current chat session
  • Automatically name chat sessions based on context or initial message This allows users to maintain separate conversations about different aspects of F1 strategy or different races.

4. Implementation Details

4.1 Streaming Responses

Rather than waiting for the complete LLM response, the interface streams the response in chunks, providing a more interactive experience:

  1. User input is sent to the LLM via handle_user_input_streaming()
  2. Response chunks are streamed back through stream_llm_response()
  3. The UI is updated in real-time as new chunks arrive
  4. The complete response is added to chat history when streaming completes

4.2 Model Configuration

Users can customize their interaction through model parameters:

  • Select from available Ollama models (with llama3.2-vision as default)
  • Adjust temperature (creativity) from 0.0 to 1.0 (default 0.2) The system retrieves available models dynamically from the Ollama service.

4.3 External Integration

The open_chat_with_image() function allows other components of the F1 Strategy Manager to programmatically open the chat interface with a specific image (such as a chart) for analysis:

This enables seamless integration between the data visualization components and the conversational interface.

5. UI Design

The chat interface follows a modern chat application design with:

  • Right-aligned user messages with navy blue background
  • Left-aligned assistant messages with gray background
  • Support for both text and image content
  • Custom CSS styling for readability
  • Racing-themed icons (🏎️ for user, 🏁 for assistant)

6. Technical Requirements

The Strategy Chat Interface requires:

  1. A locally running Ollama service on port 11434
  2. Compatible LLM models with multimodal support (for image analysis)
  3. Streamlit for the web interface components If the Ollama service is unavailable, the interface will display appropriate error messages and fallback gracefully.