Skip to content

Commit

Permalink
Merge pull request #3 from RockChinQ/fix/latency-initial-value
Browse files Browse the repository at this point in the history
Fix: latency initial value is invalid
  • Loading branch information
RockChinQ authored Sep 22, 2023
2 parents 1e00d50 + 1eacaac commit 2bba354
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion free_one_api/entities/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions free_one_api/impls/forward/mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
27 changes: 17 additions & 10 deletions free_one_api/impls/router/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:chan_id>", ["DELETE"], auth=True)
async def channel_delete(chan_id: int):
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 2bba354

Please sign in to comment.