Skip to content

Commit

Permalink
Remove bunch of tests and save_history
Browse files Browse the repository at this point in the history
  • Loading branch information
WonderPG committed Jan 9, 2025
1 parent 8f6c6dc commit 8a8bcf4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 387 deletions.
47 changes: 1 addition & 46 deletions src/neuroagent/app/database/db_utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
"""Utilities for the agent's database."""

import json
from typing import Annotated, Any
from typing import Annotated

from fastapi import Depends, HTTPException
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from neuroagent.app.database.sql_schemas import (
Entity,
Messages,
Threads,
ToolCalls,
utc_now,
)
from neuroagent.app.dependencies import get_session, get_user_id
from neuroagent.utils import get_entity


async def get_thread(
Expand All @@ -38,42 +32,3 @@ async def get_thread(
},
)
return thread


async def save_history(
history: list[dict[str, Any]],
offset: int,
thread: Threads,
session: AsyncSession,
) -> None:
"""Add the new messages in the database."""
for i, message in enumerate(history):
tool_calls = []
entity = get_entity(message)
if entity == Entity.AI_TOOL:
# If AI_TOOL, create separate ToolCall entries in DB and remove it from content
tool_calls = [
ToolCalls(
tool_call_id=tool_call["id"],
name=tool_call["function"]["name"],
arguments=json.dumps(tool_call["function"]["arguments"]),
)
for tool_call in message["tool_calls"]
]
message.pop("tool_calls")

new_msg = Messages(
order=i + offset,
thread_id=thread.thread_id,
entity=entity,
content=json.dumps(message),
tool_calls=tool_calls,
)
session.add(new_msg)

# we need to update the thread update time
thread.update_date = utc_now()
await session.commit()


# db_messages: list[Messages] = await thread.awaitable_attrs.messages
2 changes: 1 addition & 1 deletion src/neuroagent/app/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import BaseModel

from neuroagent.app.database.db_utils import Entity
from neuroagent.app.database.sql_schemas import Entity


class ThreadsRead(BaseModel):
Expand Down
Loading

0 comments on commit 8a8bcf4

Please sign in to comment.