Auto-update: Sat Jun 29 13:36:50 PDT 2024
This commit is contained in:
parent
727d89b749
commit
4aaab79c2f
4 changed files with 55 additions and 49 deletions
|
@ -115,8 +115,6 @@ COMFYUI_OUTPUT_DIR = COMFYUI_DIR / 'output'
|
||||||
COMFYUI_LAUNCH_CMD = os.getenv('COMFYUI_LAUNCH_CMD', 'mamba activate comfyui && python main.py')
|
COMFYUI_LAUNCH_CMD = os.getenv('COMFYUI_LAUNCH_CMD', 'mamba activate comfyui && python main.py')
|
||||||
SD_CONFIG_PATH = CONFIG_DIR / 'sd.yaml'
|
SD_CONFIG_PATH = CONFIG_DIR / 'sd.yaml'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### ASR
|
### ASR
|
||||||
ASR_DIR = DATA_DIR / "asr"
|
ASR_DIR = DATA_DIR / "asr"
|
||||||
os.makedirs(ASR_DIR, exist_ok=True)
|
os.makedirs(ASR_DIR, exist_ok=True)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
from starlette.requests import ClientDisconnect
|
from starlette.requests import ClientDisconnect
|
||||||
from hypercorn.asyncio import serve
|
from hypercorn.asyncio import serve
|
||||||
from hypercorn.config import Config
|
from hypercorn.config import Config as HypercornConfig
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import httpx
|
import httpx
|
||||||
|
@ -18,15 +18,13 @@ from dotenv import load_dotenv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import argparse
|
import argparse
|
||||||
from . import L, API, OBSIDIAN_VAULT_DIR
|
|
||||||
from .logs import Logger
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Personal API.')
|
parser = argparse.ArgumentParser(description='Personal API.')
|
||||||
parser.add_argument('--debug', action='store_true', help='Set log level to L.INFO')
|
parser.add_argument('--debug', action='store_true', help='Set log level to L.INFO')
|
||||||
parser.add_argument('--test', type=str, help='Load only the specified module.')
|
parser.add_argument('--test', type=str, help='Load only the specified module.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
from sijapi import L
|
from . import L, API, ROUTER_DIR
|
||||||
L.setup_from_args(args)
|
L.setup_from_args(args)
|
||||||
|
|
||||||
from sijapi import ROUTER_DIR
|
from sijapi import ROUTER_DIR
|
||||||
|
@ -132,11 +130,10 @@ def main(argv):
|
||||||
if getattr(API.MODULES, module_name):
|
if getattr(API.MODULES, module_name):
|
||||||
load_router(module_name)
|
load_router(module_name)
|
||||||
|
|
||||||
config = Config()
|
|
||||||
config.keep_alive_timeout = 1200
|
|
||||||
config.bind = [API.BIND]
|
|
||||||
asyncio.run(serve(api, config))
|
|
||||||
|
|
||||||
|
config = HypercornConfig()
|
||||||
|
config.bind = [API.BIND] # Use the resolved BIND value
|
||||||
|
asyncio.run(serve(api, config))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
|
@ -1,56 +1,36 @@
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from typing import List, Optional, Any, Tuple, Dict, Union, Tuple
|
|
||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Union, Dict, Any, Optional
|
|
||||||
from pydantic import BaseModel, create_model
|
|
||||||
import yaml
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import yaml
|
|
||||||
import math
|
import math
|
||||||
from timezonefinder import TimezoneFinder
|
|
||||||
from pathlib import Path
|
|
||||||
import asyncpg
|
|
||||||
import aiohttp
|
|
||||||
import aiofiles
|
|
||||||
from contextlib import asynccontextmanager
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
import reverse_geocoder as rg
|
|
||||||
from timezonefinder import TimezoneFinder
|
|
||||||
from srtm import get_data
|
|
||||||
from pathlib import Path
|
|
||||||
import yaml
|
|
||||||
from typing import Union, List, TypeVar, Type
|
|
||||||
from pydantic import BaseModel, create_model
|
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from typing import List, Dict
|
|
||||||
import yaml
|
|
||||||
from pathlib import Path
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar, Type
|
||||||
|
|
||||||
|
import aiofiles
|
||||||
|
import aiohttp
|
||||||
|
import asyncpg
|
||||||
|
import reverse_geocoder as rg
|
||||||
|
import yaml
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
from pydantic import BaseModel, Field, create_model
|
||||||
|
from srtm import get_data
|
||||||
|
from timezonefinder import TimezoneFinder
|
||||||
|
|
||||||
T = TypeVar('T', bound='Configuration')
|
T = TypeVar('T', bound='Configuration')
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, create_model
|
|
||||||
from typing import List, Optional, Any, Dict
|
|
||||||
from pathlib import Path
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
class APIConfig(BaseModel):
|
class APIConfig(BaseModel):
|
||||||
BIND: str
|
HOST: str
|
||||||
PORT: int
|
PORT: int
|
||||||
|
BIND: str
|
||||||
URL: str
|
URL: str
|
||||||
PUBLIC: List[str]
|
PUBLIC: List[str]
|
||||||
TRUSTED_SUBNETS: List[str]
|
TRUSTED_SUBNETS: List[str]
|
||||||
MODULES: Any # This will be replaced with a dynamic model
|
MODULES: Any # This will be replaced with a dynamic model
|
||||||
BaseTZ: Optional[str] = 'UTC'
|
TZ: str
|
||||||
KEYS: List[str]
|
KEYS: List[str]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -73,6 +53,11 @@ class APIConfig(BaseModel):
|
||||||
print(f"Error parsing secrets YAML: {e}")
|
print(f"Error parsing secrets YAML: {e}")
|
||||||
secrets_data = {}
|
secrets_data = {}
|
||||||
|
|
||||||
|
# Resolve internal placeholders
|
||||||
|
config_data = cls.resolve_placeholders(config_data)
|
||||||
|
|
||||||
|
print(f"Resolved config: {config_data}") # Debug print
|
||||||
|
|
||||||
# Handle KEYS placeholder
|
# Handle KEYS placeholder
|
||||||
if isinstance(config_data.get('KEYS'), list) and len(config_data['KEYS']) == 1:
|
if isinstance(config_data.get('KEYS'), list) and len(config_data['KEYS']) == 1:
|
||||||
placeholder = config_data['KEYS'][0]
|
placeholder = config_data['KEYS'][0]
|
||||||
|
@ -105,6 +90,33 @@ class APIConfig(BaseModel):
|
||||||
|
|
||||||
return cls(**config_data)
|
return cls(**config_data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def resolve_placeholders(cls, config_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
def resolve_value(value):
|
||||||
|
if isinstance(value, str):
|
||||||
|
pattern = r'\{\{\s*([^}]+)\s*\}\}'
|
||||||
|
matches = re.findall(pattern, value)
|
||||||
|
for match in matches:
|
||||||
|
if match in config_data:
|
||||||
|
value = value.replace(f'{{{{ {match} }}}}', str(config_data[match]))
|
||||||
|
return value
|
||||||
|
|
||||||
|
resolved_data = {}
|
||||||
|
for key, value in config_data.items():
|
||||||
|
if isinstance(value, dict):
|
||||||
|
resolved_data[key] = cls.resolve_placeholders(value)
|
||||||
|
elif isinstance(value, list):
|
||||||
|
resolved_data[key] = [resolve_value(item) for item in value]
|
||||||
|
else:
|
||||||
|
resolved_data[key] = resolve_value(value)
|
||||||
|
|
||||||
|
# Resolve BIND separately to ensure HOST and PORT are used
|
||||||
|
if 'BIND' in resolved_data:
|
||||||
|
resolved_data['BIND'] = resolved_data['BIND'].replace('{{ HOST }}', str(resolved_data['HOST']))
|
||||||
|
resolved_data['BIND'] = resolved_data['BIND'].replace('{{ PORT }}', str(resolved_data['PORT']))
|
||||||
|
|
||||||
|
return resolved_data
|
||||||
|
|
||||||
def __getattr__(self, name: str) -> Any:
|
def __getattr__(self, name: str) -> Any:
|
||||||
if name == 'MODULES':
|
if name == 'MODULES':
|
||||||
return self.__dict__['MODULES']
|
return self.__dict__['MODULES']
|
||||||
|
|
|
@ -373,7 +373,6 @@ async def process_all_accounts():
|
||||||
autoresponding_tasks = [asyncio.create_task(process_account_autoresponding(account)) for account in email_accounts]
|
autoresponding_tasks = [asyncio.create_task(process_account_autoresponding(account)) for account in email_accounts]
|
||||||
await asyncio.gather(*summarization_tasks, *autoresponding_tasks)
|
await asyncio.gather(*summarization_tasks, *autoresponding_tasks)
|
||||||
|
|
||||||
|
|
||||||
@email.on_event("startup")
|
@email.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
Loading…
Reference in a new issue