Skip to content

Commit

Permalink
made example working to create task and post feedback w/ api
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhe-log10 committed Feb 12, 2024
1 parent 39e4cc6 commit 173e1ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
18 changes: 15 additions & 3 deletions examples/feedback/create_feedback_task.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"])
6 changes: 3 additions & 3 deletions log10/feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
5 changes: 1 addition & 4 deletions log10/feedback/feedback_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 173e1ad

Please sign in to comment.