divi 0.0.1b1__py3-none-any.whl → 0.0.1b3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- divi/__init__.py +1 -1
- divi/evaluation/evaluator.py +12 -3
- divi/evaluation/prompts.py +1 -1
- divi/signals/span.py +5 -0
- divi/signals/trace.py +5 -0
- {divi-0.0.1b1.dist-info → divi-0.0.1b3.dist-info}/METADATA +1 -1
- {divi-0.0.1b1.dist-info → divi-0.0.1b3.dist-info}/RECORD +9 -9
- {divi-0.0.1b1.dist-info → divi-0.0.1b3.dist-info}/WHEEL +0 -0
- {divi-0.0.1b1.dist-info → divi-0.0.1b3.dist-info}/licenses/LICENSE +0 -0
divi/__init__.py
CHANGED
divi/evaluation/evaluator.py
CHANGED
@@ -19,6 +19,7 @@ class EvaluatorConfig:
|
|
19
19
|
max_concurrency: int = 10,
|
20
20
|
api_key: Optional[str] = None,
|
21
21
|
base_url: Optional[str] = None,
|
22
|
+
language: str = "zh",
|
22
23
|
):
|
23
24
|
self.model = model
|
24
25
|
self.api_key = api_key
|
@@ -26,6 +27,7 @@ class EvaluatorConfig:
|
|
26
27
|
self.temperature = temperature
|
27
28
|
self.n_rounds = n_rounds
|
28
29
|
self.max_concurrency = max_concurrency
|
30
|
+
self.language = language
|
29
31
|
|
30
32
|
|
31
33
|
class EvaluationResult(BaseModel):
|
@@ -52,17 +54,22 @@ class Evaluator:
|
|
52
54
|
)
|
53
55
|
|
54
56
|
@staticmethod
|
55
|
-
def generate_prompt(
|
57
|
+
def generate_prompt(
|
58
|
+
target: str, conversation: str, score: Score, language: str
|
59
|
+
) -> str:
|
56
60
|
return PROMPT_TEMPLATE.format(
|
57
61
|
requirements=PRESET_PROMPT[score.value],
|
58
62
|
target=target,
|
59
63
|
conversation=conversation,
|
64
|
+
language=language,
|
60
65
|
)
|
61
66
|
|
62
67
|
def _sync_evaluate_once(
|
63
68
|
self, target: str, conversation: str, score: Score
|
64
69
|
) -> Optional[EvaluationResult]:
|
65
|
-
prompt = self.generate_prompt(
|
70
|
+
prompt = self.generate_prompt(
|
71
|
+
target, conversation, score, self.config.language
|
72
|
+
)
|
66
73
|
response = self.sync_client.beta.chat.completions.parse(
|
67
74
|
model=self.config.model,
|
68
75
|
messages=[{"role": "user", "content": prompt}],
|
@@ -77,7 +84,9 @@ class Evaluator:
|
|
77
84
|
async def _async_evaluate_once(
|
78
85
|
self, target: str, conversation: str, score: Score
|
79
86
|
) -> Optional[EvaluationResult]:
|
80
|
-
prompt = self.generate_prompt(
|
87
|
+
prompt = self.generate_prompt(
|
88
|
+
target, conversation, score, self.config.language
|
89
|
+
)
|
81
90
|
response = await self.async_client.beta.chat.completions.parse(
|
82
91
|
model=self.config.model,
|
83
92
|
messages=[{"role": "user", "content": prompt}],
|
divi/evaluation/prompts.py
CHANGED
@@ -8,7 +8,7 @@ PROMPT_TEMPLATE = (
|
|
8
8
|
"Strictly output your answer in the following JSON format:\n"
|
9
9
|
"{{\n"
|
10
10
|
' "judgment": bool, # true if the response meets all requirements\n'
|
11
|
-
' "reasoning": "string" # concise explanation, hitting only the key points\n'
|
11
|
+
' "reasoning": "string" # concise explanation, in {language}, hitting only the key points\n'
|
12
12
|
"}}\n"
|
13
13
|
"Do not output anything else."
|
14
14
|
)
|
divi/signals/span.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import atexit
|
1
2
|
import os
|
2
3
|
import time
|
3
4
|
from enum import Enum
|
@@ -62,6 +63,8 @@ class Span:
|
|
62
63
|
"""Start the span by recording the current time in nanoseconds."""
|
63
64
|
self.start_time_unix_nano = time.time_ns()
|
64
65
|
self.upsert_span()
|
66
|
+
# Register the end method to be called at exit
|
67
|
+
atexit.register(self.end)
|
65
68
|
|
66
69
|
def end(self):
|
67
70
|
"""End the span by recording the end time in nanoseconds."""
|
@@ -69,6 +72,8 @@ class Span:
|
|
69
72
|
raise ValueError("Span must be started before ending.")
|
70
73
|
self.end_time_unix_nano = time.time_ns()
|
71
74
|
self.upsert_span()
|
75
|
+
# Unregister the end method
|
76
|
+
atexit.unregister(self.end)
|
72
77
|
|
73
78
|
def _add_node(self, trace_id: UUID4, parent_id: Optional[bytes] = None):
|
74
79
|
"""Add node for obs tree."""
|
divi/signals/trace.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import atexit
|
1
2
|
from datetime import UTC, datetime
|
2
3
|
from typing import Optional
|
3
4
|
from uuid import uuid4
|
@@ -63,6 +64,8 @@ class Trace:
|
|
63
64
|
"""Start the trace by recording the current time in nanoseconds."""
|
64
65
|
self.start_time = datetime.now(UTC).isoformat()
|
65
66
|
self.upsert_trace()
|
67
|
+
# Register the end method to be called on exit
|
68
|
+
atexit.register(self.end)
|
66
69
|
|
67
70
|
def end(self):
|
68
71
|
"""End the trace by recording the end time in nanoseconds."""
|
@@ -70,6 +73,8 @@ class Trace:
|
|
70
73
|
raise ValueError("Span must be started before ending.")
|
71
74
|
self.end_time = datetime.now(UTC).isoformat()
|
72
75
|
self.upsert_trace()
|
76
|
+
# Unregister the end method to prevent multiple calls
|
77
|
+
atexit.unregister(self.end)
|
73
78
|
|
74
79
|
def upsert_trace(self):
|
75
80
|
"""Upsert trace with datapark."""
|
@@ -1,5 +1,5 @@
|
|
1
1
|
divi/README.md,sha256=hdw10Mkebd1SGMeA3tPJtlOwbWZzuQ8J-N9YPEHGuXg,67
|
2
|
-
divi/__init__.py,sha256=
|
2
|
+
divi/__init__.py,sha256=hscfdliNohMGPl12Xzr6UGm6QDJfxxbLXjhc0FPI4Fc,436
|
3
3
|
divi/utils.py,sha256=fXkjoyo_Lh8AZliKICOP460m0czUcNQjcEcceJbaOVA,1439
|
4
4
|
divi/decorators/__init__.py,sha256=HkyWdC1ctTsVFucCWCkj57JB4NmwONus1d2S2dUbvs4,110
|
5
5
|
divi/decorators/collect.py,sha256=5iUxAnbHYx4ISkFg64IK_4miGdrWgbOXLJxKz8lGIv8,1074
|
@@ -8,8 +8,8 @@ divi/decorators/observable.py,sha256=orDNCP1_uOTwgg71lg2c0qXOv6DtcxufRzuQZqXOrH4
|
|
8
8
|
divi/decorators/observe.py,sha256=I2RVsp2WQep6iTLSxkAlMP8wiRsSYiiYrxR2hJzPxcI,1211
|
9
9
|
divi/evaluation/__init__.py,sha256=SVu4tYZLgx4juEa1JtkXGcwB_Xuwvh60lbVhYKMseQo,129
|
10
10
|
divi/evaluation/evaluate.py,sha256=lVMCw5vHGa5sJvUyhVDZ9m3Sgl4baCjWhw2OKazhvgM,1861
|
11
|
-
divi/evaluation/evaluator.py,sha256=
|
12
|
-
divi/evaluation/prompts.py,sha256=
|
11
|
+
divi/evaluation/evaluator.py,sha256=UbKBedn0iYMSBT2L-_e7AUB1D8kvRlP0oai1dqWOA3c,6319
|
12
|
+
divi/evaluation/prompts.py,sha256=NBPSn09GarOHXXIcdiViMuOupcL7MHP1_qiyDq6rO5Y,975
|
13
13
|
divi/evaluation/scores.py,sha256=ZgSxfve-ZivX3WU4TGcgPOSpUQVMbG5a15IQNPeq_bQ,173
|
14
14
|
divi/proto/common/v1/common.proto,sha256=Rx8wr0_tOtQ1NseTMnsav4ApD1MDALzQDBA2IvLRTU0,1775
|
15
15
|
divi/proto/common/v1/common_pb2.py,sha256=br61OHQVAi6SI3baFcb5xJv2Xd-AZ04A19xeSjLNMXo,2442
|
@@ -44,9 +44,9 @@ divi/session/session.py,sha256=QxtEezI447PbtKG2U6cxL1ACae55e8nFfTufAY8pEYI,811
|
|
44
44
|
divi/session/setup.py,sha256=rC1QdCxpdCOaRXmcLEQs4Yuu5UC_aRzKSaqWRPJN4Og,1390
|
45
45
|
divi/session/teardown.py,sha256=YiBz_3yCiljMFEofZ60VmRL5sb8WA5GT7EYF8nFznZ4,133
|
46
46
|
divi/signals/__init__.py,sha256=wfSkkCwkRsFP4aLj8aGHk_k6Y50P5yN44WWlO3XyW18,43
|
47
|
-
divi/signals/span.py,sha256=
|
48
|
-
divi/signals/trace.py,sha256=
|
49
|
-
divi-0.0.
|
50
|
-
divi-0.0.
|
51
|
-
divi-0.0.
|
52
|
-
divi-0.0.
|
47
|
+
divi/signals/span.py,sha256=AQ24C8EKzGceryybX0rBe9B0z43kKaULdR6eOeOCtno,2804
|
48
|
+
divi/signals/trace.py,sha256=US_M2CAYNGUhEa5pppRPJN8dfNA5owgHMFDK2AOrFXA,2345
|
49
|
+
divi-0.0.1b3.dist-info/METADATA,sha256=VwB4fMovuRHqB8jr0Z218r702bZbov6SSYsCQc_TesE,493
|
50
|
+
divi-0.0.1b3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
51
|
+
divi-0.0.1b3.dist-info/licenses/LICENSE,sha256=5OJuZ4wMMEV0DgF0tofhAlS_KLkaUsZwwwDS2U_GwQ0,1063
|
52
|
+
divi-0.0.1b3.dist-info/RECORD,,
|
File without changes
|
File without changes
|