forked from open-webui/open-webui
		
	fix: chat model schema
This commit is contained in:
		
							parent
							
								
									8d5c3ee56f
								
							
						
					
					
						commit
						6350d86bde
					
				
					 2 changed files with 21 additions and 17 deletions
				
			
		|  | @ -98,21 +98,23 @@ class AuthsTable: | ||||||
| 
 | 
 | ||||||
|     def authenticate_user(self, email: str, password: str) -> Optional[UserModel]: |     def authenticate_user(self, email: str, password: str) -> Optional[UserModel]: | ||||||
|         print("authenticate_user", email) |         print("authenticate_user", email) | ||||||
|  |         try: | ||||||
|  |             auth = Auth.get(Auth.email == email, Auth.active == True) | ||||||
|  |             print(auth.email) | ||||||
| 
 | 
 | ||||||
|         auth = Auth.get(Auth.email == email, Auth.active == True) |             if auth: | ||||||
|         print(auth.email) |                 print(password, str(auth.password)) | ||||||
|  |                 print(verify_password(password, str(auth.password))) | ||||||
|  |                 if verify_password(password, auth.password): | ||||||
|  |                     user = Users.get_user_by_id(auth.id) | ||||||
| 
 | 
 | ||||||
|         if auth: |                     print(user) | ||||||
|             print(password, str(auth.password)) |                     return user | ||||||
|             print(verify_password(password, str(auth.password))) |                 else: | ||||||
|             if verify_password(password, auth.password): |                     return None | ||||||
|                 user = Users.get_user_by_id(auth.id) |  | ||||||
| 
 |  | ||||||
|                 print(user) |  | ||||||
|                 return user |  | ||||||
|             else: |             else: | ||||||
|                 return None |                 return None | ||||||
|         else: |         except: | ||||||
|             return None |             return None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ from apps.web.internal.db import DB | ||||||
| 
 | 
 | ||||||
| class Chat(Model): | class Chat(Model): | ||||||
|     id = CharField(unique=True) |     id = CharField(unique=True) | ||||||
|     user_id: CharField() |     user_id = CharField() | ||||||
|     title = CharField() |     title = CharField() | ||||||
|     chat = TextField()  # Save Chat JSON as Text |     chat = TextField()  # Save Chat JSON as Text | ||||||
|     timestamp = DateField() |     timestamp = DateField() | ||||||
|  | @ -31,7 +31,7 @@ class ChatModel(BaseModel): | ||||||
|     id: str |     id: str | ||||||
|     user_id: str |     user_id: str | ||||||
|     title: str |     title: str | ||||||
|     chat: dict |     chat: str | ||||||
|     timestamp: int  # timestamp in epoch |     timestamp: int  # timestamp in epoch | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -64,8 +64,10 @@ class ChatTable: | ||||||
|             **{ |             **{ | ||||||
|                 "id": id, |                 "id": id, | ||||||
|                 "user_id": user_id, |                 "user_id": user_id, | ||||||
|                 "title": form_data.chat["title"], |                 "title": form_data.chat["title"] | ||||||
|                 "chat": json.dump(form_data.chat), |                 if "title" in form_data.chat | ||||||
|  |                 else "New Chat", | ||||||
|  |                 "chat": json.dumps(form_data.chat), | ||||||
|                 "timestamp": int(time.time()), |                 "timestamp": int(time.time()), | ||||||
|             } |             } | ||||||
|         ) |         ) | ||||||
|  | @ -75,7 +77,7 @@ class ChatTable: | ||||||
| 
 | 
 | ||||||
|     def update_chat_by_id(self, id: str, chat: dict) -> Optional[ChatModel]: |     def update_chat_by_id(self, id: str, chat: dict) -> Optional[ChatModel]: | ||||||
|         try: |         try: | ||||||
|             query = Chat.update(chat=json.dump(chat)).where(Chat.id == id) |             query = Chat.update(chat=json.dumps(chat)).where(Chat.id == id) | ||||||
|             query.execute() |             query.execute() | ||||||
| 
 | 
 | ||||||
|             chat = Chat.get(Chat.id == id) |             chat = Chat.get(Chat.id == id) | ||||||
|  | @ -88,7 +90,7 @@ class ChatTable: | ||||||
|     ) -> List[ChatModel]: |     ) -> List[ChatModel]: | ||||||
|         return [ |         return [ | ||||||
|             ChatModel(**model_to_dict(chat)) |             ChatModel(**model_to_dict(chat)) | ||||||
|             for chat in Chat.select(Chat.id, Chat.title) |             for chat in Chat.select() | ||||||
|             .where(Chat.user_id == user_id) |             .where(Chat.user_id == user_id) | ||||||
|             .limit(limit) |             .limit(limit) | ||||||
|             .offset(skip) |             .offset(skip) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek