Skip to content

Commit

Permalink
fix: Persist call model changes in tools
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Dec 9, 2024
1 parent c942d28 commit cd99824
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
from pydantic import BaseModel, Field, field_validator

from app.helpers.config import CONFIG
from app.helpers.llm_utils import AbstractPlugin
from app.helpers.monitoring import tracer

_FUNC_NAME_SANITIZER_R = r"[^a-zA-Z0-9_-]"
_MESSAGE_ACTION_R = r"(?:action=*([a-z_]*))? *(.*)"
_MESSAGE_STYLE_R = r"(?:style=*([a-z_]*))? *(.*)"

_db = CONFIG.database.instance()


class StyleEnum(str, Enum):
"""
Expand Down Expand Up @@ -99,7 +103,7 @@ def to_openai(self) -> ChatCompletionMessageToolCallParam:
},
)

async def execute_function(self, plugin: object) -> None:
async def execute_function(self, plugin: AbstractPlugin) -> None:
from app.helpers.logging import logger

json_str = self.function_arguments
Expand Down Expand Up @@ -137,7 +141,13 @@ async def execute_function(self, plugin: object) -> None:
},
) as span:
try:
res = await getattr(plugin, name)(**args)
# Persist the call if updating it
async with _db.call_transac(
call=plugin.call,
scheduler=plugin.scheduler,
):
res = await getattr(plugin, name)(**args)
# Format pretty logs
res_log = f"{res[:20]}...{res[-20:]}"
logger.info("Executing function %s (%s): %s", name, args, res_log)
except TypeError as e:
Expand Down

0 comments on commit cd99824

Please sign in to comment.