feat(api): add INCI tool-calling with normalized tool traces
Enable on-demand INCI retrieval in /routines/suggest through Gemini function calling so detailed ingredient data is fetched only when needed. Persist and normalize tool_trace data in AI logs to make function-call behavior directly inspectable via /ai-logs endpoints.
This commit is contained in:
parent
c0eeb0425d
commit
cfd2485b7e
8 changed files with 455 additions and 29 deletions
44
backend/tests/test_ai_logs.py
Normal file
44
backend/tests/test_ai_logs.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import uuid
|
||||
from typing import Any, cast
|
||||
|
||||
from innercontext.models.ai_log import AICallLog
|
||||
|
||||
|
||||
def test_list_ai_logs_normalizes_tool_trace_string(client, session):
|
||||
log = AICallLog(
|
||||
id=uuid.uuid4(),
|
||||
endpoint="routines/suggest",
|
||||
model="gemini-3-flash-preview",
|
||||
success=True,
|
||||
)
|
||||
log.tool_trace = cast(
|
||||
Any,
|
||||
'{"mode":"function_tools","events":[{"function":"get_product_inci"}]}',
|
||||
)
|
||||
session.add(log)
|
||||
session.commit()
|
||||
|
||||
response = client.get("/ai-logs")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 1
|
||||
assert data[0]["tool_trace"]["mode"] == "function_tools"
|
||||
assert data[0]["tool_trace"]["events"][0]["function"] == "get_product_inci"
|
||||
|
||||
|
||||
def test_get_ai_log_normalizes_tool_trace_string(client, session):
|
||||
log = AICallLog(
|
||||
id=uuid.uuid4(),
|
||||
endpoint="routines/suggest",
|
||||
model="gemini-3-flash-preview",
|
||||
success=True,
|
||||
)
|
||||
log.tool_trace = cast(Any, '{"mode":"function_tools","round":1}')
|
||||
session.add(log)
|
||||
session.commit()
|
||||
|
||||
response = client.get(f"/ai-logs/{log.id}")
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert payload["tool_trace"]["mode"] == "function_tools"
|
||||
assert payload["tool_trace"]["round"] == 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue