From f2f98284ffcc3bf473c66defd6b0ccc6de364622 Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Fri, 22 Sep 2023 09:01:38 +0000 Subject: [PATCH 1/2] fix: api format bug --- free_one_api/entities/response.py | 2 +- free_one_api/impls/forward/mgr.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/free_one_api/entities/response.py b/free_one_api/entities/response.py index 716162a..2c2da2d 100644 --- a/free_one_api/entities/response.py +++ b/free_one_api/entities/response.py @@ -5,7 +5,7 @@ class FinishReason(enum.Enum): """Finish reason type enum.""" - NULL = "null" + NULL = None """Null if this is a part of a streaming response.""" FUNCTION_CALL = "function_call" diff --git a/free_one_api/impls/forward/mgr.py b/free_one_api/impls/forward/mgr.py index 2281b47..14930a9 100644 --- a/free_one_api/impls/forward/mgr.py +++ b/free_one_api/impls/forward/mgr.py @@ -25,8 +25,8 @@ async def __stream_query( before = time.time() id_suffix = "".join(random.choices(string.ascii_letters+string.digits, k=29)) + t = int(time.time()) async def _gen(): - index = 0 async for resp in chan.adapter.query(req): if (resp.normal_message is None or len(resp.normal_message) == 0) and resp.finish_reason == response.FinishReason.NULL: @@ -35,17 +35,16 @@ async def _gen(): yield "data: {}\n\n".format(json.dumps({ "id": "chatcmpl-"+id_suffix, "object": "chat.completion.chunk", - "created": int(time.time()), + "created": t, "model": req.model, "choices": [{ - "index": index, + "index": 0, "delta": { "content": resp.normal_message, - }, + } if resp.normal_message else {}, "finish_reason": resp.finish_reason.value }] })) - index += 1 yield "data: [DONE]\n\n" spent_ms = int((time.time() - before)*1000) From 1eacaac167697bb6e3df3f1bde4b0fa7f070f1e6 Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Fri, 22 Sep 2023 09:32:06 +0000 Subject: [PATCH 2/2] fix: initial value of latency is not -1 --- free_one_api/impls/router/api.py | 27 +++++++++++++++++---------- web/src/components/Channel.vue | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/free_one_api/impls/router/api.py b/free_one_api/impls/router/api.py index c41ca2d..be890b2 100644 --- a/free_one_api/impls/router/api.py +++ b/free_one_api/impls/router/api.py @@ -45,16 +45,23 @@ async def channel_list(): @self.api("/channel/create", ["POST"], auth=True) async def channel_create(): - data = await quart.request.get_json() - - chan = channel.Channel.load_channel(data) - - await self.chanmgr.create_channel(chan) - - return quart.jsonify({ - "code": 0, - "message": "ok", - }) + try: + data = await quart.request.get_json() + + chan = channel.Channel.load_channel(data) + + await self.chanmgr.create_channel(chan) + + return quart.jsonify({ + "code": 0, + "message": "ok", + }) + except Exception as e: + traceback.print_exc() + return quart.jsonify({ + "code": 1, + "message": str(e), + }) @self.api("/channel/delete/", ["DELETE"], auth=True) async def channel_delete(chan_id: int): diff --git a/web/src/components/Channel.vue b/web/src/components/Channel.vue index 8647c96..3277333 100644 --- a/web/src/components/Channel.vue +++ b/web/src/components/Channel.vue @@ -305,7 +305,7 @@ function showCreateChannelDialog() { }, "model_mapping": `{}`, "enabled": true, // no need for creation - "latency": 0.13 // no need for creation + "latency": -1 // no need for creation }; detailsDialogVisible.value = true; }