Skip to content

Commit

Permalink
feat: Updated agents-api/agents_api/models/entry/a
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Apr 13, 2024
1 parent 4199c15 commit f254bed
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions agents-api/agents_api/models/entry/add_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
def add_entries_query(
entries: list[Entry], client: CozoClient = client
) -> pd.DataFrame:
"""
Adds a list of Entry objects and a CozoClient object to a pandas DataFrame.
Parameters:
entries (list[Entry]): A list of Entry objects to be processed.
client (CozoClient): The CozoClient object used for database operations.
Returns:
pd.DataFrame: A DataFrame containing the entries data ready for insertion into the 'cozodb' database.
"""
# Iterate over each entry in the provided list, processing them for database insertion.
entries_lst = []

for e in entries:
ts = utcnow().timestamp()
source = e.source
role = e.role
# Convert the content of each entry to a string, serializing JSON objects.
content: str = (
e.content if isinstance(e.content, str) else json.dumps(e.content)
)
# Append entries with non-empty content to the list for database insertion.
if e.content:
entries_lst.append(
[
Expand All @@ -35,9 +48,12 @@ def add_entries_query(
]
)

# If no entries are provided or all entries have empty content, return an empty DataFrame.
if not len(entries_lst):
return pd.DataFrame(data={})

# Construct a datalog query to insert the processed entries into the 'cozodb' database.
# Refer to the schema for the 'entries' relation in the README.md for column names and types.
query = """
{
?[entry_id, session_id, source, role, name, content, token_count, tokenizer, created_at, timestamp] <- $entries_lst
Expand Down

0 comments on commit f254bed

Please sign in to comment.