Skip to content

Commit

Permalink
wip stash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhe-log10 committed Feb 12, 2024
1 parent c42a2e5 commit 39e4cc6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 9 deletions.
20 changes: 20 additions & 0 deletions examples/feedback/create_feedback_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
from log10.feedback.feedback_task import FeedbackTask

httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.DEBUG)

feedback_task = FeedbackTask()
t_s = {
"type": "object",
"properties": {
"feedback": {
"type": "string",
"enum": ["😀", "😬", "😐", "🙁", "😫"]
}
}
}
# convert t_s to json
import json
t_s = json.dumps(t_s)
task = feedback_task.create(name="emo", task_schema=t_s)
38 changes: 38 additions & 0 deletions examples/feedback/simple_feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pprint import pprint
from typing import Literal

from pydantic import BaseModel, Field

from log10.feedback.feedback import Feedback
from log10.feedback.feedback_task import FeedbackTask
from log10.load import OpenAI


class EmojiFeedback(BaseModel):
feedback: Literal["😀", "🙁"] = Field(..., description="User feedback with emojis")


client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are the most knowledgable Star Wars guru on the planet",
},
{
"role": "user",
"content": "Write the time period of all the Star Wars movies and spinoffs?",
},
],
)
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)
4 changes: 0 additions & 4 deletions log10/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ def feedback_task():

if __name__ == "__main__":
cli()


# cli.add_command(feedback.create_feedback)
# cli.add_command(feedback_task.create_feedback_task)
2 changes: 1 addition & 1 deletion log10/feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, log10_config: Log10Config = None):
self._http_client = httpx.Client()

def _post_request(self, url: str, json_payload: dict) -> httpx.Response:
headers = {"x-log10-token": self._log10_config.token, "Content-Type": "application/json"}
headers = {"x-log10-token": self._log10_config.token, "x-log10-organization": self._log10_config.org_id, "Content-Type": "application/json"}
json_payload["organization_id"] = self._log10_config.org_id
try:
res = self._http_client.post(self._log10_config.url + url, headers=headers, json=json_payload)
Expand Down
17 changes: 13 additions & 4 deletions log10/feedback/feedback_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,41 @@
logger.setLevel(logging.INFO)



class FeedbackTask:
feedback_task_create_url = "/api/v1/feedback_task"
feedback_task_create_url = "api/v1/feedback_task"

def __init__(self, log10_config: Log10Config = None):
self._log10_config = log10_config or Log10Config()
self._http_client = httpx.Client()

def _post_request(self, url: str, json_payload: dict) -> httpx.Response:
headers = {"x-log10-token": self._log10_config.token, "Content-Type": "application/json"}
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
except Exception as e:
logger.error(e)
raise

def create(self, name: str, task_schema: dict) -> httpx.Response:
def create(self, task_schema: dict, name: str = None, instruction: str = None) -> httpx.Response:
"""
Example:
>>> from log10.feedback.feedback_task import FeedbackTask
>>> feedback_task = FeedbackTask()
>>> task = feedback_task.create(name="summarization", task_schema={...})
"""
json_payload = {"name": name, "task_schema": task_schema}
json_payload = {"task_schema": task_schema}
if name:
json_payload["name"] = name
if instruction:
json_payload["instruction"] = instruction

res = self._post_request(self.feedback_task_create_url, json_payload)
return res

Expand Down

0 comments on commit 39e4cc6

Please sign in to comment.