Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token list , stats in api app.py #1896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
69a1b56
Update wikipedia.py
guoyuhao2330 Jul 15, 2024
6bbb1df
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 15, 2024
4e3067a
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 17, 2024
bc8d5ad
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 17, 2024
678994d
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 17, 2024
268c0c7
Update requirements.txt
guoyuhao2330 Jul 17, 2024
757ca5b
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 18, 2024
dfe71cb
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 18, 2024
7aba129
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 18, 2024
e52e08f
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 19, 2024
c140c70
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 19, 2024
92cf451
Update llm_service.py
guoyuhao2330 Jul 19, 2024
ad5a5b8
Update index.tsx
guoyuhao2330 Jul 19, 2024
4b49bb9
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 22, 2024
12baffc
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 22, 2024
585a0f6
Update init_data.py
guoyuhao2330 Jul 22, 2024
f3b3451
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 25, 2024
31af72c
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 25, 2024
e23f5b5
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 26, 2024
941c29d
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 26, 2024
bace5b5
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 26, 2024
8936941
Merge branch 'infiniflow:main' into main
guoyuhao2330 Jul 29, 2024
4fe66d8
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 2, 2024
3cad1dd
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 5, 2024
4ce659e
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 7, 2024
764de5b
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 8, 2024
addfea5
Update __init__.py
guoyuhao2330 Aug 8, 2024
ab10427
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 9, 2024
898dcbd
Merge branch 'infiniflow:main' into main
guoyuhao2330 Aug 9, 2024
c8f1ea4
Update api_app.py
guoyuhao2330 Aug 9, 2024
a4acbe5
Update api_service.py
guoyuhao2330 Aug 9, 2024
0a79327
Update __init__.py
guoyuhao2330 Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/apps/api_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def token_list():
if not tenants:
return get_data_error_result(retmsg="Tenant not found!")

objs = APITokenService.query(tenant_id=tenants[0].tenant_id, dialog_id=request.args["dialog_id"])
id = request.args.get("dialog_id", request.args["canvas_id"])
objs = APITokenService.query(tenant_id=tenants[0].tenant_id, dialog_id=id)
return get_json_result(data=[o.to_dict() for o in objs])
except Exception as e:
return server_error_response(e)
Expand Down Expand Up @@ -123,7 +124,8 @@ def stats():
days=7)).strftime("%Y-%m-%d 24:00:00")),
request.args.get(
"to_date",
datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
"agent" if request.args.get("canvas_id") else None)
res = {
"pv": [(o["dt"], o["pv"]) for o in objs],
"uv": [(o["dt"], o["uv"]) for o in objs],
Expand Down
5 changes: 3 additions & 2 deletions api/db/services/api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def append_message(cls, id, conversation):

@classmethod
@DB.connection_context()
def stats(cls, tenant_id, from_date, to_date):
def stats(cls, tenant_id, from_date, to_date, source=None):
return cls.model.select(
cls.model.create_date.truncate("day").alias("dt"),
peewee.fn.COUNT(
Expand All @@ -62,5 +62,6 @@ def stats(cls, tenant_id, from_date, to_date):
cls.model.thumb_up).alias("thumb_up")
).join(Dialog, on=(cls.model.dialog_id == Dialog.id & Dialog.tenant_id == tenant_id)).where(
cls.model.create_date >= from_date,
cls.model.create_date <= to_date
cls.model.create_date <= to_date,
cls.model.source == source
).group_by(cls.model.create_date.truncate("day")).dicts()
9 changes: 7 additions & 2 deletions rag/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ def findMaxTm(fnm):

encoder = tiktoken.encoding_for_model("gpt-3.5-turbo")


def num_tokens_from_string(string: str) -> int:
"""Returns the number of tokens in a text string."""
num_tokens = len(encoder.encode(string))
return num_tokens
try:
num_tokens = len(encoder.encode(string))
return num_tokens
except Exception as e:
pass
return 0


def truncate(string: str, max_len: int) -> int:
Expand Down