File size: 1,820 Bytes
0413dd6
4ad7a82
0413dd6
1f39bb8
4ad7a82
 
 
 
 
0413dd6
 
 
aa7685e
 
 
0413dd6
 
 
 
 
 
 
 
571c059
 
 
 
 
a02a4b0
 
571c059
 
 
 
 
923909d
571c059
 
923909d
 
 
 
 
 
a02a4b0
 
 
923909d
571c059
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from pydantic import BaseModel, UUID4
from typing import List, Optional
from langsmith import Client
from app.lib.supabase_client import SupabaseClient

class Feedback(BaseModel):
    metric_type: Optional[str]
    metric_score: Optional[float]
    feedback_on: Optional[str]


def post_feedback(run_id: UUID4, feedback: Feedback):
    print("Metric Type: ", feedback.metric_type)
    print("Feedback On: ", feedback.feedback_on)

    client = Client()
    client.create_feedback(
        str(run_id),
        key=feedback.metric_type,
        score=feedback.metric_score,
        source_info={"content": feedback.feedback_on},
        type="api",
    )

## fields of inputs dict: run_id, sub_workflow
class NewFeedback(BaseModel):
    metric_type: str
    metric_score: float
    original_content: Optional[dict]
    modified_content: Optional[dict]

    def post(self, inputs={}):
        run_id = inputs["run_id"]
        sub_workflow = inputs["sub_workflow"]

        self._post_to_supbase(run_id, sub_workflow)
        self._post_to_langsmith(run_id)

    def _post_to_supbase(self, run_id: UUID4, sub_worfklow: str):
        client = SupabaseClient()
        client.post_feedback(
            run_id= run_id,
            sub_workflow= sub_worfklow,
            metric_score=self.metric_score,
            metric_type=self.metric_type,
            original_content=self.original_content,
            modified_content=self.modified_content
        )
        return

    def _post_to_langsmith(self, run_id: UUID4):
        client = Client()
        client.create_feedback(
            str(run_id),
            key=self.metric_type,
            score=self.metric_score,
            source_info={"original_content": self.original_content, "modified_content": self.modified_content},
            type="api",
        )