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
|
| 2 |
+
.env
|
| 3 |
+
.env.local
|
| 4 |
+
.env.*.local
|
| 5 |
+
|
| 6 |
+
# Database
|
| 7 |
+
db.*
|
| 8 |
+
*.sqlite3
|
| 9 |
+
*.db
|
| 10 |
+
|
| 11 |
+
# Byte-compiled / optimized / DLL files
|
| 12 |
+
__pycache__/
|
| 13 |
+
*.py[cod]
|
| 14 |
+
*$py.class
|
| 15 |
+
|
| 16 |
+
# C extensions
|
| 17 |
+
*.so
|
| 18 |
+
|
| 19 |
+
# Distribution / packaging
|
| 20 |
+
.Python
|
| 21 |
+
build/
|
| 22 |
+
develop-eggs/
|
| 23 |
+
dist/
|
| 24 |
+
downloads/
|
| 25 |
+
eggs/
|
| 26 |
+
.eggs/
|
| 27 |
+
lib/
|
| 28 |
+
lib64/
|
| 29 |
+
parts/
|
| 30 |
+
sdist/
|
| 31 |
+
var/
|
| 32 |
+
wheels/
|
| 33 |
+
pip-wheel-metadata/
|
| 34 |
+
share/python-wheels/
|
| 35 |
+
*.egg-info/
|
| 36 |
+
.installed.cfg
|
| 37 |
+
*.egg
|
| 38 |
+
MANIFEST
|
| 39 |
+
|
| 40 |
+
# PyInstaller
|
| 41 |
+
*.manifest
|
| 42 |
+
*.spec
|
| 43 |
+
|
| 44 |
+
# Installer logs
|
| 45 |
+
pip-log.txt
|
| 46 |
+
pip-delete-this-directory.txt
|
| 47 |
+
|
| 48 |
+
# Unit test / coverage reports
|
| 49 |
+
htmlcov/
|
| 50 |
+
.tox/
|
| 51 |
+
.nox/
|
| 52 |
+
.coverage
|
| 53 |
+
.coverage.*
|
| 54 |
+
.cache
|
| 55 |
+
nosetests.xml
|
| 56 |
+
coverage.xml
|
| 57 |
+
*.cover
|
| 58 |
+
*.py,cover
|
| 59 |
+
.hypothesis/
|
| 60 |
+
.pytest_cache/
|
| 61 |
+
|
| 62 |
+
# Translations
|
| 63 |
+
*.mo
|
| 64 |
+
*.pot
|
| 65 |
+
|
| 66 |
+
# Django stuff:
|
| 67 |
+
*.log
|
| 68 |
+
local_settings.py
|
| 69 |
+
db.sqlite3
|
| 70 |
+
db.sqlite3-journal
|
| 71 |
+
|
| 72 |
+
# Flask stuff:
|
| 73 |
+
instance/
|
| 74 |
+
.webassets-cache
|
| 75 |
+
|
| 76 |
+
# Scrapy stuff:
|
| 77 |
+
.scrapy
|
| 78 |
+
|
| 79 |
+
# Sphinx documentation
|
| 80 |
+
docs/_build/
|
| 81 |
+
|
| 82 |
+
# PyBuilder
|
| 83 |
+
target/
|
| 84 |
+
|
| 85 |
+
# Jupyter Notebook
|
| 86 |
+
.ipynb_checkpoints
|
| 87 |
+
|
| 88 |
+
# IPython
|
| 89 |
+
profile_default/
|
| 90 |
+
ipython_config.py
|
| 91 |
+
|
| 92 |
+
# pyenv
|
| 93 |
+
.python-version
|
| 94 |
+
|
| 95 |
+
# pipenv
|
| 96 |
+
Pipfile.lock
|
| 97 |
+
|
| 98 |
+
# PEP 582
|
| 99 |
+
__pypackages__/
|
| 100 |
+
|
| 101 |
+
# Celery stuff
|
| 102 |
+
celerybeat-schedule
|
| 103 |
+
celerybeat.pid
|
| 104 |
+
|
| 105 |
+
# SageMath parsed files
|
| 106 |
+
*.sage.py
|
| 107 |
+
|
| 108 |
+
# Environments
|
| 109 |
+
venv/
|
| 110 |
+
env/
|
| 111 |
+
ENV/
|
| 112 |
+
env.bak/
|
| 113 |
+
venv.bak/
|
| 114 |
+
.venv
|
| 115 |
+
|
| 116 |
+
# Spyder project settings
|
| 117 |
+
.spyderproject
|
| 118 |
+
.spyproject
|
| 119 |
+
|
| 120 |
+
# Rope project settings
|
| 121 |
+
.ropeproject
|
| 122 |
+
|
| 123 |
+
# mkdocs documentation
|
| 124 |
+
/site
|
| 125 |
+
|
| 126 |
+
# mypy
|
| 127 |
+
.mypy_cache/
|
| 128 |
+
.dmypy.json
|
| 129 |
+
dmypy.json
|
| 130 |
+
|
| 131 |
+
# Pyre type checker
|
| 132 |
+
.pyre/
|
| 133 |
+
|
| 134 |
+
# pytype static type analyzer
|
| 135 |
+
.pytype/
|
| 136 |
+
|
| 137 |
+
# Cython debug symbols
|
| 138 |
+
cython_debug/
|
| 139 |
+
|
| 140 |
+
# IDEs
|
| 141 |
+
.vscode/
|
| 142 |
+
.idea/
|
| 143 |
+
*.swp
|
| 144 |
+
*.swo
|
| 145 |
+
*~
|
| 146 |
+
|
| 147 |
+
# OS
|
| 148 |
+
.DS_Store
|
| 149 |
+
Thumbs.db
|
Dockerfile
CHANGED
|
@@ -19,6 +19,9 @@ RUN pip install --upgrade pip
|
|
| 19 |
# Install Python dependencies
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
# Copy the entire backend directory
|
| 23 |
COPY . .
|
| 24 |
|
|
|
|
| 19 |
# Install Python dependencies
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
+
# Install specific transformers
|
| 23 |
+
RUN pip install git+https://github.com/huggingface/transformers@8fb854cac869b42c87a7bd15d9298985c5aea96e
|
| 24 |
+
|
| 25 |
# Copy the entire backend directory
|
| 26 |
COPY . .
|
| 27 |
|
agent_manager/__init__.py
CHANGED
|
@@ -17,7 +17,31 @@ import uuid
|
|
| 17 |
# Load environment variables from .env file
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
SYSTEM_PROMPT = """
|
| 22 |
You are an expert linguistic assistant specializing in grammar correction and translation. Your responses must always be accurate, concise, clear, and easy to understand.
|
| 23 |
|
|
@@ -114,6 +138,8 @@ MODEL = HuggingFaceEndpoint(
|
|
| 114 |
huggingfacehub_api_token=API_KEY
|
| 115 |
)
|
| 116 |
|
|
|
|
|
|
|
| 117 |
CHAT = ChatHuggingFace(llm=MODEL).with_structured_output(schema=Response, method='json_schema')
|
| 118 |
STRUCTURED_CHAT = StructuredChatWrapper(CHAT)
|
| 119 |
|
|
|
|
| 17 |
# Load environment variables from .env file
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
+
# Try multiple environment variable names for HuggingFace token
|
| 21 |
+
API_KEY = (
|
| 22 |
+
os.environ.get("HUGGINGFACEHUB_API_TOKEN") or
|
| 23 |
+
os.environ.get("HF_TOKEN") or
|
| 24 |
+
os.environ.get("HF_API_TOKEN")
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if not API_KEY:
|
| 28 |
+
raise ValueError(
|
| 29 |
+
"HuggingFace API token not found. Please set one of the following environment variables:\n"
|
| 30 |
+
" - HUGGINGFACEHUB_API_TOKEN (preferred)\n"
|
| 31 |
+
" - HF_TOKEN\n"
|
| 32 |
+
" - HF_API_TOKEN\n\n"
|
| 33 |
+
"Get your token from: https://huggingface.co/settings/tokens\n"
|
| 34 |
+
"Make sure to create a .env file in the backend directory with your token."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if not API_KEY.strip():
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"HuggingFace API token is empty. Please check your .env file or environment variables."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# Set HF_TOKEN for huggingface-hub library compatibility
|
| 43 |
+
os.environ["HF_TOKEN"] = API_KEY
|
| 44 |
+
|
| 45 |
SYSTEM_PROMPT = """
|
| 46 |
You are an expert linguistic assistant specializing in grammar correction and translation. Your responses must always be accurate, concise, clear, and easy to understand.
|
| 47 |
|
|
|
|
| 138 |
huggingfacehub_api_token=API_KEY
|
| 139 |
)
|
| 140 |
|
| 141 |
+
|
| 142 |
+
|
| 143 |
CHAT = ChatHuggingFace(llm=MODEL).with_structured_output(schema=Response, method='json_schema')
|
| 144 |
STRUCTURED_CHAT = StructuredChatWrapper(CHAT)
|
| 145 |
|
backend/settings.py
CHANGED
|
@@ -37,7 +37,7 @@ ALLOWED_HOSTS = [
|
|
| 37 |
] if os.environ.get("ALLOWED_HOSTS") else []
|
| 38 |
|
| 39 |
CORS_ALLOW_CREDENTIALS = True
|
| 40 |
-
CORS_ALLOW_ALL_ORIGINS =
|
| 41 |
|
| 42 |
|
| 43 |
SESSION_COOKIE_HTTPONLY = True
|
|
|
|
| 37 |
] if os.environ.get("ALLOWED_HOSTS") else []
|
| 38 |
|
| 39 |
CORS_ALLOW_CREDENTIALS = True
|
| 40 |
+
CORS_ALLOW_ALL_ORIGINS = os.environ.get("CORS_ALLOW_ALL_ORIGINS", "True") == "True"
|
| 41 |
|
| 42 |
|
| 43 |
SESSION_COOKIE_HTTPONLY = True
|
requirements.txt
CHANGED
|
@@ -53,7 +53,6 @@ tenacity==9.1.2
|
|
| 53 |
tokenizers==0.22.1
|
| 54 |
torch==2.9.0
|
| 55 |
tqdm==4.67.1
|
| 56 |
-
transformers @ git+https://github.com/huggingface/transformers@8fb854cac869b42c87a7bd15d9298985c5aea96e
|
| 57 |
typer-slim==0.20.0
|
| 58 |
typing-inspection==0.4.2
|
| 59 |
typing_extensions==4.15.0
|
|
|
|
| 53 |
tokenizers==0.22.1
|
| 54 |
torch==2.9.0
|
| 55 |
tqdm==4.67.1
|
|
|
|
| 56 |
typer-slim==0.20.0
|
| 57 |
typing-inspection==0.4.2
|
| 58 |
typing_extensions==4.15.0
|