-
Notifications
You must be signed in to change notification settings - Fork 0
property embeddings #5
base: main
Are you sure you want to change the base?
Changes from all commits
74cf3c5
e9941ad
d2e4e2e
c5ec3ea
12221c9
8343d3c
0036b2c
173b9b2
c9ef9ed
c933c58
263758b
8a0e6cd
a60887d
43cdcae
b4f1a51
142a44e
9f245a0
87cb1cf
961f582
4cbb47a
36116e6
5db4e0c
bf19a84
026c65c
f2ee374
0e98879
a3b864f
ac7e137
8ace5a8
a9f92c4
18744d2
89b2d47
f14087a
ef37855
c24d210
f1fdbdb
2953dbc
cf279f5
182ecba
b7e7425
52c40cb
10e76cd
923502a
739479a
9acaa96
86e6098
b27d925
765e93f
b5f31ff
50ec338
7d9d67c
c918e73
7b7260a
3754211
7a2cf2b
7b3e5e2
cb31b35
9778c37
cf6d2e4
eb5e9f1
e75f68f
4aa1a4d
7b7c6d2
31bf971
a0e460c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||
| # Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||||
| # or more contributor license agreements. See the NOTICE file | ||||||||||||||||||
| # distributed with this work for additional information | ||||||||||||||||||
| # regarding copyright ownership. The ASF licenses this file | ||||||||||||||||||
| # to you under the Apache License, Version 2.0 (the | ||||||||||||||||||
| # "License"); you may not use this file except in compliance | ||||||||||||||||||
| # with the License. You may obtain a copy of the License at | ||||||||||||||||||
| # | ||||||||||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||
| # | ||||||||||||||||||
| # Unless required by applicable law or agreed to in writing, | ||||||||||||||||||
| # software distributed under the License is distributed on an | ||||||||||||||||||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||
| # KIND, either express or implied. See the License for the | ||||||||||||||||||
| # specific language governing permissions and limitations | ||||||||||||||||||
| # under the License. | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| from datetime import date | ||||||||||||||||||
| from typing import Optional | ||||||||||||||||||
|
|
||||||||||||||||||
| from fastapi import status, APIRouter, HTTPException, Body | ||||||||||||||||||
|
|
||||||||||||||||||
| from hugegraph_llm.utils.log import log | ||||||||||||||||||
| from hugegraph_llm.api.models.rag_requests import GraphConfigRequest | ||||||||||||||||||
| from hugegraph_llm.config import huge_settings | ||||||||||||||||||
|
|
||||||||||||||||||
| API_CALL_TRACKER = {} | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| # pylint: disable=too-many-statements | ||||||||||||||||||
MrJs133 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| def vector_http_api(router: APIRouter, update_embedding_func): | ||||||||||||||||||
| @router.post("/vector/embedding", status_code=status.HTTP_200_OK) | ||||||||||||||||||
| def update_embedding_api( | ||||||||||||||||||
| daily_limit: int = 50, | ||||||||||||||||||
| graph_config: Optional[GraphConfigRequest] = Body(None) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修复函数参数默认值中的可变对象问题 在函数参数默认值中使用 应用此修改来修复问题: def update_embedding_api(
daily_limit: int = 50,
- graph_config: Optional[GraphConfigRequest] = Body(None)
+ graph_config: Optional[GraphConfigRequest] = None
):
+ if graph_config is None:
+ graph_config = Body(None)或者更好的做法是在函数签名中移除默认值: def update_embedding_api(
daily_limit: int = 50,
- graph_config: Optional[GraphConfigRequest] = Body(None)
+ graph_config: Optional[GraphConfigRequest] = Body(default=None)
):📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.11.9)36-36: Do not perform function call (B008) 🤖 Prompt for AI Agents |
||||||||||||||||||
| ): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Updates the vector embedding. | ||||||||||||||||||
| This endpoint is rate-limited. By default, it allows 2 calls per day. (Note: Not Thread-Safe!) | ||||||||||||||||||
| The rate limit is tracked per day and resets at midnight. | ||||||||||||||||||
| """ | ||||||||||||||||||
| today = date.today() | ||||||||||||||||||
| for call_date in list(API_CALL_TRACKER.keys()): | ||||||||||||||||||
| if call_date != today: | ||||||||||||||||||
| del API_CALL_TRACKER[call_date] | ||||||||||||||||||
| call_count = API_CALL_TRACKER.get(today, 0) | ||||||||||||||||||
| if call_count >= daily_limit: | ||||||||||||||||||
| log.error("Rate limit exceeded for update_vid_embedding. Maximum %d calls per day.", daily_limit) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正日志消息中的函数名称。 日志消息中的函数名称 应用此修改来修正函数名称: -log.error("Rate limit exceeded for update_vid_embedding. Maximum %d calls per day.", daily_limit)
+log.error("Rate limit exceeded for update_embedding_api. Maximum %d calls per day.", daily_limit)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| raise HTTPException( | ||||||||||||||||||
| status_code=status.HTTP_429_TOO_MANY_REQUESTS, | ||||||||||||||||||
| detail=f"API call limit of {daily_limit} per day exceeded. Please try again tomorrow." | ||||||||||||||||||
| ) | ||||||||||||||||||
| API_CALL_TRACKER[today] = call_count + 1 | ||||||||||||||||||
| if graph_config: | ||||||||||||||||||
| huge_settings.graph_url = graph_config.url | ||||||||||||||||||
| huge_settings.graph_name = graph_config.graph | ||||||||||||||||||
| huge_settings.graph_user = graph_config.user | ||||||||||||||||||
| huge_settings.graph_pwd = graph_config.pwd | ||||||||||||||||||
| huge_settings.graph_space = graph_config.gs | ||||||||||||||||||
| huge_settings.graph_token = graph_config.token | ||||||||||||||||||
|
|
||||||||||||||||||
| result = update_embedding_func() | ||||||||||||||||||
| result = {"detail": result} | ||||||||||||||||||
| return result | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.