Skip to content

Commit

Permalink
quickfix
Browse files Browse the repository at this point in the history
  • Loading branch information
valaises committed Dec 20, 2023
1 parent 1c38992 commit d085431
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def robot_human_ratio(robot: int, human: int) -> float:
return 1
if robot == 0:
return 0
return round(robot / robot + human, 2)
return round(robot / (robot + human), 2)


def barplot_rh(
Expand Down
18 changes: 18 additions & 0 deletions self_hosting_machinery/dashboard_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ def fetch_records():
return pd.DataFrame(fetch_records())


def try_get_user_to_team_dict(stats_service: StatisticsService) -> Dict[str, str]:
res = {}
try:
prep = stats_service.session.prepare(
"SELECT * FROM users_access_control"
)
for record in stats_service.session.execute(prep):
res.setdefault(record["account"], record["team"])
except Exception:
pass
return res


def robot_human_df_from_ts(stats_service: StatisticsService, ts: int) -> pd.DataFrame:
prep = stats_service.session.prepare(
"SELECT * FROM telemetry_robot_human WHERE ts_end >= ? ALLOW FILTERING"
Expand Down Expand Up @@ -107,6 +120,7 @@ def retrieve_all_data_tables(stats_service: StatisticsService) -> StatsDataTable
current_year = datetime.now().year
start_of_year = datetime(current_year, 1, 1, 0, 0, 0, 0)
timestamp_start_of_year = int(start_of_year.timestamp())
user_to_team_dict = try_get_user_to_team_dict(stats_service)

extra = {}
network_df = network_df_from_ts(stats_service, timestamp_start_of_year)
Expand All @@ -120,6 +134,10 @@ def retrieve_all_data_tables(stats_service: StatisticsService) -> StatsDataTable
robot_human_df['dt_end'] = pd.to_datetime(robot_human_df['ts_end'], unit='s')
comp_counters_df['dt_end'] = pd.to_datetime(comp_counters_df['ts_end'], unit='s')

network_df['team'] = network_df['tenant_name'].map(lambda x: user_to_team_dict.get(x, "unassigned"))
robot_human_df['team'] = robot_human_df['tenant_name'].map(lambda x: user_to_team_dict.get(x, "unassigned"))
comp_counters_df['team'] = comp_counters_df['tenant_name'].map(lambda x: user_to_team_dict.get(x, "unassigned"))

network_df.sort_values(by='dt_end', inplace=True)
robot_human_df.sort_values(by='dt_end', inplace=True)
comp_counters_df.sort_values(by='dt_end', inplace=True)
Expand Down
8 changes: 4 additions & 4 deletions self_hosting_machinery/webgui/selfhost_fastapi_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async def _secret_key_activate(self):
"human_readable_message": "API key verified",
}

async def _completions(self, post: NlpCompletion, account: str = "XXX"):
async def _completions(self, post: NlpCompletion, account: str = "user"):
ticket = Ticket("comp-")
req = post.clamp()
model_name, err_msg = static_resolve_model(post.model, self._inference_queue)
Expand All @@ -371,7 +371,7 @@ async def _completions(self, post: NlpCompletion, account: str = "XXX"):
media_type=("text/event-stream" if post.stream else "application/json"),
)

async def _contrast(self, post: DiffCompletion, request: Request, account: str = "XXX"):
async def _contrast(self, post: DiffCompletion, request: Request, account: str = "user"):
if post.function != "diff-anywhere":
if post.cursor_file not in post.sources:
raise HTTPException(status_code=400, detail="cursor_file='%s' is not in sources=%s" % (post.cursor_file, list(post.sources.keys())))
Expand Down Expand Up @@ -418,7 +418,7 @@ async def _contrast(self, post: DiffCompletion, request: Request, account: str =
await q.put(ticket)
return StreamingResponse(diff_streamer(ticket, post, self._timeout, req["created"]))

async def _chat(self, post: ChatContext, request: Request, account: str = "XXX"):
async def _chat(self, post: ChatContext, request: Request, account: str = "user"):
ticket = Ticket("comp-")

model_name, err_msg = static_resolve_model(post.model, self._inference_queue)
Expand Down Expand Up @@ -478,7 +478,7 @@ async def _models(self):
"data": data,
}

async def _chat_completions(self, post: ChatContext, account: str = "XXX"):
async def _chat_completions(self, post: ChatContext, account: str = "user"):
prefix, postfix = "data: ", "\n\n"

if post.model in litellm.model_list:
Expand Down
4 changes: 2 additions & 2 deletions self_hosting_machinery/webgui/selfhost_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def _dash_teams_post(self, data: DashTeamsGenDashData):
media_type='application/json',
status_code=500)

async def _telemetry_basic(self, data: TelemetryBasicData, request: Request, account: str = "XXX"):
async def _telemetry_basic(self, data: TelemetryBasicData, request: Request, account: str = "user"):
if not self._stats_service.is_ready:
return self._stats_service_not_available_response

Expand Down Expand Up @@ -175,7 +175,7 @@ async def _telemetry_basic(self, data: TelemetryBasicData, request: Request, acc

return JSONResponse({"retcode": "OK"})

async def _telemetry_snippets(self, data: TelemetryBasicData, request: Request, account: str = "XXX"):
async def _telemetry_snippets(self, data: TelemetryBasicData, request: Request, account: str = "user"):
if not self._stats_service.is_ready:
return self._stats_service_not_available_response

Expand Down

0 comments on commit d085431

Please sign in to comment.