(duration, provider, model, input_tokens, service, purpose, session_id=None)
| 48 | |
| 49 | @failsoft |
| 50 | def log_apicall_failure(duration, provider, model, input_tokens, service, purpose, session_id=None): |
| 51 | if not EVENTS_ENGINE: |
| 52 | return {"status": "no engine"} |
| 53 | |
| 54 | params = { |
| 55 | "duration": duration, |
| 56 | "provider": provider, |
| 57 | "model": model, |
| 58 | "input_tokens": input_tokens, |
| 59 | "output_tokens": 0, |
| 60 | "service": service, |
| 61 | "purpose": purpose, |
| 62 | "cost": 0, |
| 63 | "success": "false", |
| 64 | "session_id": session_id, |
| 65 | } |
| 66 | |
| 67 | insert_query = text(""" |
| 68 | INSERT INTO apicalls (duration, provider, model, input_tokens, output_tokens, service, purpose, cost, success, session_id) |
| 69 | VALUES (:duration, :provider, :model, :input_tokens, :output_tokens, :service, :purpose, :cost, :success, :session_id) |
| 70 | """) |
| 71 | |
| 72 | with EVENTS_ENGINE.connect() as conn: |
| 73 | conn.execute(insert_query, params) |
| 74 | conn.commit() |
| 75 | |
| 76 | return {"status": "success"} |
| 77 | |
| 78 | |
| 79 |
nothing calls this directly
no outgoing calls
no test coverage detected