#1128 | Remove deprecated type hints from typing module (#1131)

This commit is contained in:
Sandra Serrano
2024-01-09 18:35:24 +01:00
committed by GitHub
parent c9df7a2020
commit 0de9491c61
41 changed files with 272 additions and 267 deletions

View File

@@ -2,7 +2,7 @@ import json
import logging
import sqlite3
import uuid
from typing import Any, Dict, List, Optional
from typing import Any, Optional
from embedchain.constants import SQLITE_PATH
from embedchain.memory.message import ChatMessage
@@ -67,7 +67,7 @@ class ChatHistory:
self.cursor.execute(DELETE_CHAT_HISTORY_QUERY, (app_id, session_id))
self.connection.commit()
def get(self, app_id, session_id, num_rounds=10, display_format=False) -> List[ChatMessage]:
def get(self, app_id, session_id, num_rounds=10, display_format=False) -> list[ChatMessage]:
"""
Get the most recent num_rounds rounds of conversations
between human and AI, for a given app_id.
@@ -114,7 +114,7 @@ class ChatHistory:
return count
@staticmethod
def _serialize_json(metadata: Dict[str, Any]):
def _serialize_json(metadata: dict[str, Any]):
return json.dumps(metadata)
@staticmethod

View File

@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, Optional
from typing import Any, Optional
from embedchain.helpers.json_serializable import JSONSerializable
@@ -18,9 +18,9 @@ class BaseMessage(JSONSerializable):
created_by: str
# Any additional info.
metadata: Dict[str, Any]
metadata: dict[str, Any]
def __init__(self, content: str, created_by: str, metadata: Optional[Dict[str, Any]] = None) -> None:
def __init__(self, content: str, created_by: str, metadata: Optional[dict[str, Any]] = None) -> None:
super().__init__()
self.content = content
self.created_by = created_by

View File

@@ -1,16 +1,16 @@
from typing import Any, Dict, Optional
from typing import Any, Optional
def merge_metadata_dict(left: Optional[Dict[str, Any]], right: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
def merge_metadata_dict(left: Optional[dict[str, Any]], right: Optional[dict[str, Any]]) -> Optional[dict[str, Any]]:
"""
Merge the metadatas of two BaseMessage types.
Args:
left (Dict[str, Any]): metadata of human message
right (Dict[str, Any]): metadata of AI message
left (dict[str, Any]): metadata of human message
right (dict[str, Any]): metadata of AI message
Returns:
Dict[str, Any]: combined metadata dict with dedup
dict[str, Any]: combined metadata dict with dedup
to be saved in db.
"""
if not left and not right: