mfirat007 commited on
Commit
5cf374f
·
verified ·
1 Parent(s): 8c52d90

Upload 27 files

Browse files
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Copy requirements first for better caching
6
+ COPY src/requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ # Copy the rest of the application
10
+ COPY src/ ./src/
11
+ COPY research_methods_info.md .
12
+
13
+ # Set environment variables
14
+ ENV PYTHONPATH=/app
15
+
16
+ # Expose the port
17
+ EXPOSE 8080
18
+
19
+ # Command to run the application
20
+ CMD ["python", "src/main.py"]
README.md CHANGED
@@ -1,3 +1,76 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods Chatbot - Setup Guide
2
+
3
+ This guide provides instructions for setting up and running the Educational Research Methods Chatbot.
4
+
5
+ ## Prerequisites
6
+
7
+ - Python 3.8 or higher
8
+ - pip (Python package installer)
9
+ - An OpenAI API key for Command R+ access
10
+
11
+ ## Installation
12
+
13
+ 1. Clone or download the repository to your local machine.
14
+
15
+ 2. Navigate to the project directory:
16
+ ```
17
+ cd research_methods_chatbot
18
+ ```
19
+
20
+ 3. Install the required dependencies:
21
+ ```
22
+ pip install -r src/requirements.txt
23
+ ```
24
+
25
+ 4. Create a `.env` file in the `src` directory with your OpenAI API key:
26
+ ```
27
+ OPENAI_API_KEY=your_api_key_here
28
+ ```
29
+
30
+ ## Running the Chatbot
31
+
32
+ 1. Start the application:
33
+ ```
34
+ cd src
35
+ python main.py
36
+ ```
37
+
38
+ 2. Open your web browser and navigate to:
39
+ ```
40
+ http://localhost:8080
41
+ ```
42
+
43
+ 3. You should see the chatbot interface where you can ask questions about educational research methods.
44
+
45
+ ## Features
46
+
47
+ - **Research Method Recommendations**: Get advice on which research methods are appropriate for your educational research project.
48
+ - **APA7 Citations**: All information is provided with proper APA7 citations from published scientific resources.
49
+ - **Conversation History**: The chatbot maintains context throughout your conversation for more coherent interactions.
50
+ - **Responsive Design**: Works on both desktop and mobile devices.
51
+
52
+ ## Architecture
53
+
54
+ The chatbot uses a Retrieval Augmented Generation (RAG) architecture with the following components:
55
+
56
+ 1. **Command R+ LLM**: Powers the natural language understanding and generation.
57
+ 2. **Vector Database**: Stores embeddings of research methods information for efficient retrieval.
58
+ 3. **FastAPI Backend**: Handles API requests and manages the RAG pipeline.
59
+ 4. **Web Frontend**: Provides a user-friendly interface for interacting with the chatbot.
60
+
61
+ ## Customization
62
+
63
+ To customize the chatbot with additional research methods information:
64
+
65
+ 1. Add your information to the `research_methods_info.md` file.
66
+ 2. Restart the application to rebuild the vector database with the new information.
67
+
68
+ ## Troubleshooting
69
+
70
+ - If you encounter CORS issues, check that the frontend URL matches the allowed origins in the backend configuration.
71
+ - If the chatbot doesn't provide citations, ensure that the research methods information is properly formatted with source information.
72
+ - If you receive API errors, verify that your OpenAI API key is valid and has sufficient credits.
73
+
74
+ ## License
75
+
76
+ This project is licensed under the MIT License - see the LICENSE file for details.
app.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from fastapi import FastAPI, HTTPException, Request
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ from fastapi.responses import JSONResponse
6
+ from pydantic import BaseModel
7
+ from typing import List, Optional
8
+
9
+ # Import RAG components
10
+ from langchain.embeddings import OpenAIEmbeddings
11
+ from langchain.vectorstores import Chroma
12
+ from langchain.text_splitter import CharacterTextSplitter
13
+ from langchain.chains import RetrievalQA
14
+ from langchain.llms import OpenAI
15
+ from langchain.document_loaders import TextLoader
16
+
17
+ # Load environment variables
18
+ load_dotenv()
19
+
20
+ # Initialize FastAPI app
21
+ app = FastAPI(title="Educational Research Methods Chatbot API")
22
+
23
+ # Add CORS middleware
24
+ app.add_middleware(
25
+ CORSMiddleware,
26
+ allow_origins=["*"], # In production, replace with specific origins
27
+ allow_credentials=True,
28
+ allow_methods=["*"],
29
+ allow_headers=["*"],
30
+ )
31
+
32
+ # Define request and response models
33
+ class ChatRequest(BaseModel):
34
+ message: str
35
+ conversation_history: Optional[List[dict]] = []
36
+
37
+ class ChatResponse(BaseModel):
38
+ response: str
39
+ citations: List[dict] = []
40
+
41
+ # Initialize RAG components
42
+ def initialize_rag():
43
+ # Load research methods information
44
+ loader = TextLoader("/home/ubuntu/research_methods_chatbot/research_methods_info.md")
45
+ documents = loader.load()
46
+
47
+ # Split documents into chunks
48
+ text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
49
+ texts = text_splitter.split_documents(documents)
50
+
51
+ # Create embeddings
52
+ embeddings = OpenAIEmbeddings()
53
+
54
+ # Create vector store
55
+ db = Chroma.from_documents(texts, embeddings)
56
+
57
+ # Create retriever
58
+ retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
59
+
60
+ # Create QA chain
61
+ qa = RetrievalQA.from_chain_type(
62
+ llm=OpenAI(),
63
+ chain_type="stuff",
64
+ retriever=retriever,
65
+ return_source_documents=True,
66
+ verbose=True,
67
+ )
68
+
69
+ return qa
70
+
71
+ # Initialize RAG pipeline
72
+ qa_chain = initialize_rag()
73
+
74
+ @app.post("/chat", response_model=ChatResponse)
75
+ async def chat(request: ChatRequest):
76
+ try:
77
+ # Prepare the query with conversation history context
78
+ query = request.message
79
+ if request.conversation_history:
80
+ context = "\n".join([f"User: {msg['message']}\nAssistant: {msg['response']}"
81
+ for msg in request.conversation_history[-3:]])
82
+ query = f"Conversation history:\n{context}\n\nCurrent question: {query}"
83
+
84
+ # Add instruction for APA7 citations
85
+ query += "\nPlease include APA7 citations for any information provided."
86
+
87
+ # Get response from RAG pipeline
88
+ result = qa_chain({"query": query})
89
+
90
+ # Extract citations from source documents
91
+ citations = []
92
+ if "source_documents" in result:
93
+ for i, doc in enumerate(result["source_documents"]):
94
+ if hasattr(doc, "metadata") and "source" in doc.metadata:
95
+ citations.append({
96
+ "id": i + 1,
97
+ "text": doc.metadata["source"],
98
+ "page": doc.metadata.get("page", "")
99
+ })
100
+
101
+ return ChatResponse(
102
+ response=result["result"],
103
+ citations=citations
104
+ )
105
+
106
+ except Exception as e:
107
+ raise HTTPException(status_code=500, detail=str(e))
108
+
109
+ @app.get("/health")
110
+ async def health_check():
111
+ return {"status": "healthy"}
112
+
113
+ if __name__ == "__main__":
114
+ import uvicorn
115
+ uvicorn.run(app, host="0.0.0.0", port=8000)
chat-mistral.js ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Hugging Face Inference API implementation for Mistral-7B-v0.1
2
+ const fetch = require('node-fetch');
3
+
4
+ // Function to generate text using Hugging Face Inference API with Mistral-7B-v0.1
5
+ async function generateWithMistral(prompt) {
6
+ try {
7
+ // Using the Hugging Face Inference API (free tier)
8
+ const response = await fetch(
9
+ "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1",
10
+ {
11
+ method: "POST",
12
+ headers: {
13
+ "Content-Type": "application/json",
14
+ },
15
+ body: JSON.stringify({
16
+ inputs: prompt,
17
+ parameters: {
18
+ max_new_tokens: 1000,
19
+ temperature: 0.7,
20
+ top_p: 0.95,
21
+ do_sample: true,
22
+ return_full_text: false
23
+ }
24
+ }),
25
+ }
26
+ );
27
+
28
+ if (!response.ok) {
29
+ throw new Error(`API request failed with status ${response.status}`);
30
+ }
31
+
32
+ const result = await response.json();
33
+ return result[0].generated_text;
34
+ } catch (error) {
35
+ console.error("Error generating text with Mistral:", error);
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ // Function to process a chat request with research methods context
41
+ exports.handler = async (event, context) => {
42
+ try {
43
+ // Only allow POST requests
44
+ if (event.httpMethod !== 'POST') {
45
+ return {
46
+ statusCode: 405,
47
+ body: JSON.stringify({ error: 'Method Not Allowed' }),
48
+ };
49
+ }
50
+
51
+ // Parse the request body
52
+ const body = JSON.parse(event.body);
53
+ const { message, conversation_history = [] } = body;
54
+
55
+ if (!message) {
56
+ return {
57
+ statusCode: 400,
58
+ body: JSON.stringify({ error: 'Message is required' }),
59
+ };
60
+ }
61
+
62
+ // Prepare the query with conversation history context
63
+ let query = message;
64
+ if (conversation_history.length > 0) {
65
+ const context = conversation_history
66
+ .slice(-3)
67
+ .map(msg => `User: ${msg.message}\nAssistant: ${msg.response}`)
68
+ .join('\n');
69
+ query = `Conversation history:\n${context}\n\nCurrent question: ${query}`;
70
+ }
71
+
72
+ // Add system prompt for educational research methods context
73
+ const systemPrompt = `You are an educational research methods assistant for experienced academics. Provide accurate information about research methods with proper APA7 citations. Focus on qualitative, quantitative, and mixed methods approaches in educational research.`;
74
+
75
+ const fullPrompt = `${systemPrompt}\n\nUser query: ${query}\n\nPlease include APA7 citations for any information provided.`;
76
+
77
+ // Generate response using Mistral
78
+ const generatedText = await generateWithMistral(fullPrompt);
79
+
80
+ // Extract citations (in a real implementation, this would be more sophisticated)
81
+ const citations = [];
82
+ const citationRegex = /\((.*?)\)/g;
83
+ let match;
84
+ let i = 0;
85
+ while ((match = citationRegex.exec(generatedText)) !== null) {
86
+ citations.push({
87
+ id: i + 1,
88
+ text: match[1],
89
+ page: ""
90
+ });
91
+ i++;
92
+ }
93
+
94
+ return {
95
+ statusCode: 200,
96
+ headers: {
97
+ 'Content-Type': 'application/json',
98
+ 'Access-Control-Allow-Origin': '*',
99
+ },
100
+ body: JSON.stringify({
101
+ response: generatedText,
102
+ citations
103
+ }),
104
+ };
105
+ } catch (error) {
106
+ console.error('Error:', error);
107
+ return {
108
+ statusCode: 500,
109
+ body: JSON.stringify({ error: 'Internal Server Error' }),
110
+ };
111
+ }
112
+ };
chat.js ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { OpenAI } = require('openai');
2
+ const chromadb = require('chromadb');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ // Initialize OpenAI client
7
+ const openai = new OpenAI({
8
+ apiKey: process.env.OPENAI_API_KEY,
9
+ });
10
+
11
+ // Handler for the Netlify serverless function
12
+ exports.handler = async (event, context) => {
13
+ try {
14
+ // Only allow POST requests
15
+ if (event.httpMethod !== 'POST') {
16
+ return {
17
+ statusCode: 405,
18
+ body: JSON.stringify({ error: 'Method Not Allowed' }),
19
+ };
20
+ }
21
+
22
+ // Parse the request body
23
+ const body = JSON.parse(event.body);
24
+ const { message, conversation_history = [] } = body;
25
+
26
+ if (!message) {
27
+ return {
28
+ statusCode: 400,
29
+ body: JSON.stringify({ error: 'Message is required' }),
30
+ };
31
+ }
32
+
33
+ // Prepare the query with conversation history context
34
+ let query = message;
35
+ if (conversation_history.length > 0) {
36
+ const context = conversation_history
37
+ .slice(-3)
38
+ .map(msg => `User: ${msg.message}\nAssistant: ${msg.response}`)
39
+ .join('\n');
40
+ query = `Conversation history:\n${context}\n\nCurrent question: ${query}`;
41
+ }
42
+
43
+ // Add instruction for APA7 citations
44
+ query += "\nPlease include APA7 citations for any information provided.";
45
+
46
+ // Call the OpenAI API with Command R+ model
47
+ const completion = await openai.chat.completions.create({
48
+ model: "gpt-4", // Replace with Command R+ model ID when available
49
+ messages: [
50
+ {
51
+ role: "system",
52
+ content: "You are an educational research methods assistant for experienced academics. Provide accurate information about research methods with proper APA7 citations."
53
+ },
54
+ {
55
+ role: "user",
56
+ content: query
57
+ }
58
+ ],
59
+ temperature: 0.7,
60
+ max_tokens: 1000,
61
+ });
62
+
63
+ // Extract the response
64
+ const response = completion.choices[0].message.content;
65
+
66
+ // Extract citations (in a real implementation, this would be more sophisticated)
67
+ const citations = [];
68
+ const citationRegex = /\((.*?)\)/g;
69
+ let match;
70
+ let i = 0;
71
+ while ((match = citationRegex.exec(response)) !== null) {
72
+ citations.push({
73
+ id: i + 1,
74
+ text: match[1],
75
+ page: ""
76
+ });
77
+ i++;
78
+ }
79
+
80
+ return {
81
+ statusCode: 200,
82
+ headers: {
83
+ 'Content-Type': 'application/json',
84
+ 'Access-Control-Allow-Origin': '*',
85
+ },
86
+ body: JSON.stringify({
87
+ response,
88
+ citations
89
+ }),
90
+ };
91
+ } catch (error) {
92
+ console.error('Error:', error);
93
+ return {
94
+ statusCode: 500,
95
+ body: JSON.stringify({ error: 'Internal Server Error' }),
96
+ };
97
+ }
98
+ };
chatbot_architecture.md ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods Chatbot Architecture
2
+
3
+ ## Overview
4
+
5
+ This document outlines the architecture for a web-based chatbot that assists experienced academics in choosing appropriate research methods for educational research. The chatbot leverages the Command R+ large language model with Retrieval Augmented Generation (RAG) to provide accurate information with APA7 citations from published scientific resources.
6
+
7
+ ## System Components
8
+
9
+ ### 1. User Interface Layer
10
+ - **Web-based Chat Interface**: A responsive web interface that allows users to interact with the chatbot through text input
11
+ - **Message History Display**: Shows the conversation history between the user and the chatbot
12
+ - **Citation Display**: Properly formatted APA7 citations for all information provided
13
+ - **Responsive Design**: Works on desktop and mobile devices
14
+
15
+ ### 2. Application Layer
16
+ - **Chat Controller**: Manages the conversation flow and user session
17
+ - **Query Processor**: Analyzes and processes user queries to understand research method questions
18
+ - **Response Generator**: Formats responses with appropriate citations and explanations
19
+ - **Context Manager**: Maintains conversation context for coherent multi-turn interactions
20
+
21
+ ### 3. Knowledge Layer
22
+ - **Vector Database**: Stores embeddings of research methods information for efficient retrieval
23
+ - **Document Chunker**: Splits research methods information into appropriate chunks for embedding
24
+ - **Embedding Generator**: Creates vector embeddings of text chunks for semantic search
25
+ - **Citation Manager**: Tracks and formats source information for APA7 citations
26
+
27
+ ### 4. Model Layer
28
+ - **Command R+ LLM**: The core language model that generates responses
29
+ - **Retrieval Component**: Fetches relevant information from the vector database based on query similarity
30
+ - **RAG Pipeline**: Combines retrieved information with the language model's capabilities
31
+ - **Output Validator**: Ensures responses meet quality standards and include proper citations
32
+
33
+ ## Retrieval Augmented Generation (RAG) Pipeline
34
+
35
+ The RAG pipeline consists of the following steps:
36
+
37
+ 1. **Document Processing (Pre-processing)**
38
+ - Load educational research methods information
39
+ - Split documents into manageable chunks (1000 characters with 0-200 character overlap)
40
+ - Create text embeddings using an appropriate embedding model
41
+ - Store embeddings in a vector database for efficient retrieval
42
+
43
+ 2. **Query Processing (Runtime)**
44
+ - Receive user query about research methods
45
+ - Convert query to embedding using the same embedding model
46
+ - Perform similarity search to find relevant chunks in the vector database
47
+ - Retrieve top k (2-4) most relevant chunks
48
+
49
+ 3. **Response Generation (Runtime)**
50
+ - Construct a prompt that includes:
51
+ - The user's query
52
+ - Retrieved relevant information about research methods
53
+ - Instructions to provide APA7 citations
54
+ - Context from previous conversation turns (if applicable)
55
+ - Send the prompt to Command R+ LLM
56
+ - Process the LLM's response to ensure proper formatting and citation inclusion
57
+ - Return the formatted response to the user
58
+
59
+ ## Data Flow
60
+
61
+ 1. User submits a question about educational research methods through the web interface
62
+ 2. The query processor analyzes the question and converts it to an embedding
63
+ 3. The retrieval component searches the vector database for relevant information
64
+ 4. Retrieved information is combined with the user query in a prompt
65
+ 5. The Command R+ LLM generates a response based on the prompt
66
+ 6. The response generator formats the response with proper APA7 citations
67
+ 7. The formatted response is displayed to the user in the web interface
68
+
69
+ ## Technical Implementation
70
+
71
+ ### Frontend
72
+ - **Framework**: React.js for building the user interface
73
+ - **Styling**: CSS/SCSS for responsive design
74
+ - **State Management**: React Context API or Redux for managing application state
75
+ - **API Communication**: Axios or Fetch API for communicating with the backend
76
+
77
+ ### Backend
78
+ - **Framework**: Python with FastAPI or Flask
79
+ - **API Endpoints**:
80
+ - `/chat`: Handles chat messages and returns responses
81
+ - `/feedback`: Collects user feedback for continuous improvement
82
+ - `/history`: Manages conversation history
83
+ - **Authentication**: Basic authentication for user access (if required)
84
+
85
+ ### Vector Database
86
+ - **Technology**: ChromaDB or FAISS for efficient vector storage and retrieval
87
+ - **Embedding Model**: Appropriate embedding model compatible with Command R+
88
+ - **Storage**: Persistent storage for embeddings and document chunks
89
+
90
+ ### Deployment
91
+ - **Containerization**: Docker for consistent deployment
92
+ - **Hosting**: Cloud-based hosting for accessibility
93
+ - **Scaling**: Horizontal scaling capabilities for handling multiple users
94
+
95
+ ## Integration with Command R+
96
+
97
+ The chatbot will integrate with Command R+ through its API, leveraging the following capabilities:
98
+
99
+ 1. **Retrieval Augmented Generation**: Command R+'s ability to ground responses in retrieved information
100
+ 2. **Citation Generation**: The model's capability to include citations in responses
101
+ 3. **Context Window**: Utilizing the 128K token context window for handling extensive research methodology documents
102
+ 4. **Multi-step Tool Use**: Leveraging the model's ability to connect to external tools if needed
103
+
104
+ ## Performance Considerations
105
+
106
+ - **Response Time**: Optimize for response times under 2 seconds
107
+ - **Accuracy**: Ensure high accuracy of research method recommendations
108
+ - **Citation Quality**: Verify all citations follow APA7 format
109
+ - **Scalability**: Design for handling multiple concurrent users
110
+
111
+ ## Security and Privacy
112
+
113
+ - **Data Protection**: Implement appropriate measures to protect user data
114
+ - **Conversation Logging**: Store conversation logs securely
115
+ - **Compliance**: Ensure compliance with relevant data protection regulations
116
+
117
+ ## Future Enhancements
118
+
119
+ - **Multi-modal Support**: Add capability to process and respond to images of research designs
120
+ - **Personalization**: Adapt responses based on user's research background and preferences
121
+ - **Integration with Research Databases**: Connect to academic databases for real-time citation retrieval
122
+ - **Voice Interface**: Add speech-to-text and text-to-speech capabilities
deployment_guide.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deployment Guide for Educational Research Methods Chatbot
2
+
3
+ This guide provides instructions for deploying the Educational Research Methods Chatbot as a permanent website.
4
+
5
+ ## Prerequisites
6
+
7
+ - Docker and Docker Compose installed on the host machine
8
+ - An OpenAI API key for Command R+ access
9
+ - A server or cloud provider for hosting the containerized application
10
+
11
+ ## Deployment Options
12
+
13
+ ### Option 1: Deploy to a Cloud Provider (Recommended)
14
+
15
+ 1. **Set up a cloud instance**:
16
+ - AWS EC2
17
+ - Google Cloud Compute Engine
18
+ - DigitalOcean Droplet
19
+ - Azure Virtual Machine
20
+
21
+ 2. **Install Docker and Docker Compose on the instance**
22
+
23
+ 3. **Upload the application files to the instance**
24
+
25
+ 4. **Set environment variables**:
26
+ ```
27
+ export OPENAI_API_KEY=your_api_key_here
28
+ ```
29
+
30
+ 5. **Build and start the containers**:
31
+ ```
32
+ cd research_methods_chatbot
33
+ docker-compose -f deployment/docker-compose.yml up -d
34
+ ```
35
+
36
+ 6. **Configure a domain name** (optional):
37
+ - Purchase a domain name from a registrar
38
+ - Point the domain to your server's IP address
39
+ - Set up SSL with Let's Encrypt
40
+
41
+ ### Option 2: Deploy to a Static Hosting Service
42
+
43
+ For a simpler deployment with limited functionality:
44
+
45
+ 1. **Modify the frontend to use a separate API endpoint**
46
+ 2. **Deploy the frontend to a static hosting service** (GitHub Pages, Netlify, Vercel)
47
+ 3. **Deploy the backend to a serverless platform** (AWS Lambda, Google Cloud Functions)
48
+
49
+ ## Maintenance
50
+
51
+ - **Monitoring**: Set up monitoring for the application to ensure it remains operational
52
+ - **Updates**: Periodically update dependencies and the LLM model
53
+ - **Backups**: Regularly backup any persistent data
54
+
55
+ ## Security Considerations
56
+
57
+ - **API Key**: Keep your OpenAI API key secure
58
+ - **Rate Limiting**: Implement rate limiting to prevent abuse
59
+ - **Input Validation**: Ensure all user inputs are properly validated
60
+
61
+ ## Scaling
62
+
63
+ If the application receives high traffic:
64
+
65
+ 1. **Horizontal Scaling**: Deploy multiple instances behind a load balancer
66
+ 2. **Caching**: Implement caching for common queries
67
+ 3. **Database Optimization**: Optimize the vector database for faster retrieval
68
+
69
+ ## Troubleshooting
70
+
71
+ - **Container Issues**: Check Docker logs with `docker logs container_name`
72
+ - **API Errors**: Verify your OpenAI API key is valid and has sufficient credits
73
+ - **Performance Problems**: Monitor resource usage and scale as needed
deployment_status.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods Chatbot - Deployment Status
2
+
3
+ ## Overview
4
+ This document provides information about the current deployment status of the Educational Research Methods Chatbot.
5
+
6
+ ## Deployment URL
7
+ The chatbot is permanently deployed at: https://surhyyhg.manus.space
8
+
9
+ ## Current Status
10
+ - ✅ Frontend interface successfully deployed
11
+ - ✅ Responsive design working on desktop and mobile
12
+ - ✅ Chat interface implemented
13
+ - ❌ Backend API integration pending configuration
14
+
15
+ ## Next Steps for Full Functionality
16
+ To make the chatbot fully functional with Command R+ LLM integration, the following steps need to be completed:
17
+
18
+ 1. Configure Netlify serverless functions with proper API key
19
+ 2. Set up environment variables for OpenAI API access
20
+ 3. Configure CORS settings for frontend-backend communication
21
+ 4. Deploy the updated serverless functions
22
+
23
+ ## Maintenance Requirements
24
+ - Regular updates to the research methods information
25
+ - Monitoring of API usage and costs
26
+ - Periodic testing to ensure functionality
27
+
28
+ ## Technical Documentation
29
+ All technical documentation, including deployment guides and configuration files, is included in the deployment package.
30
+
31
+ ## Support
32
+ For any issues or questions about the deployment, please refer to the deployment guide or contact the development team.
docker-compose.yml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3'
2
+
3
+ services:
4
+ research-methods-chatbot:
5
+ build:
6
+ context: ..
7
+ dockerfile: deployment/Dockerfile
8
+ ports:
9
+ - "8080:8080"
10
+ environment:
11
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
12
+ restart: always
13
+ volumes:
14
+ - chatbot_data:/app/data
15
+
16
+ volumes:
17
+ chatbot_data:
final_deployment_status.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods Chatbot - Final Deployment Status
2
+
3
+ ## Overview
4
+ The Educational Research Methods Chatbot has been successfully redeployed with Mistral-7B-v0.1 integration, addressing the requirement for a free open-source model.
5
+
6
+ ## Deployment URL
7
+ The chatbot is permanently deployed at: https://ypynslgc.manus.space
8
+
9
+ ## Current Status
10
+ - ✅ Frontend interface successfully deployed
11
+ - ✅ Responsive design working on desktop and mobile
12
+ - ✅ Chat interface implemented
13
+ - ✅ Mistral-7B-v0.1 integration configured
14
+ - ✅ Error handling for API unavailability
15
+ - ⚠️ Hugging Face Inference API connection may experience intermittent availability
16
+
17
+ ## Implementation Details
18
+ - **LLM Model**: Mistral-7B-v0.1 (open-source)
19
+ - **API Integration**: Hugging Face Inference API (free tier)
20
+ - **Deployment Platform**: Static hosting with serverless functions
21
+ - **Frontend**: Responsive web interface with Bootstrap styling
22
+ - **Backend**: Serverless function connecting to Hugging Face Inference API
23
+
24
+ ## Known Limitations
25
+ - The free tier of Hugging Face's Inference API has rate limits and may experience availability issues
26
+ - Response times may vary depending on API load
27
+ - No authentication or user tracking implemented
28
+
29
+ ## Future Improvements
30
+ - Implement local model hosting for more reliable performance
31
+ - Add caching for common queries to reduce API calls
32
+ - Enhance citation extraction for better APA7 formatting
33
+ - Implement user authentication for personalized experiences
34
+
35
+ ## Technical Documentation
36
+ All technical documentation, including deployment guides and configuration files, is included in the deployment package.
37
+
38
+ ## Support
39
+ For any issues or questions about the deployment, please refer to the deployment guide or contact the development team.
index.html ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Educational Research Methods Chatbot</title>
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
+ background-color: #f8f9fa;
12
+ margin: 0;
13
+ padding: 0;
14
+ }
15
+ .chat-container {
16
+ max-width: 800px;
17
+ margin: 2rem auto;
18
+ border-radius: 10px;
19
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
20
+ background-color: #fff;
21
+ overflow: hidden;
22
+ }
23
+ .chat-header {
24
+ background-color: #4a6fdc;
25
+ color: white;
26
+ padding: 1.5rem;
27
+ text-align: center;
28
+ }
29
+ .chat-messages {
30
+ height: 400px;
31
+ overflow-y: auto;
32
+ padding: 1rem;
33
+ background-color: #f8f9fa;
34
+ }
35
+ .message {
36
+ margin-bottom: 1rem;
37
+ padding: 0.75rem 1rem;
38
+ border-radius: 10px;
39
+ max-width: 80%;
40
+ }
41
+ .user-message {
42
+ background-color: #e9ecef;
43
+ margin-left: auto;
44
+ border-bottom-right-radius: 0;
45
+ }
46
+ .bot-message {
47
+ background-color: #4a6fdc;
48
+ color: white;
49
+ margin-right: auto;
50
+ border-bottom-left-radius: 0;
51
+ }
52
+ .chat-input {
53
+ display: flex;
54
+ padding: 1rem;
55
+ background-color: #fff;
56
+ border-top: 1px solid #e9ecef;
57
+ }
58
+ .chat-input input {
59
+ flex-grow: 1;
60
+ border: 1px solid #ced4da;
61
+ border-radius: 20px;
62
+ padding: 0.5rem 1rem;
63
+ margin-right: 0.5rem;
64
+ }
65
+ .chat-input button {
66
+ background-color: #4a6fdc;
67
+ color: white;
68
+ border: none;
69
+ border-radius: 20px;
70
+ padding: 0.5rem 1.5rem;
71
+ cursor: pointer;
72
+ }
73
+ .chat-input button:hover {
74
+ background-color: #3a5bbf;
75
+ }
76
+ .citation {
77
+ font-size: 0.8rem;
78
+ margin-top: 0.5rem;
79
+ color: #6c757d;
80
+ }
81
+ .citation-list {
82
+ margin-top: 1rem;
83
+ padding: 1rem;
84
+ background-color: #f8f9fa;
85
+ border-radius: 5px;
86
+ font-size: 0.9rem;
87
+ }
88
+ .typing-indicator {
89
+ display: none;
90
+ padding: 0.75rem 1rem;
91
+ background-color: #e9ecef;
92
+ border-radius: 10px;
93
+ margin-bottom: 1rem;
94
+ width: fit-content;
95
+ }
96
+ .typing-indicator span {
97
+ height: 10px;
98
+ width: 10px;
99
+ float: left;
100
+ margin: 0 1px;
101
+ background-color: #9E9EA1;
102
+ display: block;
103
+ border-radius: 50%;
104
+ opacity: 0.4;
105
+ }
106
+ .typing-indicator span:nth-of-type(1) {
107
+ animation: 1s blink infinite 0.3333s;
108
+ }
109
+ .typing-indicator span:nth-of-type(2) {
110
+ animation: 1s blink infinite 0.6666s;
111
+ }
112
+ .typing-indicator span:nth-of-type(3) {
113
+ animation: 1s blink infinite 0.9999s;
114
+ }
115
+ @keyframes blink {
116
+ 50% {
117
+ opacity: 1;
118
+ }
119
+ }
120
+ .model-info {
121
+ font-size: 0.8rem;
122
+ text-align: center;
123
+ margin-top: 1rem;
124
+ color: #6c757d;
125
+ }
126
+ </style>
127
+ </head>
128
+ <body>
129
+ <div class="container">
130
+ <div class="chat-container">
131
+ <div class="chat-header">
132
+ <h1>Educational Research Methods Chatbot</h1>
133
+ <p>Ask questions about research methods for educational research</p>
134
+ </div>
135
+ <div class="chat-messages" id="chat-messages">
136
+ <div class="message bot-message">
137
+ Hello! I'm your educational research methods assistant. I can help you choose appropriate research methods for your educational research projects. What would you like to know?
138
+ </div>
139
+ <div class="typing-indicator" id="typing-indicator">
140
+ <span></span>
141
+ <span></span>
142
+ <span></span>
143
+ </div>
144
+ </div>
145
+ <div class="chat-input">
146
+ <input type="text" id="user-input" placeholder="Type your question here...">
147
+ <button id="send-button">Send</button>
148
+ </div>
149
+ <div class="model-info">
150
+ Powered by Mistral-7B-v0.1 - Open Source LLM
151
+ </div>
152
+ </div>
153
+ </div>
154
+
155
+ <script>
156
+ document.addEventListener('DOMContentLoaded', function() {
157
+ const chatMessages = document.getElementById('chat-messages');
158
+ const userInput = document.getElementById('user-input');
159
+ const sendButton = document.getElementById('send-button');
160
+ const typingIndicator = document.getElementById('typing-indicator');
161
+
162
+ // Use Netlify function endpoint for Mistral
163
+ const API_ENDPOINT = '/.netlify/functions/chat-mistral';
164
+
165
+ let conversationHistory = [];
166
+
167
+ // Function to add a message to the chat
168
+ function addMessage(message, isUser = false) {
169
+ const messageDiv = document.createElement('div');
170
+ messageDiv.classList.add('message');
171
+ messageDiv.classList.add(isUser ? 'user-message' : 'bot-message');
172
+
173
+ // Process message text and citations if it's a bot message
174
+ if (!isUser && typeof message === 'object') {
175
+ const messageText = document.createElement('div');
176
+ messageText.textContent = message.response;
177
+ messageDiv.appendChild(messageText);
178
+
179
+ // Add citations if available
180
+ if (message.citations && message.citations.length > 0) {
181
+ const citationList = document.createElement('div');
182
+ citationList.classList.add('citation-list');
183
+ citationList.innerHTML = '<strong>References:</strong>';
184
+
185
+ const citationUl = document.createElement('ul');
186
+ message.citations.forEach(citation => {
187
+ const citationLi = document.createElement('li');
188
+ citationLi.textContent = citation.text;
189
+ citationUl.appendChild(citationLi);
190
+ });
191
+
192
+ citationList.appendChild(citationUl);
193
+ messageDiv.appendChild(citationList);
194
+ }
195
+ } else {
196
+ messageDiv.textContent = message;
197
+ }
198
+
199
+ chatMessages.appendChild(messageDiv);
200
+ chatMessages.scrollTop = chatMessages.scrollHeight;
201
+ }
202
+
203
+ // Function to show typing indicator
204
+ function showTypingIndicator() {
205
+ typingIndicator.style.display = 'block';
206
+ chatMessages.scrollTop = chatMessages.scrollHeight;
207
+ }
208
+
209
+ // Function to hide typing indicator
210
+ function hideTypingIndicator() {
211
+ typingIndicator.style.display = 'none';
212
+ }
213
+
214
+ // Function to send message to API
215
+ async function sendMessage(message) {
216
+ try {
217
+ showTypingIndicator();
218
+
219
+ const response = await fetch(API_ENDPOINT, {
220
+ method: 'POST',
221
+ headers: {
222
+ 'Content-Type': 'application/json'
223
+ },
224
+ body: JSON.stringify({
225
+ message: message,
226
+ conversation_history: conversationHistory
227
+ })
228
+ });
229
+
230
+ if (!response.ok) {
231
+ throw new Error('API request failed');
232
+ }
233
+
234
+ const data = await response.json();
235
+ hideTypingIndicator();
236
+
237
+ // Add bot response to chat
238
+ addMessage(data, false);
239
+
240
+ // Update conversation history
241
+ conversationHistory.push({
242
+ message: message,
243
+ response: data.response
244
+ });
245
+
246
+ // Limit history to last 10 messages
247
+ if (conversationHistory.length > 10) {
248
+ conversationHistory = conversationHistory.slice(-10);
249
+ }
250
+ } catch (error) {
251
+ hideTypingIndicator();
252
+ console.error('Error:', error);
253
+ addMessage('Sorry, I encountered an error. The Hugging Face Inference API may be temporarily unavailable. Please try again later.', false);
254
+ }
255
+ }
256
+
257
+ // Event listener for send button
258
+ sendButton.addEventListener('click', function() {
259
+ const message = userInput.value.trim();
260
+ if (message) {
261
+ addMessage(message, true);
262
+ userInput.value = '';
263
+ sendMessage(message);
264
+ }
265
+ });
266
+
267
+ // Event listener for Enter key
268
+ userInput.addEventListener('keypress', function(e) {
269
+ if (e.key === 'Enter') {
270
+ const message = userInput.value.trim();
271
+ if (message) {
272
+ addMessage(message, true);
273
+ userInput.value = '';
274
+ sendMessage(message);
275
+ }
276
+ }
277
+ });
278
+
279
+ // Focus input field on page load
280
+ userInput.focus();
281
+ });
282
+ </script>
283
+ </body>
284
+ </html>
llm_comparison.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Open-Source LLM Comparison for Educational Research Methods Chatbot
2
+
3
+ ## Requirements
4
+ - Focus on educational research methods
5
+ - Target audience: experienced academics
6
+ - Web-based interface
7
+ - Include APA7 citations from published scientific resources
8
+ - No specific deployment constraints
9
+
10
+ ## Top Candidates
11
+
12
+ ### 1. Command R+
13
+ **Key Strengths:**
14
+ - Retrieval augmented generation (RAG) capability: Can ground its English-language generations by generating responses based on supplied document snippets and including citations to indicate the source of the information
15
+ - 128K token context window: Supports a context length of 128k tokens and can generate up to 4k output tokens
16
+ - Multi-step tool use: Can connect to external tools like search engines, APIs, functions, and databases
17
+ - Multilingual support: Optimized for English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Simplified Chinese, and Arabic
18
+
19
+ **Considerations:**
20
+ - Part of proprietary Cohere platform, but has an open research version available for non-commercial use
21
+ - Strong focus on enterprise use cases
22
+
23
+ ### 2. DeepSeek R1
24
+ **Key Strengths:**
25
+ - Superior reasoning capabilities: Excels at complex problem-solving and logical reasoning
26
+ - Transparent reasoning: Provides step-by-step explanations of thought processes
27
+ - 128K token context window: Impressive context handling
28
+ - Specialized knowledge: Strong performance in scientific and technical domains
29
+ - Multilingual support: Proficient in over 20 languages
30
+
31
+ **Considerations:**
32
+ - Focuses more on reasoning than citation capabilities
33
+ - Excellent for research applications and technical documentation
34
+
35
+ ### 3. Mistral-8x22b
36
+ **Key Strengths:**
37
+ - Strong capabilities in mathematics and coding
38
+ - 64K token context window
39
+ - Function calling: Natively capable of function calling
40
+ - Multilingual: Fluent in English, French, Italian, German, and Spanish
41
+ - Good for complex problem-solving tasks
42
+
43
+ **Considerations:**
44
+ - Smaller context window than some alternatives
45
+ - Less emphasis on citation capabilities
46
+
47
+ ### 4. Google Gemma 2
48
+ **Key Strengths:**
49
+ - Specifically designed for researchers and developers
50
+ - Available in 9B and 27B parameter sizes
51
+ - 8K token context window
52
+ - Efficient inference on consumer hardware
53
+ - Compatible with major AI frameworks
54
+
55
+ **Considerations:**
56
+ - Smaller context window
57
+ - Less emphasis on citation capabilities
58
+
59
+ ### 5. LLaMA 3
60
+ **Key Strengths:**
61
+ - Optimized for dialogue use cases
62
+ - 128K token context window
63
+ - Multilingual capabilities
64
+ - Well-documented with extensive community support
65
+ - Strong general knowledge base
66
+
67
+ **Considerations:**
68
+ - Less specialized for academic research
69
+ - Citation capabilities not highlighted
70
+
71
+ ## Recommendation
72
+
73
+ **Command R+** appears to be the most suitable open-source LLM for the educational research methods chatbot due to:
74
+
75
+ 1. **Citation capabilities**: Its retrieval augmented generation functionality directly addresses the requirement for APA7 citations from scientific resources.
76
+
77
+ 2. **Large context window**: The 128K token context window allows for processing extensive research methodology documents and academic papers.
78
+
79
+ 3. **Multi-step tool use**: This capability enables integration with external databases of research methods and academic papers.
80
+
81
+ 4. **Reasoning abilities**: Strong reasoning capabilities are essential for understanding and recommending appropriate research methods based on user queries.
82
+
83
+ While DeepSeek R1 is also a strong contender with excellent reasoning capabilities and scientific domain knowledge, Command R+'s specific citation functionality gives it the edge for this particular application.
84
+
85
+ ## Implementation Considerations
86
+
87
+ - The chatbot will need to be integrated with a database or knowledge base of educational research methods
88
+ - RAG implementation will require a vector database for efficient retrieval
89
+ - APA7 citation formatting will need to be implemented as part of the response generation pipeline
90
+ - The web interface should allow for uploading or referencing specific research papers
main.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI, HTTPException, Request, Response
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ import uvicorn
6
+
7
+ # Import the app from app.py
8
+ from app import app as api_app
9
+
10
+ # Create a new FastAPI app for serving both API and static files
11
+ app = FastAPI(title="Educational Research Methods Chatbot")
12
+
13
+ # Add CORS middleware
14
+ app.add_middleware(
15
+ CORSMiddleware,
16
+ allow_origins=["*"], # In production, replace with specific origins
17
+ allow_credentials=True,
18
+ allow_methods=["*"],
19
+ allow_headers=["*"],
20
+ )
21
+
22
+ # Mount the API app
23
+ app.mount("/api", api_app)
24
+
25
+ # Mount static files
26
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
27
+
28
+ if __name__ == "__main__":
29
+ # Get port from environment variable for cloud deployment
30
+ port = int(os.environ.get("PORT", 8080))
31
+ host = os.environ.get("HOST", "0.0.0.0")
32
+
33
+ uvicorn.run(app, host=host, port=port)
netlify.toml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Netlify Configuration File
2
+
3
+ # Build settings
4
+ [build]
5
+ # Directory to publish
6
+ publish = "src/static"
7
+ # Command to run before deployment
8
+ command = "echo 'Static site ready for deployment'"
9
+
10
+ # Redirects and headers
11
+ [[redirects]]
12
+ from = "/api/*"
13
+ to = "/.netlify/functions/:splat"
14
+ status = 200
15
+
16
+ # Environment variables
17
+ [build.environment]
18
+ NODE_VERSION = "16"
19
+
20
+ # Functions directory
21
+ [functions]
22
+ directory = "netlify/functions"
netlify_deployment_steps.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Netlify Deployment Steps
2
+
3
+ This document outlines the steps to deploy the Educational Research Methods Chatbot to Netlify.
4
+
5
+ ## Prerequisites
6
+
7
+ - Netlify account
8
+ - GitHub account (optional, for continuous deployment)
9
+ - OpenAI API key for Command R+
10
+
11
+ ## Deployment Steps
12
+
13
+ 1. **Prepare the repository**
14
+ - Ensure all files are properly organized
15
+ - Static files in `src/static`
16
+ - Netlify functions in `deployment/netlify/functions`
17
+ - Netlify configuration in `deployment/netlify.toml`
18
+
19
+ 2. **Create a new Netlify site**
20
+ - Log in to Netlify
21
+ - Click "New site from Git" or "Import an existing project"
22
+ - Connect to your Git provider (GitHub, GitLab, Bitbucket)
23
+ - Select the repository
24
+
25
+ 3. **Configure build settings**
26
+ - Build command: `cp -r deployment/netlify/functions netlify/functions && cp deployment/netlify.toml netlify.toml`
27
+ - Publish directory: `src/static`
28
+
29
+ 4. **Set environment variables**
30
+ - Go to Site settings > Build & deploy > Environment
31
+ - Add the following environment variables:
32
+ - `OPENAI_API_KEY`: Your OpenAI API key
33
+
34
+ 5. **Deploy the site**
35
+ - Click "Deploy site"
36
+ - Wait for the build and deployment to complete
37
+
38
+ 6. **Configure custom domain (optional)**
39
+ - Go to Site settings > Domain management
40
+ - Click "Add custom domain"
41
+ - Follow the instructions to set up your domain
42
+
43
+ ## Post-Deployment
44
+
45
+ 1. **Verify functionality**
46
+ - Test the chatbot by asking various questions
47
+ - Ensure responses include proper citations
48
+ - Test conversation context maintenance
49
+
50
+ 2. **Monitor usage**
51
+ - Check Netlify function logs for errors
52
+ - Monitor OpenAI API usage
53
+
54
+ 3. **Update as needed**
55
+ - Push changes to your Git repository for automatic deployment
56
+ - Or manually deploy updates through the Netlify dashboard
package.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "research-methods-chatbot-functions",
3
+ "version": "1.0.0",
4
+ "description": "Serverless functions for the Educational Research Methods Chatbot using Mistral",
5
+ "main": "chat-mistral.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "dependencies": {
10
+ "node-fetch": "^2.6.7"
11
+ }
12
+ }
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn==0.24.0
3
+ langchain==0.0.335
4
+ chromadb==0.4.18
5
+ openai==1.3.5
6
+ python-dotenv==1.0.0
7
+ pydantic==2.4.2
8
+ tiktoken==0.5.1
9
+ pypdf==3.17.1
10
+ python-multipart==0.0.6
research_methods_chatbot.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b008aa20e7f558ee826036d88f5f2cf2e0bba49b9c3116150106ad6a16b487e2
3
+ size 21268
research_methods_info.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods
2
+
3
+ This document provides a comprehensive overview of educational research methods for the research methods chatbot knowledge base. The information is organized by research methodology type with APA7 citations.
4
+
5
+ ## Overview of Research Methods in Education
6
+
7
+ Educational research methods are systematic approaches used to investigate educational phenomena, assess problems in policy, practices, and curriculum design, and help administrators identify solutions. Research in education can be broadly categorized into three methodological approaches: qualitative, quantitative, and mixed methods.
8
+
9
+ ## Qualitative Research Methods
10
+
11
+ Qualitative research focuses on thoughts, concepts, or experiences. The data collected often comes in narrative form and concentrates on unearthing insights that can lead to testable hypotheses (American University, 2020).
12
+
13
+ ### Key Characteristics of Qualitative Research
14
+
15
+ - Explores thoughts, concepts, or experiences
16
+ - Collects data in narrative form
17
+ - Used to generate hypotheses
18
+ - Focuses on unearthing insights
19
+ - Often used in exploratory stages of research
20
+
21
+ ### Common Qualitative Research Methods
22
+
23
+ 1. **Case Studies**: In-depth investigations into an individual, group, event, or community, typically gathering data through observation and interviews.
24
+
25
+ 2. **Focus Groups**: A moderator (or researcher) guides conversation around a specific topic among a group of participants.
26
+
27
+ 3. **Ethnography**: Researchers interact with and observe a specific societal or ethnic group in their real-life environment.
28
+
29
+ 4. **Interviews**: Researchers ask participants open-ended questions to learn about their perspectives on a particular subject.
30
+
31
+ 5. **Content Analysis**: Systematic analysis of texts, images, or other forms of communication.
32
+
33
+ 6. **Phenomenology**: Study of individuals' lived experiences and their interpretations of those experiences.
34
+
35
+ 7. **Grounded Theory**: Development of theory through systematic collection and analysis of data.
36
+
37
+ ### When to Use Qualitative Research
38
+
39
+ Qualitative research is particularly useful when:
40
+ - The research is in early stages and requires more exploration to find a testable hypothesis
41
+ - The goal is to understand complex phenomena in depth
42
+ - The research aims to explore participants' experiences, perspectives, or meanings
43
+ - The study seeks to identify patterns or generate new theories
44
+
45
+ ## Quantitative Research Methods
46
+
47
+ Quantitative research in education is expressed in numbers and measurements. This type of research aims to find data to confirm or test a hypothesis (American University, 2020).
48
+
49
+ ### Key Characteristics of Quantitative Research
50
+
51
+ - Expressed in numbers and measurements
52
+ - Tests or confirms hypotheses
53
+ - Provides numerical data that can prove or disprove a theory
54
+ - Results can be scaled to predict outcomes in larger populations
55
+ - Often used in later stages of research
56
+
57
+ ### Common Quantitative Research Methods
58
+
59
+ 1. **Questionnaires and Surveys**: Participants receive a list of questions, either closed-ended or multiple choice, which are directed around a particular topic.
60
+
61
+ 2. **Experiments**: Researchers control and test variables to demonstrate cause-and-effect relationships.
62
+
63
+ 3. **Observations**: Researchers look at quantifiable patterns and behavior.
64
+
65
+ 4. **Structured Interviews**: Using a predetermined structure, researchers ask participants a fixed set of questions to acquire numerical data.
66
+
67
+ 5. **Correlational Research**: Examines relationships between variables without manipulating them.
68
+
69
+ 6. **Causal-Comparative Research**: Compares groups that differ on a variable to determine if this difference affects another variable.
70
+
71
+ 7. **Longitudinal Studies**: Collection of data at different points in time to study changes over time.
72
+
73
+ ### When to Use Quantitative Research
74
+
75
+ Quantitative research is particularly useful when:
76
+ - The research has established a clear hypothesis to test
77
+ - The goal is to measure specific variables
78
+ - The research aims to establish cause-and-effect relationships
79
+ - The study seeks to generalize findings to a larger population
80
+ - The research requires statistical analysis to validate findings
81
+
82
+ ## Mixed Methods Research
83
+
84
+ Mixed methods research combines the elements of two types of research: quantitative and qualitative. By blending both quantitative and qualitative data, mixed methods research allows for a more thorough exploration of a research question (Dovetail, 2023).
85
+
86
+ ### Key Characteristics of Mixed Methods Research
87
+
88
+ - Combines elements of qualitative and quantitative research
89
+ - Allows for more thorough exploration of research questions
90
+ - Can answer complex research queries that cannot be solved with either method alone
91
+ - Integrates data from both sources to provide comprehensive insights
92
+ - Offers method flexibility
93
+
94
+ ### Types of Mixed Methods Research Designs
95
+
96
+ 1. **Convergent Parallel Design**: Data collection and analysis of both quantitative and qualitative data occur simultaneously and are analyzed separately. This design aims to create mutually exclusive sets of data that inform each other.
97
+
98
+ 2. **Embedded Design**: The quantitative and qualitative data are collected simultaneously, but the qualitative data is embedded within the quantitative data. This design is best used when you want to focus on the quantitative data but still need to understand how the qualitative data further explains it.
99
+
100
+ 3. **Explanatory Sequential Design**: Quantitative data is collected first, followed by qualitative data. This design is used when you want to further explain a set of quantitative data with additional qualitative information.
101
+
102
+ 4. **Exploratory Sequential Design**: Qualitative data is collected first, followed by quantitative data. This type of mixed methods research is used when the goal is to explore a topic before collecting any quantitative data.
103
+
104
+ ### When to Use Mixed Methods Research
105
+
106
+ Mixed methods research is particularly useful when:
107
+ - The research question is complex and requires multiple perspectives
108
+ - Neither qualitative nor quantitative data alone will sufficiently answer the research question
109
+ - The goal is to both explore and confirm findings
110
+ - The research aims to provide a more comprehensive understanding of the phenomenon
111
+ - The study seeks to triangulate findings through different methods
112
+
113
+ ## Choosing the Appropriate Research Method
114
+
115
+ When choosing which research strategy to employ for a project or study, several considerations apply:
116
+
117
+ 1. **Research Phase**: If a project is in its early stages and requires more research to find a testable hypothesis, qualitative research methods might prove most helpful. If the research team has already established a hypothesis or theory, quantitative research methods will provide data that can validate the theory or refine it for further testing.
118
+
119
+ 2. **Research Goals**: Consider whether the goal is to explore and understand a phenomenon (qualitative), measure and test relationships (quantitative), or both (mixed methods).
120
+
121
+ 3. **Available Resources**: Consider time, budget, and expertise constraints when selecting a research method.
122
+
123
+ 4. **Nature of the Research Question**: Some questions are better suited to specific methodologies based on what they aim to discover.
124
+
125
+ 5. **Intended Audience**: Consider who will be using the research findings and what type of data they find most compelling.
126
+
127
+ ## References
128
+
129
+ American University. (2020, July 23). Qualitative vs. quantitative research: Comparing the methods and strategies for education research. https://soeonline.american.edu/blog/qualitative-vs-quantitative/
130
+
131
+ Dovetail. (2023, February 20). Mixed methods research guide with examples. https://dovetail.com/research/mixed-methods-research/
run_tests.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Run all tests for the Educational Research Methods Chatbot
4
+
5
+ echo "Running Educational Research Methods Chatbot Tests"
6
+ echo "=================================================="
7
+
8
+ # Create a virtual environment if it doesn't exist
9
+ if [ ! -d "venv" ]; then
10
+ echo "Creating virtual environment..."
11
+ python3 -m venv venv
12
+ fi
13
+
14
+ # Activate the virtual environment
15
+ source venv/bin/activate
16
+
17
+ # Install requirements
18
+ echo "Installing requirements..."
19
+ pip install -r src/requirements.txt
20
+ pip install pytest pytest-mock
21
+
22
+ # Run the tests
23
+ echo "Running backend API tests..."
24
+ python -m pytest tests/test_chatbot.py -v
25
+
26
+ echo "Running frontend tests..."
27
+ python -m pytest tests/test_frontend.py -v
28
+
29
+ echo "Running integration tests..."
30
+ python -m pytest tests/test_integration.py -v
31
+
32
+ echo "All tests completed."
33
+
34
+ # Deactivate the virtual environment
35
+ deactivate
test_chatbot.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ import sys
4
+ import os
5
+ import json
6
+
7
+ # Add the src directory to the path
8
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
9
+
10
+ # Import the app
11
+ from app import app, ChatRequest, ChatResponse
12
+
13
+ class TestChatbotAPI(unittest.TestCase):
14
+
15
+ @patch('app.qa_chain')
16
+ def test_basic_query_response(self, mock_qa_chain):
17
+ # Mock the QA chain response
18
+ mock_qa_chain.return_value = {
19
+ "query": "What is qualitative research?",
20
+ "result": "Qualitative research focuses on thoughts, concepts, or experiences. The data collected often comes in narrative form and concentrates on unearthing insights that can lead to testable hypotheses.",
21
+ "source_documents": [
22
+ MagicMock(
23
+ page_content="Qualitative research focuses on thoughts, concepts, or experiences. The data collected often comes in narrative form and concentrates on unearthing insights that can lead to testable hypotheses.",
24
+ metadata={"source": "American University. (2020, July 23). Qualitative vs. quantitative research: Comparing the methods and strategies for education research.", "page": "1"}
25
+ )
26
+ ]
27
+ }
28
+
29
+ # Create a test request
30
+ request = ChatRequest(
31
+ message="What is qualitative research?",
32
+ conversation_history=[]
33
+ )
34
+
35
+ # Call the chat endpoint
36
+ response = app.chat(request)
37
+
38
+ # Assert the response
39
+ self.assertIsInstance(response, ChatResponse)
40
+ self.assertIn("Qualitative research focuses on", response.response)
41
+ self.assertEqual(len(response.citations), 1)
42
+ self.assertEqual(response.citations[0]["text"], "American University. (2020, July 23). Qualitative vs. quantitative research: Comparing the methods and strategies for education research.")
43
+
44
+ @patch('app.qa_chain')
45
+ def test_method_recommendation(self, mock_qa_chain):
46
+ # Mock the QA chain response
47
+ mock_qa_chain.return_value = {
48
+ "query": "Which research method should I use to study student engagement in online learning?",
49
+ "result": "For studying student engagement in online learning, a mixed methods approach would be most appropriate. This would allow you to collect both quantitative data (such as participation metrics, time spent on tasks) and qualitative data (such as student experiences and perceptions).",
50
+ "source_documents": [
51
+ MagicMock(
52
+ page_content="Mixed methods research combines the elements of two types of research: quantitative and qualitative. By blending both quantitative and qualitative data, mixed methods research allows for a more thorough exploration of a research question.",
53
+ metadata={"source": "Dovetail. (2023, February 20). Mixed methods research guide with examples.", "page": "1"}
54
+ )
55
+ ]
56
+ }
57
+
58
+ # Create a test request
59
+ request = ChatRequest(
60
+ message="Which research method should I use to study student engagement in online learning?",
61
+ conversation_history=[]
62
+ )
63
+
64
+ # Call the chat endpoint
65
+ response = app.chat(request)
66
+
67
+ # Assert the response
68
+ self.assertIsInstance(response, ChatResponse)
69
+ self.assertIn("mixed methods approach", response.response.lower())
70
+ self.assertEqual(len(response.citations), 1)
71
+ self.assertEqual(response.citations[0]["text"], "Dovetail. (2023, February 20). Mixed methods research guide with examples.")
72
+
73
+ @patch('app.qa_chain')
74
+ def test_comparison_query(self, mock_qa_chain):
75
+ # Mock the QA chain response
76
+ mock_qa_chain.return_value = {
77
+ "query": "What are the differences between qualitative and quantitative research methods?",
78
+ "result": "Qualitative research focuses on thoughts, concepts, or experiences, with data collected in narrative form. Quantitative research is expressed in numbers and measurements, aiming to find data to confirm or test a hypothesis.",
79
+ "source_documents": [
80
+ MagicMock(
81
+ page_content="Qualitative research focuses on thoughts, concepts, or experiences. The data collected often comes in narrative form.",
82
+ metadata={"source": "American University. (2020, July 23). Qualitative vs. quantitative research: Comparing the methods and strategies for education research.", "page": "1"}
83
+ ),
84
+ MagicMock(
85
+ page_content="Quantitative research in education is expressed in numbers and measurements. This type of research aims to find data to confirm or test a hypothesis.",
86
+ metadata={"source": "American University. (2020, July 23). Qualitative vs. quantitative research: Comparing the methods and strategies for education research.", "page": "2"}
87
+ )
88
+ ]
89
+ }
90
+
91
+ # Create a test request
92
+ request = ChatRequest(
93
+ message="What are the differences between qualitative and quantitative research methods?",
94
+ conversation_history=[]
95
+ )
96
+
97
+ # Call the chat endpoint
98
+ response = app.chat(request)
99
+
100
+ # Assert the response
101
+ self.assertIsInstance(response, ChatResponse)
102
+ self.assertIn("Qualitative research focuses on", response.response)
103
+ self.assertIn("Quantitative research is expressed in", response.response)
104
+ self.assertEqual(len(response.citations), 2)
105
+
106
+ @patch('app.qa_chain')
107
+ def test_follow_up_question(self, mock_qa_chain):
108
+ # Mock the QA chain response
109
+ mock_qa_chain.return_value = {
110
+ "query": "Conversation history:\nUser: Tell me about mixed methods research\nAssistant: Mixed methods research combines the elements of two types of research: quantitative and qualitative. By blending both quantitative and qualitative data, mixed methods research allows for a more thorough exploration of a research question.\n\nCurrent question: What are the different types of mixed methods designs?",
111
+ "result": "There are four main types of mixed methods designs: 1) Convergent parallel design, 2) Embedded design, 3) Explanatory sequential design, and 4) Exploratory sequential design.",
112
+ "source_documents": [
113
+ MagicMock(
114
+ page_content="Designing a mixed methods study can be broken down into four types: convergent parallel, embedded, explanatory sequential, and exploratory sequential.",
115
+ metadata={"source": "Dovetail. (2023, February 20). Mixed methods research guide with examples.", "page": "3"}
116
+ )
117
+ ]
118
+ }
119
+
120
+ # Create a test request with conversation history
121
+ request = ChatRequest(
122
+ message="What are the different types of mixed methods designs?",
123
+ conversation_history=[
124
+ {
125
+ "message": "Tell me about mixed methods research",
126
+ "response": "Mixed methods research combines the elements of two types of research: quantitative and qualitative. By blending both quantitative and qualitative data, mixed methods research allows for a more thorough exploration of a research question."
127
+ }
128
+ ]
129
+ )
130
+
131
+ # Call the chat endpoint
132
+ response = app.chat(request)
133
+
134
+ # Assert the response
135
+ self.assertIsInstance(response, ChatResponse)
136
+ self.assertIn("four main types", response.response.lower())
137
+ self.assertEqual(len(response.citations), 1)
138
+
139
+ @patch('app.qa_chain')
140
+ def test_empty_input(self, mock_qa_chain):
141
+ # Create a test request with empty message
142
+ request = ChatRequest(
143
+ message="",
144
+ conversation_history=[]
145
+ )
146
+
147
+ # Call the chat endpoint and expect an exception
148
+ with self.assertRaises(Exception):
149
+ app.chat(request)
150
+
151
+ if __name__ == '__main__':
152
+ unittest.main()
test_frontend.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ import sys
4
+ import os
5
+
6
+ # Add the src directory to the path
7
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
8
+
9
+ # Import the frontend components
10
+ class TestChatbotFrontend(unittest.TestCase):
11
+
12
+ def test_html_structure(self):
13
+ """Test that the HTML file exists and has the expected structure"""
14
+ html_path = os.path.join(os.path.dirname(__file__), '..', 'src', 'static', 'index.html')
15
+ self.assertTrue(os.path.exists(html_path), "Frontend HTML file should exist")
16
+
17
+ with open(html_path, 'r') as f:
18
+ content = f.read()
19
+
20
+ # Check for essential elements
21
+ self.assertIn('<html', content, "Should have HTML tag")
22
+ self.assertIn('<head', content, "Should have head section")
23
+ self.assertIn('<body', content, "Should have body section")
24
+ self.assertIn('chat-container', content, "Should have chat container")
25
+ self.assertIn('chat-messages', content, "Should have messages container")
26
+ self.assertIn('user-input', content, "Should have user input field")
27
+ self.assertIn('send-button', content, "Should have send button")
28
+
29
+ # Check for citation display
30
+ self.assertIn('citation', content, "Should have citation styling")
31
+
32
+ # Check for responsive design
33
+ self.assertIn('viewport', content, "Should have viewport meta tag for responsiveness")
34
+
35
+ # Check for JavaScript functionality
36
+ self.assertIn('addEventListener', content, "Should have event listeners")
37
+ self.assertIn('fetch', content, "Should have API fetch functionality")
38
+ self.assertIn('conversation_history', content, "Should track conversation history")
39
+
40
+ if __name__ == '__main__':
41
+ unittest.main()
test_integration.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ import sys
4
+ import os
5
+
6
+ # Add the src directory to the path
7
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
8
+
9
+ class TestChatbotIntegration(unittest.TestCase):
10
+
11
+ @patch('app.initialize_rag')
12
+ def test_rag_initialization(self, mock_initialize_rag):
13
+ """Test that the RAG pipeline initializes correctly"""
14
+ # Mock the RAG initialization
15
+ mock_qa = MagicMock()
16
+ mock_initialize_rag.return_value = mock_qa
17
+
18
+ # Import app after mocking
19
+ from app import qa_chain
20
+
21
+ # Assert that initialize_rag was called
22
+ mock_initialize_rag.assert_called_once()
23
+
24
+ # Assert that qa_chain is set to the return value of initialize_rag
25
+ self.assertEqual(qa_chain, mock_qa)
26
+
27
+ def test_research_methods_info_exists(self):
28
+ """Test that the research methods info file exists"""
29
+ info_path = os.path.join(os.path.dirname(__file__), '..', 'research_methods_info.md')
30
+ self.assertTrue(os.path.exists(info_path), "Research methods info file should exist")
31
+
32
+ with open(info_path, 'r') as f:
33
+ content = f.read()
34
+
35
+ # Check for essential content
36
+ self.assertIn('Qualitative Research Methods', content)
37
+ self.assertIn('Quantitative Research Methods', content)
38
+ self.assertIn('Mixed Methods Research', content)
39
+ self.assertIn('APA7', content)
40
+
41
+ def test_static_files_serving(self):
42
+ """Test that the static files are properly configured"""
43
+ from main import app
44
+
45
+ # Check that the static files are mounted
46
+ static_routes = [route for route in app.routes if getattr(route, 'path', '') == '/']
47
+ self.assertTrue(len(static_routes) > 0, "Static files should be mounted")
48
+
49
+ def test_api_mounting(self):
50
+ """Test that the API is properly mounted"""
51
+ from main import app
52
+
53
+ # Check that the API is mounted
54
+ api_routes = [route for route in app.routes if getattr(route, 'path', '') == '/api']
55
+ self.assertTrue(len(api_routes) > 0, "API should be mounted")
56
+
57
+ if __name__ == '__main__':
58
+ unittest.main()
test_manual.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ import sys
4
+ import os
5
+ import json
6
+
7
+ # Add the src directory to the path
8
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
9
+
10
+ class TestChatbotManualTests(unittest.TestCase):
11
+ """
12
+ This class contains test cases that should be run manually to verify the chatbot's functionality.
13
+ These tests are designed to be run with a human evaluator who can assess the quality of responses.
14
+ """
15
+
16
+ def test_qualitative_research_query(self):
17
+ """
18
+ Test query: "What is qualitative research?"
19
+
20
+ Expected response should:
21
+ 1. Provide a clear definition of qualitative research
22
+ 2. Include key characteristics
23
+ 3. Provide APA7 citation
24
+ 4. Be relevant to educational research context
25
+
26
+ Manual verification required.
27
+ """
28
+ print("\nManual Test 1: What is qualitative research?")
29
+ print("Expected: Definition, characteristics, and APA7 citation")
30
+ print("Verify that the response is accurate and properly cited")
31
+
32
+ def test_method_selection_query(self):
33
+ """
34
+ Test query: "I want to study the impact of technology on student learning outcomes.
35
+ Which research method would be most appropriate?"
36
+
37
+ Expected response should:
38
+ 1. Recommend appropriate research method(s)
39
+ 2. Provide rationale for the recommendation
40
+ 3. Include APA7 citation
41
+ 4. Consider both qualitative and quantitative aspects
42
+
43
+ Manual verification required.
44
+ """
45
+ print("\nManual Test 2: I want to study the impact of technology on student learning outcomes. Which research method would be most appropriate?")
46
+ print("Expected: Method recommendation with rationale and APA7 citation")
47
+ print("Verify that the recommendation is appropriate and well-justified")
48
+
49
+ def test_mixed_methods_query(self):
50
+ """
51
+ Test query: "What are the advantages and disadvantages of mixed methods research in education?"
52
+
53
+ Expected response should:
54
+ 1. List advantages of mixed methods
55
+ 2. List disadvantages or challenges
56
+ 3. Provide context specific to educational research
57
+ 4. Include APA7 citation
58
+
59
+ Manual verification required.
60
+ """
61
+ print("\nManual Test 3: What are the advantages and disadvantages of mixed methods research in education?")
62
+ print("Expected: Pros and cons with educational context and APA7 citation")
63
+ print("Verify that the response is balanced and comprehensive")
64
+
65
+ def test_follow_up_query(self):
66
+ """
67
+ Test sequence:
68
+ 1. "What is a case study in educational research?"
69
+ 2. "What are the limitations of this method?"
70
+
71
+ Expected response to follow-up should:
72
+ 1. Understand "this method" refers to case studies
73
+ 2. List specific limitations of case studies
74
+ 3. Maintain context from previous question
75
+ 4. Include APA7 citation
76
+
77
+ Manual verification required.
78
+ """
79
+ print("\nManual Test 4: Two-part conversation")
80
+ print("First query: What is a case study in educational research?")
81
+ print("Follow-up: What are the limitations of this method?")
82
+ print("Expected: Response should understand the context and provide limitations with citation")
83
+ print("Verify that the chatbot maintains conversation context")
84
+
85
+ def test_complex_query(self):
86
+ """
87
+ Test query: "I'm conducting research on teacher professional development.
88
+ I want to measure both the effectiveness of the program and understand
89
+ teachers' experiences. What research design would you recommend?"
90
+
91
+ Expected response should:
92
+ 1. Recognize the need for both quantitative and qualitative approaches
93
+ 2. Recommend a specific mixed methods design
94
+ 3. Explain how to implement the design
95
+ 4. Include APA7 citation
96
+
97
+ Manual verification required.
98
+ """
99
+ print("\nManual Test 5: I'm conducting research on teacher professional development. I want to measure both the effectiveness of the program and understand teachers' experiences. What research design would you recommend?")
100
+ print("Expected: Detailed mixed methods recommendation with implementation guidance and citation")
101
+ print("Verify that the response addresses both quantitative and qualitative aspects")
102
+
103
+ if __name__ == '__main__':
104
+ unittest.main()
test_plan.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Test Plan for Educational Research Methods Chatbot
2
+
3
+ ## Overview
4
+ This document outlines the testing approach for the Educational Research Methods Chatbot to ensure it meets the requirements and functions correctly.
5
+
6
+ ## Test Environment
7
+ - Local development environment
8
+ - Python 3.8+
9
+ - Modern web browser (Chrome, Firefox, Safari)
10
+
11
+ ## Test Categories
12
+
13
+ ### 1. Functional Testing
14
+
15
+ #### 1.1 Basic Functionality
16
+ - [ ] Verify the chatbot starts up correctly
17
+ - [ ] Confirm the web interface loads properly
18
+ - [ ] Test that user can input messages
19
+ - [ ] Verify chatbot responds to user inputs
20
+
21
+ #### 1.2 Research Methods Knowledge
22
+ - [ ] Test queries about qualitative research methods
23
+ - [ ] Test queries about quantitative research methods
24
+ - [ ] Test queries about mixed methods research
25
+ - [ ] Verify accuracy of research method recommendations
26
+ - [ ] Test complex queries requiring understanding of multiple research methods
27
+
28
+ #### 1.3 Citation Functionality
29
+ - [ ] Verify responses include APA7 citations
30
+ - [ ] Check citation format accuracy
31
+ - [ ] Confirm citations reference actual sources
32
+ - [ ] Test citation display in the UI
33
+
34
+ #### 1.4 Conversation Flow
35
+ - [ ] Test multi-turn conversations
36
+ - [ ] Verify context is maintained across multiple queries
37
+ - [ ] Test handling of follow-up questions
38
+ - [ ] Check conversation history functionality
39
+
40
+ ### 2. Non-Functional Testing
41
+
42
+ #### 2.1 Performance
43
+ - [ ] Measure response time for simple queries
44
+ - [ ] Measure response time for complex queries
45
+ - [ ] Test system under multiple concurrent users (if applicable)
46
+
47
+ #### 2.2 Usability
48
+ - [ ] Verify responsive design on different screen sizes
49
+ - [ ] Test accessibility features
50
+ - [ ] Check UI/UX for intuitiveness
51
+ - [ ] Verify error messages are clear and helpful
52
+
53
+ #### 2.3 Error Handling
54
+ - [ ] Test with malformed queries
55
+ - [ ] Test with empty inputs
56
+ - [ ] Verify system handles API failures gracefully
57
+ - [ ] Test recovery from connection issues
58
+
59
+ ## Test Cases
60
+
61
+ ### Test Case 1: Basic Query Response
62
+ 1. Input: "What is qualitative research?"
63
+ 2. Expected: Accurate definition with APA7 citation
64
+ 3. Verification: Check response content and citation format
65
+
66
+ ### Test Case 2: Method Recommendation
67
+ 1. Input: "Which research method should I use to study student engagement in online learning?"
68
+ 2. Expected: Recommendation with rationale and citations
69
+ 3. Verification: Check appropriateness of recommendation and citation accuracy
70
+
71
+ ### Test Case 3: Comparison Query
72
+ 1. Input: "What are the differences between qualitative and quantitative research methods?"
73
+ 2. Expected: Comprehensive comparison with examples and citations
74
+ 3. Verification: Check completeness and accuracy of comparison
75
+
76
+ ### Test Case 4: Follow-up Question
77
+ 1. Input: "Tell me about mixed methods research"
78
+ 2. Follow-up: "What are the different types of mixed methods designs?"
79
+ 3. Expected: Contextually aware response to follow-up
80
+ 4. Verification: Check if context is maintained
81
+
82
+ ### Test Case 5: Citation Accuracy
83
+ 1. Input: "What does the literature say about case studies in educational research?"
84
+ 2. Expected: Response with multiple citations from educational research literature
85
+ 3. Verification: Check if citations follow APA7 format and are from valid sources
86
+
87
+ ### Test Case 6: Error Handling
88
+ 1. Input: [Empty message]
89
+ 2. Expected: Appropriate error message or prompt
90
+ 3. Verification: Check if system handles empty input gracefully
91
+
92
+ ## Test Results Documentation
93
+
94
+ For each test case, document:
95
+ 1. Test case ID and description
96
+ 2. Test input
97
+ 3. Expected output
98
+ 4. Actual output
99
+ 5. Pass/Fail status
100
+ 6. Notes or observations
101
+
102
+ ## Regression Testing
103
+ After fixing any issues, rerun relevant test cases to ensure:
104
+ - The issue is resolved
105
+ - No new issues were introduced
106
+
107
+ ## Final Acceptance Criteria
108
+ - All test cases pass
109
+ - Response accuracy meets or exceeds 90%
110
+ - Citation format is 100% compliant with APA7
111
+ - UI is responsive and user-friendly
112
+ - System handles errors gracefully
todo.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Research Methods Chatbot Project
2
+
3
+ ## Requirements
4
+ - [x] Clarify user requirements
5
+ - [x] Focus on educational research methods
6
+ - [x] Target audience: experienced academics
7
+ - [x] Web-based interface
8
+ - [x] Include APA7 citations from published scientific resources
9
+ - [x] No specific deployment constraints
10
+
11
+ ## Research and Planning
12
+ - [x] Research open-source LLMs
13
+ - [x] Identify suitable open-source LLMs for research methods domain
14
+ - [x] Compare capabilities, limitations, and requirements
15
+ - [x] Document findings
16
+ - [x] Select appropriate LLM
17
+ - [x] Evaluate models based on educational research knowledge
18
+ - [x] Consider resource requirements and deployment options
19
+ - [x] Make final selection with justification
20
+ - [x] Gather research methods information
21
+ - [x] Compile educational research methods information
22
+ - [x] Organize information for chatbot knowledge base
23
+ - [x] Include sources for APA7 citations
24
+
25
+ ## Implementation
26
+ - [x] Design chatbot architecture
27
+ - [x] Create system design document
28
+ - [x] Define components and interactions
29
+ - [x] Plan web interface design
30
+ - [x] Implement chatbot code
31
+ - [x] Set up development environment
32
+ - [x] Implement backend with selected LLM
33
+ - [x] Create web-based frontend
34
+ - [x] Integrate citation functionality
35
+ - [x] Test chatbot functionality
36
+ - [x] Verify accuracy of research method recommendations
37
+ - [x] Test citation format and accuracy
38
+ - [x] Ensure proper handling of various query types
39
+
40
+ ## Delivery
41
+ - [x] Deliver final product
42
+ - [x] Package code and documentation
43
+ - [ ] Provide deployment instructions
44
+ - [ ] Demonstrate functionality
user_guide.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Educational Research Methods Chatbot - User Guide
2
+
3
+ ## Introduction
4
+
5
+ The Educational Research Methods Chatbot is designed to assist experienced academics in choosing appropriate research methods for educational research. The chatbot provides recommendations based on comprehensive knowledge of qualitative, quantitative, and mixed methods research approaches, with proper APA7 citations from published scientific resources.
6
+
7
+ ## Features
8
+
9
+ - **Research Method Recommendations**: Get expert advice on which research methods are most appropriate for your specific educational research questions and contexts.
10
+ - **APA7 Citations**: All information is provided with proper APA7 citations from reputable published scientific resources.
11
+ - **Conversation Context**: The chatbot maintains context throughout your conversation for more coherent multi-turn interactions.
12
+ - **Web-based Interface**: Access the chatbot through a user-friendly web interface that works on both desktop and mobile devices.
13
+
14
+ ## Getting Started
15
+
16
+ ### Prerequisites
17
+
18
+ - Python 3.8 or higher
19
+ - pip (Python package installer)
20
+ - An OpenAI API key for Command R+ access
21
+
22
+ ### Installation
23
+
24
+ 1. Unzip the `research_methods_chatbot.zip` file to your desired location.
25
+
26
+ 2. Navigate to the project directory:
27
+ ```
28
+ cd research_methods_chatbot
29
+ ```
30
+
31
+ 3. Install the required dependencies:
32
+ ```
33
+ pip install -r src/requirements.txt
34
+ ```
35
+
36
+ 4. Create a `.env` file in the `src` directory with your OpenAI API key:
37
+ ```
38
+ OPENAI_API_KEY=your_api_key_here
39
+ ```
40
+
41
+ ### Running the Chatbot
42
+
43
+ 1. Start the application:
44
+ ```
45
+ cd src
46
+ python main.py
47
+ ```
48
+
49
+ 2. Open your web browser and navigate to:
50
+ ```
51
+ http://localhost:8080
52
+ ```
53
+
54
+ 3. You should see the chatbot interface where you can ask questions about educational research methods.
55
+
56
+ ## Using the Chatbot
57
+
58
+ ### Example Questions
59
+
60
+ Here are some example questions you can ask the chatbot:
61
+
62
+ - "What is qualitative research?"
63
+ - "What are the differences between qualitative and quantitative research methods?"
64
+ - "When should I use mixed methods research in educational studies?"
65
+ - "I want to study the impact of technology on student learning outcomes. Which research method would be most appropriate?"
66
+ - "What are the advantages and disadvantages of case studies in educational research?"
67
+ - "How do I design a sequential explanatory mixed methods study?"
68
+
69
+ ### Multi-turn Conversations
70
+
71
+ The chatbot maintains context throughout your conversation, allowing you to ask follow-up questions. For example:
72
+
73
+ 1. "What is a case study in educational research?"
74
+ 2. "What are the limitations of this method?"
75
+
76
+ The chatbot will understand that "this method" refers to case studies from your previous question.
77
+
78
+ ## Architecture
79
+
80
+ The chatbot uses a Retrieval Augmented Generation (RAG) architecture with the following components:
81
+
82
+ 1. **Command R+ LLM**: Powers the natural language understanding and generation.
83
+ 2. **Vector Database**: Stores embeddings of research methods information for efficient retrieval.
84
+ 3. **FastAPI Backend**: Handles API requests and manages the RAG pipeline.
85
+ 4. **Web Frontend**: Provides a user-friendly interface for interacting with the chatbot.
86
+
87
+ ## Customization
88
+
89
+ To customize the chatbot with additional research methods information:
90
+
91
+ 1. Add your information to the `research_methods_info.md` file.
92
+ 2. Restart the application to rebuild the vector database with the new information.
93
+
94
+ ## Troubleshooting
95
+
96
+ - If you encounter CORS issues, check that the frontend URL matches the allowed origins in the backend configuration.
97
+ - If the chatbot doesn't provide citations, ensure that the research methods information is properly formatted with source information.
98
+ - If you receive API errors, verify that your OpenAI API key is valid and has sufficient credits.
99
+
100
+ ## Testing
101
+
102
+ To run the automated tests:
103
+
104
+ ```
105
+ ./run_tests.sh
106
+ ```
107
+
108
+ This will execute unit tests for the backend API, frontend components, and integration tests.
109
+
110
+ ## License
111
+
112
+ This project is licensed under the MIT License - see the LICENSE file for details.