Commit 1d4dc39f authored by Harris, Tyrone's avatar Harris, Tyrone
Browse files

remove email add chat

parent e5561dfb
Loading
Loading
Loading
Loading
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

+36 −0
Original line number Diff line number Diff line
graph TD
    subgraph Chat["Chat Input (Terminal)"]
        A[Chat Input Handler] --> Q[(Queue)]
        style Chat fill:#f0f,stroke:#333,stroke-width:2px,color:#000,fill-opacity:0.2;
    end

    subgraph Processing["Processing"]
        Q --> B[Extract Question/Follow-up]
        B --> C[Generate UID]
        C --> D[Store in DB]
        B --> E{Is Follow-up?}
        E -- Yes --> F[Extract UID from Reply]
        F --> G[Retrieve Context]
        E -- No --> H[Language Detection]
        G --> H
        H --> I{Is Input English?}
        I -- Yes --> J[Document Retriever]
        I -- No --> K["Translate to English"]
        K --> J
        J --> L[Contextual Answer<br>Generation]
        L --> M[Self-Corrective Agent]
        M -- Acceptable --> N["Translate to<br>UserLanguage"]
        M -- "Not Acceptable &<br>Retry < 3" --> J
        M -- "Not Acceptable &<br>Retry >= 3" --> N
        style Processing fill:#ccf,stroke:#333,stroke-width:2px,color:#000,fill-opacity:0.2;
    end

    subgraph Output["Output"]
        N --> O[Display Answer in Chat]
        O --> P[Update DB]
        style Output fill:#fcf,stroke:#333,stroke-width:2px,color:#000,fill-opacity:0.2;
    end

    P --> A

    classDef default text-align:center;
 No newline at end of file

requirements.txt

0 → 100644
+28 −0
Original line number Diff line number Diff line
# Core Libraries
langgraph==0.0.13  # Latest version as of Sept 30, 2024
sentence-transformers==2.2.2
spacy==3.6.1
langdetect==1.0.9
transformers==4.31.0

# Database (SQLite3 is usually included by default)
# sqlite3 

# Caching (Choose one based on your preference)
# - In-memory cache (no additional library needed)
# - Redis: 
# redis

# Email Handling (If implementing Outlook 365 integration in the future)
requests_oauthlib==1.3.1
microsoft-graph==0.60.0

# Offline LLM (Vicuna-7B)
torch==2.1.0
accelerate==0.23.0
bitsandbytes==0.41.0

# Other potential dependencies (add as needed)
numpy==1.26.0
pandas==2.1.1
# ... any other libraries used in your custom tool implementations
 No newline at end of file
+79 −0
Original line number Diff line number Diff line
import curses
import uuid

from langchain.tools import BaseTool

class ChatInputTool(BaseTool):
    name = "check_chat"
    description = "Gets user input from the terminal-based chat interface"

    def __init__(self, request_queue):
        super().__init__()
        self.request_queue = request_queue
        self.current_chat_uid = None

    def _run(self):
        # Initialize curses
        stdscr = curses.initscr()
        curses.cbreak()  # Get characters immediately
        curses.noecho()  # Don't echo user input
        stdscr.keypad(True)  # Enable special keys

        # Create chat window and input area
        height, width = stdscr.getmaxyx()
        chat_win = curses.newwin(height - 3, width, 0, 0)  # Leave space for input
        input_win = curses.newwin(3, width, height - 3, 0)
        chat_win.scrollok(True)  # Enable scrolling in chat window

        # Display welcome message
        self._display_message(chat_win, "Welcome to the Offline Q&A Chatbot!")

        while True:
            # Get user input
            user_input = self._get_user_input(input_win)

            if user_input:
                # Check if it's a new chat session
                if self.current_chat_uid is None:
                    self.current_chat_uid = str(uuid.uuid4())

                # Retrieve context if it's a follow-up question
                context = cache.get(self.current_chat_uid) if self.current_chat_uid else None

                # Add the request to the queue
                self.request_queue.put(("chat", user_input, self.current_chat_uid, context, None))

                # Display user input in the chat window
                self._display_message(chat_win, f"You: {user_input}")

    def _get_user_input(self, input_win):
        input_win.clear()
        input_win.addstr(1, 0, "You: ")
        input_win.refresh()

        user_input = ""
        while True:
            key = input_win.getch()
            if key == curses.KEY_ENTER or key in [10, 13]:  # Enter key
                break
            elif key == curses.KEY_BACKSPACE or key == 127:  # Backspace
                if user_input:
                    user_input = user_input[:-1]
                    y, x = input_win.getyx()
                    input_win.delch(y, x - 1)
                    input_win.refresh()
            else:
                user_input += chr(key)
                input_win.addch(key)
                input_win.refresh()

        return user_input.strip()

    def _display_message(self, chat_win, message):
        chat_win.addstr(message + "\n")
        chat_win.refresh()

        # Scroll the chat window if necessary
        max_y, _ = chat_win.getmaxyx()
        if chat_win.getyx()[0] >= max_y - 1:
            chat_win.scroll(1)
 No newline at end of file