diff --git a/examples/feedback/create_feedback_task.py b/examples/feedback/create_feedback_task.py deleted file mode 100644 index 967ac524..00000000 --- a/examples/feedback/create_feedback_task.py +++ /dev/null @@ -1,32 +0,0 @@ -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) - -feedback_task = FeedbackTask() -t_s = { - "type": "object", - "properties": { - "feedback": { - "type": "string", - "enum": ["😀", "😬", "😐", "🙁", "😫"] - } - } -} -class EmojiFeedback(BaseModel): - feedback: Literal["😀", "🙁"] = Field(..., description="User feedback with emojis") - -eft = EmojiFeedback(feedback="😀") - -# convert t_s to json -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/examples/feedback/simple_feedback.py b/examples/feedback/simple_feedback.py index 9a57d43e..fc4c9888 100644 --- a/examples/feedback/simple_feedback.py +++ b/examples/feedback/simple_feedback.py @@ -1,3 +1,4 @@ +import uuid from pprint import pprint from typing import Literal @@ -8,11 +9,14 @@ from log10.load import OpenAI -class EmojiFeedback(BaseModel): - feedback: Literal["😀", "🙁"] = Field(..., description="User feedback with emojis") - +# +# use log10 to log an openai completion +# -client = OpenAI() +# create a unique id +unique_id = str(uuid.uuid4()) +print(f"Use tag: {unique_id}") +client = OpenAI(tags=[unique_id]) completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ @@ -26,13 +30,23 @@ class EmojiFeedback(BaseModel): }, ], ) -completion_id = completion.choices[0].id - -task = FeedbackTask() -res = task.create(name="emoji_feedback_task", task_schema=EmojiFeedback.model_json_schema()) -task_id = res["id"] -pprint(task) -# Example usage -fb = Feedback() -res = fb.create(task_id=task_id, data=EmojiFeedback(feedback="😀").model_dump_json(), completion_tags_selector=[str(completion_id)]) -pprint(res) +print(completion.choices[0].message) + +# +# add feedback to the completion +# + + +# define a feedback task +class EmojiFeedback(BaseModel): + feedback: Literal["😀", "🙁"] = Field(..., description="User feedback with emojis") + + +# create a feedback +fb = EmojiFeedback(feedback="😀") + +task = FeedbackTask().create(name="emoji_task_test", task_schema=fb.model_json_schema()) +task_dump = task.json() + +print(fb.model_dump_json()) +Feedback().create(task_id=task_dump["id"], values=fb.model_dump(), completion_tags_selector=[unique_id])