Skip to content

Commit

Permalink
fix: time.tzset() error (#16)
Browse files Browse the repository at this point in the history
* fix tzset error in windows

* clear useless

* update docker
  • Loading branch information
KenyonY authored May 5, 2023
1 parent 9ddf2ca commit 315d110
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 68 deletions.
63 changes: 4 additions & 59 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,4 @@
.idea/
.vscode/
third-party/
ssl/
chat.yaml

tests/
Log/
dist/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
Miniconda3-latest-Linux-x86_64.sh
# C extensions
*.so

# Distribution / packaging
.Python
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
**/*
!openai_forward
!pyproject.toml
!README.md
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Replace `BASE_URL` in the docker startup command with the address of the proxy s
docker run -d -p 3000:3000 -e OPENAI_API_KEY="sk-******" -e CODE="<your password>" -e BASE_URL="caloi.top/openai" yidadaa/chatgpt-next-web
```


# Deploy

Two deployment methods are provided, just choose one.
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ services:
- "8000:8000"
volumes:
- ./Log:/home/openai-forward/Log
- ./openai_forward:/opt/conda/lib/python3.10/site-packages/openai_forward
- ./openai_forward:/home/openai-forward/openai_forward
# - ./openai_forward:/opt/conda/lib/python3.10/site-packages/openai_forward
command:
- --port=8000
- --workers=1
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ RUN pip install --no-cache-dir \

COPY . /home/openai-forward
WORKDIR /home/openai-forward
RUN pip install . --no-cache-dir && rm -rf /home/openai-forward/*
RUN pip install -e . --no-cache-dir
EXPOSE 8000
ENTRYPOINT ["openai_forward", "run"]
2 changes: 1 addition & 1 deletion openai_forward/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.5"
__version__ = "0.1.6"

from dotenv import load_dotenv

Expand Down
4 changes: 4 additions & 0 deletions openai_forward/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ def run(port=8000, workers=1):

def main():
fire.Fire(Cli)


if __name__ == "__main__":
main()
9 changes: 6 additions & 3 deletions openai_forward/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def emit(self, record):
logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())


def setting_log(log_name, multi_process=True, time_zone='Asia/Shanghai'):
def setting_log(log_name, multi_process=True):
# TODO 修复时区配置
time_zone = os.environ.get("TZ")
print(f"{time_zone=}")
if time_zone == "Asia/Shanghai":
import datetime
tz = pytz.timezone(time_zone)
Expand All @@ -36,8 +38,9 @@ def setting_log(log_name, multi_process=True, time_zone='Asia/Shanghai'):
# offset = loc_dt.strftime("%z")
# os.environ['TZ'] = f"UTC-{offset}"
os.environ['TZ'] = f"UTC-8"
print(os.environ['TZ'])
time.tzset()
if hasattr(time, 'tzset'):
print(os.environ['TZ'])
time.tzset()

logging.root.handlers = [InterceptHandler()]
for name in logging.root.manager.loggerDict.keys():
Expand Down
3 changes: 0 additions & 3 deletions tests/test_chat_save.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from openai_forward.content.chat import ChatSaver
import pytest
import os
from utils import rm

@pytest.fixture(scope="module")
def saver() -> ChatSaver:
os.system("rm -rf chat_*.txt")
return ChatSaver(save_interval=1, max_chat_size=2)

class TestChatSaver:

@classmethod
def teardown_class(cls):
rm("Log/*.log")
rm("Log/chat*.txt")

def test_init(self, saver: ChatSaver):
Expand Down

0 comments on commit 315d110

Please sign in to comment.