Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Eero committed Feb 8, 2024
1 parent 67d8624 commit f72d54e
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish to PyPI.org
on:
release:
types: [ published ]
types: [published]
jobs:
pypi:
runs-on: ubuntu-latest
Expand All @@ -13,10 +13,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
- name: Build package
run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions src/delibird/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

from . import _version
__version__ = _version.get_versions()['version']

__version__ = _version.get_versions()["version"]
81 changes: 81 additions & 0 deletions src/delibird/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import click
import psutil
import subprocess

from delibird.server import app
from delibird.log import Log, LogLevel
from delibird.pm import kill_process, http_process
from delibird.config import read_config


@click.group()
def cli():
pass


@cli.command()
@click.option(
"--config", "-c", type=click.Path(exists=True), help="指定配置文件", required=True
)
def start(config):
# init log
logger = Log("delibird")

# print and log
logger.echo("Starting...")
click.echo("Starting...")

# check if the program is running
if check_process("delibird"):
logger.echo("The program is already running", "error")
click.echo("The program is already running")
return

if not config:
click.echo("没有配置文件")
return

# 从配置文件中读取 server 配置, host 和 port
config_info = read_config(config)

host = config_info.get("server", {}).get("host")
port = config_info.get("server", {}).get("port")

# check if host or port is null
if not host or not port:
logger.echo("host or port is null", "error")
click.echo("host or port is null")
return

# Start the http server
http_process(config, host, port)

# Print and log
logger.echo("Started")
click.echo("Started")


@cli.command()
def stop():
# get logger
logger = Log("delibird")

# print and log
logger.echo("Stopping...")
click.echo("Stopping...")

# kill the process
kill_process()

# log and close
logger.echo("Stopped")
click.echo("Stopped")


def check_process(process_name):
result = subprocess.run(
["pgrep", "-f", process_name], capture_output=True, text=True
)

# 如果pgrep命令的输出不是空的,则有匹配的进程正在运行
return bool(result.stdout.strip())
2 changes: 1 addition & 1 deletion src/delibird/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, name, level=LogLevel.DEBUG):
console_handler.setFormatter(formatter)

# 创建文件处理器并设置日志文件路径
log_file_path = get_log_path("llmproxy")
log_file_path = get_log_path("delibird")
file_handler = logging.FileHandler(log_file_path)
file_handler.setFormatter(formatter)

Expand Down
71 changes: 0 additions & 71 deletions src/delibird/main.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/delibird/mock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from llmproxy.mock.send import send_mock
from delibird.mock.send import send_mock


__all__ = ["send_mock"]
8 changes: 4 additions & 4 deletions src/delibird/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import os
import subprocess
from multiprocessing import Process, cpu_count
from llmproxy.config import read_config
from delibird.config import read_config


def kill_process():
# Kill process named 'llmproxy' if it exists
os.system("pkill -f llmproxy")
# Kill process named 'delibird' if it exists
os.system("pkill -f delibird")


def http_process(config_file, host, port):
Expand All @@ -26,7 +26,7 @@ def http_process(config_file, host, port):
"uvicorn.workers.UvicornWorker",
"-b",
f"{host}:{port}",
"llmproxy.server:app",
"delibird.server:app",
"--timeout",
"60",
]
Expand Down
4 changes: 2 additions & 2 deletions src/delibird/router/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from llmproxy.router.spark import send as spark_send
from llmproxy.router.qwen import send as qwen_send
from delibird.router.spark import send as spark_send
from delibird.router.qwen import send as qwen_send

__all__ = ["spark_send", "qwen_send"]
6 changes: 3 additions & 3 deletions src/delibird/router/qwen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.responses import StreamingResponse
from http import HTTPStatus
import dashscope
from llmproxy.log import Log
from delibird.log import Log


class Qwen:
Expand Down Expand Up @@ -33,7 +33,7 @@ def read_config(self, config, request):
request: 请求参数.格式为 {"chat": messages, "model": "v15"}
"""

logger = Log("llmproxy")
logger = Log("delibird")
# 检查配置文件和模型是否存在
if not config:
logger.echo("配置文件不存在", "error")
Expand Down Expand Up @@ -101,7 +101,7 @@ async def send(self, chunk_size=24):

def send(config, request):
"""发送处理."""
logger = Log("llmproxy")
logger = Log("delibird")

# 创建 Qwen 实例
qwen = Qwen()
Expand Down
6 changes: 3 additions & 3 deletions src/delibird/router/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import websocket
from wsgiref.handlers import format_date_time
from fastapi.responses import StreamingResponse
from llmproxy.log import Log
from delibird.log import Log
from time import sleep
import asyncio
from llmproxy.stream import WsStream
from delibird.stream import WsStream


class Spark:
Expand All @@ -39,7 +39,7 @@ def read_config(self):
config: 配置文件
request: 请求参数.格式为 {"chat": messages, "model": "v15"}
"""
logger = Log("llmproxy")
logger = Log("delibird")
if not self.config:
logger.echo("配置文件不存在", "error")
return False
Expand Down
6 changes: 3 additions & 3 deletions src/delibird/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from llmproxy.router import spark_send, qwen_send
from llmproxy.config import read_config
from llmproxy.log import Log
from delibird.router import spark_send, qwen_send
from delibird.config import read_config
from delibird.log import Log


app = FastAPI()
Expand Down
4 changes: 2 additions & 2 deletions src/delibird/stream/wsstream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base import StreamBase
from llmproxy.log import Log
from delibird.log import Log
import websocket
import json

Expand Down Expand Up @@ -29,7 +29,7 @@ def close(self):

async def _spark_send(self, messages, model, app_id):
"""星火大模型发送处理."""
logger = Log("llmproxy")
logger = Log("delibird")
websocket.enableTrace(False)

self.websocket = websocket.create_connection(self.url)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from llmproxy.config import read_config
from delibird.config import read_config


def test_config():
Expand Down

0 comments on commit f72d54e

Please sign in to comment.