Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions effectful/handlers/llm/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
from effectful.ops.syntax import ObjectInterpretation, defop, implements
from effectful.ops.types import Operation

try:
import weave
except ImportError:
weave = None # type: ignore


class _OpenAIPromptFormatter(string.Formatter):
def format_as_messages(
Expand Down Expand Up @@ -419,6 +424,15 @@ def _completion(self, *args, **kwargs):
def _call[**P, T](
self, template: Template[P, T], *args: P.args, **kwargs: P.kwargs
) -> T:
model_input = format_model_input(template, *args, **kwargs)
resp = compute_response(template, model_input)
return decode_response(template, resp)
op: Callable = lambda f: f
if weave:
op = weave.op

@op
@functools.wraps(template)
def wrapper(*args, **kwargs):
model_input = format_model_input(template, *args, **kwargs)
resp = compute_response(template, model_input)
return decode_response(template, resp)

return wrapper(*args, **kwargs)
Loading