Shurem commited on
Commit
cc837de
·
1 Parent(s): 45c5a08

Add application file

Browse files
.env ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Qdrant Configuration
2
+ QDRANT_URL=https://2aa04938-4f4a-4e3c-9e96-6328c0381059.us-east4-0.gcp.cloud.qdrant.io
3
+ QDRANT_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.iqhWUBAdUuc0uakiykAf8hBUxUFhMXFkV4edpPYklZ0
4
+ QDRANT_COLLECTION_NAME=RAGChatbot
5
+
6
+ # Neon Postgres Configuration (fixed format - removed 'psql' prefix)
7
+ DATABASE_URL=postgresql://neondb_owner:npg_olSU4n3LPjZX@ep-blue-dawn-adgrzjmt-pooler.c-2.us-east-1.aws.neon.tech/neondb?sslmode=require
8
+
9
+ # Gemini API Configuration (via OpenAI-compatible endpoint)
10
+ OPENAI_API_KEY=AIzaSyAAh9OwrhI28Z5toIZye0F9QnWfjqwq8L0
11
+ OPENAI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai
12
+ GEMINI_MODEL=gemini-2.5-flash
13
+
14
+ # Application Settings
15
+ APP_ENV=development
16
+ LOG_LEVEL=info
17
+ RATE_LIMIT_REQUESTS=100
18
+ RATE_LIMIT_WINDOW=60
19
+
20
+ # RAG Settings
21
+ RAG_TOP_K=5
22
+ RAG_MIN_SCORE=0.3
23
+ MAX_TOKENS_PER_CHUNK=512
24
+ MAX_RESPONSE_TOKENS=2000
25
+
26
+ # Embedding Configuration
27
+ EMBEDDING_MODEL=text-embedding-004
28
+ EMBEDDING_DIMENSION=768
29
+
30
+ # CORS Settings
31
+ ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8000,https://yourdomain.com
.env.example ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Qdrant Configuration
2
+ QDRANT_URL=https://2aa04938-4f4a-4e3c-9e96-6328c0381059.us-east4-0.gcp.cloud.qdrant.io
3
+ QDRANT_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJtIn0.iqhWUBAdUuc0uakiykAf8hBUxUFhMXFkV4edpPYklZ0
4
+ QDRANT_COLLECTION_NAME=RAGChatbot
5
+
6
+ # Neon Postgres Configuration
7
+ DATABASE_URL=psql 'postgresql://neondb_owner:npg_olSU4n3LPjZX@ep-blue-dawn-adgrzjmt-pooler.c-2.us-east-1.aws.neon.tech/neondb?sslmode=require&channel_binding=require'
8
+
9
+ # Gemini API Configuration (via OpenAI-compatible endpoint)
10
+ OPENAI_API_KEY=AIzaSyAAh9OwrhI28Z5toIZye0F9QnWfjqwq8L0
11
+ OPENAI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
12
+
13
+ # Application Settings
14
+ APP_ENV=development
15
+ LOG_LEVEL=info
16
+ RATE_LIMIT_REQUESTS=100
17
+ RATE_LIMIT_WINDOW=60
18
+
19
+ # RAG Settings
20
+ RAG_TOP_K=5
21
+ RAG_MIN_SCORE=0.3
22
+ MAX_TOKENS_PER_CHUNK=512
23
+ MAX_RESPONSE_TOKENS=2000
24
+
25
+ # Embedding Configuration
26
+ EMBEDDING_MODEL=text-embedding-004
27
+ EMBEDDING_DIMENSION=768
28
+
29
+ # CORS Settings
30
+ ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8000,https://yourdomain.com
Dockerfile CHANGED
@@ -21,4 +21,4 @@ COPY --chown=user . /app
21
  EXPOSE 7860
22
 
23
  # Run the FastAPI application
24
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
21
  EXPOSE 7860
22
 
23
  # Run the FastAPI application
24
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
__init__.py ADDED
File without changes
__pycache__/main.cpython-310.pyc ADDED
Binary file (3.26 kB). View file
 
__pycache__/main.cpython-312.pyc ADDED
Binary file (5.32 kB). View file
 
config.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Optional
3
+
4
+ class Config:
5
+ """
6
+ Configuration class for the RAG Chatbot backend
7
+ """
8
+ # Database configuration
9
+ DATABASE_URL: str = os.getenv("DATABASE_URL", "postgresql+asyncpg://user:password@localhost/rag_chatbot")
10
+
11
+ # Qdrant configuration
12
+ QDRANT_URL: str = os.getenv("QDRANT_URL", "http://localhost:6333")
13
+ QDRANT_API_KEY: Optional[str] = os.getenv("QDRANT_API_KEY")
14
+ QDRANT_COLLECTION_NAME: str = os.getenv("QDRANT_COLLECTION_NAME", "textbook_content_embeddings")
15
+
16
+ # OpenAI/Gemini API configuration
17
+ OPENAI_API_KEY: str = os.getenv("OPENAI_API_KEY", "")
18
+ OPENAI_BASE_URL: str = os.getenv("OPENAI_BASE_URL", "https://generativelanguage.googleapis.com/v1beta/openai/")
19
+ GEMINI_MODEL: str = os.getenv("GEMINI_MODEL", "gemini-2.5-flash")
20
+
21
+ # Embedding configuration
22
+ EMBEDDING_MODEL: str = os.getenv("EMBEDDING_MODEL", "text-embedding-004")
23
+ EMBEDDING_DIMENSION: int = int(os.getenv("EMBEDDING_DIMENSION", "768"))
24
+
25
+ # Application settings
26
+ APP_ENV: str = os.getenv("APP_ENV", "development")
27
+ LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
28
+
29
+ # Rate limiting
30
+ RATE_LIMIT_REQUESTS: int = int(os.getenv("RATE_LIMIT_REQUESTS", "100"))
31
+ RATE_LIMIT_WINDOW: int = int(os.getenv("RATE_LIMIT_WINDOW", "60")) # in seconds
32
+
33
+ # RAG settings
34
+ RAG_TOP_K: int = int(os.getenv("RAG_TOP_K", "5"))
35
+ RAG_MIN_SCORE: float = float(os.getenv("RAG_MIN_SCORE", "0.3"))
36
+ MAX_TOKENS_PER_CHUNK: int = int(os.getenv("MAX_TOKENS_PER_CHUNK", "512"))
37
+ MAX_RESPONSE_TOKENS: int = int(os.getenv("MAX_RESPONSE_TOKENS", "2000"))
38
+
39
+ # CORS settings
40
+ ALLOWED_ORIGINS: list = os.getenv("ALLOWED_ORIGINS", "*").split(",")
41
+
42
+ # SSE Streaming
43
+ SSE_STREAMING_ENABLED: bool = os.getenv("SSE_STREAMING_ENABLED", "true").lower() == "true"
44
+
45
+ @classmethod
46
+ def validate(cls):
47
+ """
48
+ Validate that required configuration values are set
49
+ """
50
+ errors = []
51
+
52
+ if not cls.OPENAI_API_KEY:
53
+ errors.append("OPENAI_API_KEY is required")
54
+
55
+ if cls.APP_ENV not in ["development", "staging", "production"]:
56
+ errors.append(f"APP_ENV must be one of: development, staging, production. Got: {cls.APP_ENV}")
57
+
58
+ if errors:
59
+ raise ValueError(f"Configuration validation failed: {'; '.join(errors)}")
60
+
61
+
62
+ # Validate configuration on import
63
+ Config.validate()
pyproject.toml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rag-chatbot-backend"
7
+ version = "0.1.0"
8
+ description = "Backend for RAG Chatbot for Physical AI Textbook"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Physical AI Textbook Team"},
14
+ ]
15
+ dependencies = [
16
+ "fastapi>=0.104.1",
17
+ "uvicorn>=0.24.0",
18
+ "openai>=1.3.5",
19
+ "qdrant-client>=1.7.0",
20
+ "asyncio>=3.4.3",
21
+ "python-dotenv>=1.0.0",
22
+ "pydantic>=2.5.0",
23
+ "sqlalchemy>=2.0.23",
24
+ "asyncpg>=0.29.0",
25
+ "psycopg[binary]>=3.1.12",
26
+ "pyjwt>=2.8.0",
27
+ "passlib[bcrypt]>=1.7.4",
28
+ "python-multipart>=0.0.6",
29
+ "alembic>=1.13.1",
30
+ "tiktoken>=0.5.1",
31
+ "sentence-transformers>=2.2.2",
32
+ "requests>=2.31.0",
33
+ "aiofiles>=23.2.1",
34
+ "sse-starlette>=1.8.2",
35
+ "python-slugify>=8.0.1",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ dev = [
40
+ "pytest>=7.4.0",
41
+ "pytest-asyncio>=0.21.0",
42
+ "pytest-cov>=4.1.0",
43
+ "black>=23.7.0",
44
+ "flake8>=6.0.0",
45
+ "mypy>=1.4.1",
46
+ "isort>=5.12.0",
47
+ "pre-commit>=3.3.3",
48
+ ]
49
+
50
+ [tool.setuptools.packages.find]
51
+ where = ["."]
52
+ include = ["backend*"]
53
+
54
+ [tool.pytest.ini_options]
55
+ testpaths = ["tests"]
56
+ asyncio_mode = "auto"
rag_chatbot_backend.egg-info/PKG-INFO ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: rag-chatbot-backend
3
+ Version: 0.1.0
4
+ Summary: Backend for RAG Chatbot for Physical AI Textbook
5
+ Author: Physical AI Textbook Team
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: fastapi>=0.104.1
10
+ Requires-Dist: uvicorn>=0.24.0
11
+ Requires-Dist: openai>=1.3.5
12
+ Requires-Dist: qdrant-client>=1.7.0
13
+ Requires-Dist: asyncio>=3.4.3
14
+ Requires-Dist: python-dotenv>=1.0.0
15
+ Requires-Dist: pydantic>=2.5.0
16
+ Requires-Dist: sqlalchemy>=2.0.23
17
+ Requires-Dist: asyncpg>=0.29.0
18
+ Requires-Dist: psycopg[binary]>=3.1.12
19
+ Requires-Dist: pyjwt>=2.8.0
20
+ Requires-Dist: passlib[bcrypt]>=1.7.4
21
+ Requires-Dist: python-multipart>=0.0.6
22
+ Requires-Dist: alembic>=1.13.1
23
+ Requires-Dist: tiktoken>=0.5.1
24
+ Requires-Dist: sentence-transformers>=2.2.2
25
+ Requires-Dist: requests>=2.31.0
26
+ Requires-Dist: aiofiles>=23.2.1
27
+ Requires-Dist: sse-starlette>=1.8.2
28
+ Requires-Dist: python-slugify>=8.0.1
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
33
+ Requires-Dist: black>=23.7.0; extra == "dev"
34
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
35
+ Requires-Dist: mypy>=1.4.1; extra == "dev"
36
+ Requires-Dist: isort>=5.12.0; extra == "dev"
37
+ Requires-Dist: pre-commit>=3.3.3; extra == "dev"
rag_chatbot_backend.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pyproject.toml
2
+ rag_chatbot_backend.egg-info/PKG-INFO
3
+ rag_chatbot_backend.egg-info/SOURCES.txt
4
+ rag_chatbot_backend.egg-info/dependency_links.txt
5
+ rag_chatbot_backend.egg-info/requires.txt
6
+ rag_chatbot_backend.egg-info/top_level.txt
rag_chatbot_backend.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
rag_chatbot_backend.egg-info/requires.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi>=0.104.1
2
+ uvicorn>=0.24.0
3
+ openai>=1.3.5
4
+ qdrant-client>=1.7.0
5
+ asyncio>=3.4.3
6
+ python-dotenv>=1.0.0
7
+ pydantic>=2.5.0
8
+ sqlalchemy>=2.0.23
9
+ asyncpg>=0.29.0
10
+ psycopg[binary]>=3.1.12
11
+ pyjwt>=2.8.0
12
+ passlib[bcrypt]>=1.7.4
13
+ python-multipart>=0.0.6
14
+ alembic>=1.13.1
15
+ tiktoken>=0.5.1
16
+ sentence-transformers>=2.2.2
17
+ requests>=2.31.0
18
+ aiofiles>=23.2.1
19
+ sse-starlette>=1.8.2
20
+ python-slugify>=8.0.1
21
+
22
+ [dev]
23
+ pytest>=7.4.0
24
+ pytest-asyncio>=0.21.0
25
+ pytest-cov>=4.1.0
26
+ black>=23.7.0
27
+ flake8>=6.0.0
28
+ mypy>=1.4.1
29
+ isort>=5.12.0
30
+ pre-commit>=3.3.3
rag_chatbot_backend.egg-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
uv.lock ADDED
The diff for this file is too large to render. See raw diff