HumeraR commited on
Commit
e637380
·
1 Parent(s): 89250ee

refactor: improve chat sorting logic in NotebookView component for better handling of timestamps

Browse files
backend/app/support/corpus.py CHANGED
@@ -73,16 +73,20 @@ def _plans_doc() -> Doc:
73
  if p.price_monthly_usd:
74
  monthly, yearly = annual_prices(p)
75
  price += f", or ${monthly:g} a month billed yearly (${yearly:g} a year)"
76
- kits = "unlimited" if p.launch_kits < 0 else str(p.launch_kits)
77
- reports = "unlimited" if p.reports < 0 else str(p.reports)
78
- infographics = "unlimited" if p.infographics < 0 else str(p.infographics)
 
 
 
 
79
  lines += [
80
  f"## {p.name}",
81
  f"{p.tagline}. Price: {price}.",
82
- f"Limits: {p.sources} sources, {p.indexed_posts} indexed posts, "
83
- f"{p.audio_minutes} minutes of audio a month, "
84
- f"{p.videos} videos {'a month' if p.videos_monthly else 'in total'}, {kits} Launch Kits a month, "
85
- f"{reports} reports a month, {infographics} infographics a month. "
86
  f"Voice cloning: {'yes' if p.voice_cloning else 'no'}.",
87
  "Includes: " + "; ".join(p.features) + ".",
88
  ]
 
73
  if p.price_monthly_usd:
74
  monthly, yearly = annual_prices(p)
75
  price += f", or ${monthly:g} a month billed yearly (${yearly:g} a year)"
76
+ per = "in total, never renewing," if p.lifetime else "a month"
77
+
78
+ def count(n: int) -> str:
79
+ return "unlimited" if n < 0 else str(n)
80
+
81
+ audio = f"{count(p.audio_overviews)} audio overviews in total, any length" if p.audio_overviews >= 0 \
82
+ else f"{p.audio_minutes} minutes of audio a month"
83
  lines += [
84
  f"## {p.name}",
85
  f"{p.tagline}. Price: {price}.",
86
+ f"Limits: {p.sources} sources, {p.indexed_posts} indexed posts across every source, {audio}, "
87
+ f"{p.videos} videos {'a month' if p.videos_monthly else 'in total, never renewing'}, "
88
+ f"{count(p.launch_kits)} Launch Kits {per}, {count(p.infographics)} infographics {per}, "
89
+ f"{count(p.reports)} reports a month. "
90
  f"Voice cloning: {'yes' if p.voice_cloning else 'no'}.",
91
  "Includes: " + "; ".join(p.features) + ".",
92
  ]
backend/app/support/scope.py CHANGED
@@ -46,6 +46,10 @@ _ABOUT_MY_DATA = re.compile(
46
  | \b(?:recap|remind\s+me|repeat)\b[^.?!]{{0,40}}\b(?:chat|conversation|discussion|said|discussed)\b
47
  """
48
  )
 
 
 
 
49
  # Words that mean something went wrong with their work; the reply also offers the human form.
50
  _BROKEN = re.compile(
51
  r"(?i)\b(?:fail\w*|slow|forever|too\s+long|taking\s+(?:so\s+|way\s+)?long|hang\w*"
@@ -65,6 +69,8 @@ def about_user_data(message: str) -> bool:
65
  text = message.strip()
66
  if _HOWTO.match(text) and not re.search(r"(?i)\b(?:i|we)\s+(?:wrote|said|posted|published)\b", text):
67
  return False
 
 
68
  return bool(_ABOUT_MY_DATA.search(text))
69
 
70
 
 
46
  | \b(?:recap|remind\s+me|repeat)\b[^.?!]{{0,40}}\b(?:chat|conversation|discussion|said|discussed)\b
47
  """
48
  )
49
+ # A question about what the plans include ("How many Launch Kits do I get on each plan?") is product help, not about the
50
+ # writer's own content, unless it also asks what they have made or hold.
51
+ _PLAN_WORDS = re.compile(r"(?i)\b(?:plans?|tiers?|pricing|prices?|free|writer|studio|allowance|limits?|upgrade|subscription)\b")
52
+ _OWN_STATE = re.compile(r"(?i)\b(?:i\s+have|have\s+i|did\s+i|i\s+(?:wrote|made|created|used|posted|published))\b")
53
  # Words that mean something went wrong with their work; the reply also offers the human form.
54
  _BROKEN = re.compile(
55
  r"(?i)\b(?:fail\w*|slow|forever|too\s+long|taking\s+(?:so\s+|way\s+)?long|hang\w*"
 
69
  text = message.strip()
70
  if _HOWTO.match(text) and not re.search(r"(?i)\b(?:i|we)\s+(?:wrote|said|posted|published)\b", text):
71
  return False
72
+ if _PLAN_WORDS.search(text) and not _OWN_STATE.search(text) and not re.search(rf"(?i)\bmy\s+(?:[\w'-]+\s+){{0,3}}{_MINE}\b", text):
73
+ return False
74
  return bool(_ABOUT_MY_DATA.search(text))
75
 
76
 
frontend/src/pages/NotebookView.tsx CHANGED
@@ -42,8 +42,9 @@ function groupChats(chats: ChatSummary[]): { label: string; items: ChatSummary[]
42
  const startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
43
  const today = startOfDay(new Date());
44
  const groups: { label: string; items: ChatSummary[] }[] = [];
45
- [...chats].sort((a, b) => +new Date(b.updated_at) - +new Date(a.updated_at)).forEach((c) => {
46
- const when = new Date(c.updated_at);
 
47
  const days = Math.round((today - startOfDay(when)) / 86400000);
48
  const label = days <= 0 ? "Today" : days === 1 ? "Yesterday" : days <= 7 ? "Previous 7 days" : days <= 30 ? "Previous 30 days"
49
  : when.toLocaleDateString(undefined, { month: "long", year: "numeric" });
 
42
  const startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
43
  const today = startOfDay(new Date());
44
  const groups: { label: string; items: ChatSummary[] }[] = [];
45
+ const stamp = (c: ChatSummary) => (c.updated_at ? new Date(c.updated_at) : new Date()); // a chat with no time yet is brand new
46
+ [...chats].sort((a, b) => +stamp(b) - +stamp(a)).forEach((c) => {
47
+ const when = stamp(c);
48
  const days = Math.round((today - startOfDay(when)) / 86400000);
49
  const label = days <= 0 ? "Today" : days === 1 ? "Yesterday" : days <= 7 ? "Previous 7 days" : days <= 30 ? "Previous 30 days"
50
  : when.toLocaleDateString(undefined, { month: "long", year: "numeric" });