|
| 1 | +""" |
| 2 | +patching module openai |
| 3 | +- patches function create(...) on Responses class, to inspect response |
| 4 | +- patches function create(...) on Completions class, to inspect response |
| 5 | +""" |
| 6 | + |
| 7 | +from aikido_zen.helpers.on_ai_call import on_ai_call |
| 8 | +from aikido_zen.helpers.register_call import register_call |
| 9 | +from aikido_zen.sinks import on_import, patch_function, after |
| 10 | + |
| 11 | + |
| 12 | +@after |
| 13 | +def _chat_completions_response(func, instance, args, kwargs, return_value): |
| 14 | + op = f"mistralai.agents.Agents.complete" |
| 15 | + register_call(op, "ai_op") |
| 16 | + |
| 17 | + on_ai_call( |
| 18 | + provider="mistralai", |
| 19 | + model=return_value.model, |
| 20 | + input_tokens=return_value.usage.prompt_tokens, |
| 21 | + output_tokens=return_value.usage.completion_tokens, |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +@on_import("mistralai", "mistralai", "1.0.0") |
| 27 | +def patch(m): |
| 28 | + """" |
| 29 | + patching module mistralai |
| 30 | + - patches function agents.Agents.complete, returns ChatCompletionResponse |
| 31 | + - patches function chat.Chat.complete, returns ChatCompletionResponse |
| 32 | + """ |
| 33 | + patch_function(m, "agents.Agents.complete", _chat_completions_response) |
| 34 | + #patch_function(m, "chat.Chat.parse", _chat_completions_response) |
| 35 | + patch_function(m, "chat.Chat.complete", _chat_completions_response) |
| 36 | + patch_function(m, "embeddings.Embeddings.create", _chat_completions_response) |
| 37 | + patch_function(m, "fim.Fim.complete", _chat_completions_response) |
0 commit comments