diff --git a/examples/feedback/create_feedback_task.py b/examples/feedback/create_feedback_task.py index 35b8c3ba..967ac524 100644 --- a/examples/feedback/create_feedback_task.py +++ b/examples/feedback/create_feedback_task.py @@ -1,5 +1,8 @@ import logging +from pydantic import BaseModel, Field +from typing import Literal from log10.feedback.feedback_task import FeedbackTask +from log10.feedback.feedback import Feedback httpx_logger = logging.getLogger("httpx") httpx_logger.setLevel(logging.DEBUG) @@ -14,7 +17,16 @@ } } } +class EmojiFeedback(BaseModel): + feedback: Literal["😀", "🙁"] = Field(..., description="User feedback with emojis") + +eft = EmojiFeedback(feedback="😀") + # convert t_s to json -import json -t_s = json.dumps(t_s) -task = feedback_task.create(name="emo", task_schema=t_s) +task = feedback_task.create(name="emo", task_schema=eft.model_json_schema()) +task_dump = task.json() +print(task_dump["id"]) + +fb = Feedback() +print(eft.model_dump_json()) +fb.create(task_id=task_dump["id"], rate=eft.model_dump(), completion_tags_selector=["give_me_feedback"]) \ No newline at end of file diff --git a/log10/feedback/feedback.py b/log10/feedback/feedback.py index e021151a..df95a8a5 100644 --- a/log10/feedback/feedback.py +++ b/log10/feedback/feedback.py @@ -27,7 +27,7 @@ class Feedback: - feedback_create_url = "/api/v1/feedback" + feedback_create_url = "api/v1/feedback" def __init__(self, log10_config: Log10Config = None): self._log10_config = log10_config or Log10Config() @@ -44,14 +44,14 @@ def _post_request(self, url: str, json_payload: dict) -> httpx.Response: logger.error(e) raise - def create(self, task_id: str, rate: dict) -> httpx.Response: + def create(self, task_id: str, rate: dict, completion_tags_selector: list[str], comment: str = None) -> httpx.Response: """ Example: >>> from log10.feedback import Feedback >>> fb = Feedback() >>> fb.create(task_id="task_id", rate={...}) """ - json_payload = {"task_id": task_id, "rate": rate} + json_payload = {"task_id": task_id, "json_values": rate, "completion_tags_selector": completion_tags_selector} res = self._post_request(self.feedback_create_url, json_payload) return res diff --git a/log10/feedback/feedback_task.py b/log10/feedback/feedback_task.py index d2319d5b..8990002c 100644 --- a/log10/feedback/feedback_task.py +++ b/log10/feedback/feedback_task.py @@ -29,9 +29,6 @@ def _post_request(self, url: str, json_payload: dict) -> httpx.Response: headers = {"x-log10-token": self._log10_config.token, "Content-Type": "application/json", "x-log10-organization": self._log10_config.org_id} json_payload["organization_id"] = self._log10_config.org_id try: - from pprint import pprint - pprint(f"{headers=}") - pprint(f"{json_payload=}") res = self._http_client.post(self._log10_config.url + url, headers=headers, json=json_payload) res.raise_for_status() return res @@ -46,7 +43,7 @@ def create(self, task_schema: dict, name: str = None, instruction: str = None) - >>> feedback_task = FeedbackTask() >>> task = feedback_task.create(name="summarization", task_schema={...}) """ - json_payload = {"task_schema": task_schema} + json_payload = {"json_schema": task_schema} if name: json_payload["name"] = name if instruction: