* Handle case where embeddings overflow token limit

* Set notification tokens

* Fix sort
This commit is contained in:
Nicolas Mowen 2024-10-15 07:17:54 -06:00 committed by GitHub
parent 0abd514064
commit 0eccb6a610
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -357,6 +357,7 @@ def create_user(request: Request, body: AppPostUsersBody):
{ {
User.username: body.username, User.username: body.username,
User.password_hash: password_hash, User.password_hash: password_hash,
User.notification_tokens: [],
} }
).execute() ).execute()
return JSONResponse(content={"username": body.username}) return JSONResponse(content={"username": body.username})

View File

@ -6,6 +6,7 @@ import logging
import os import os
import time import time
import onnxruntime as ort
from numpy import ndarray from numpy import ndarray
from PIL import Image from PIL import Image
from playhouse.shortcuts import model_to_dict from playhouse.shortcuts import model_to_dict
@ -174,7 +175,16 @@ class Embeddings:
return embedding return embedding
def batch_upsert_description(self, event_descriptions: dict[str, str]) -> ndarray: def batch_upsert_description(self, event_descriptions: dict[str, str]) -> ndarray:
embeddings = self.text_embedding(list(event_descriptions.values())) descs = list(event_descriptions.values())
try:
embeddings = self.text_embedding(descs)
except ort.RuntimeException:
half_size = len(descs) / 2
embeddings = []
embeddings.extend(self.text_embedding(descs[0:half_size]))
embeddings.extend(self.text_embedding(descs[half_size:]))
ids = list(event_descriptions.keys()) ids = list(event_descriptions.keys())
items = [] items = []