Skip to content

Commit 580f19e

Browse files
authored
feat(sdk): user feedback scores (#247)
1 parent 88032a8 commit 580f19e

4 files changed

Lines changed: 138 additions & 48 deletions

File tree

packages/sample-app/poetry.lock

Lines changed: 89 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sample-app/sample_app/methods_decorated_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ def joke_workflow():
6666
signature = generate_signature(pirate_joke)
6767
print(pirate_joke + "\n\n" + signature)
6868

69+
Traceloop.report_score("chat_id", "chat_9876", 1)
70+
6971

7072
joke_workflow()

packages/traceloop-sdk/traceloop/sdk/__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Traceloop:
3232
AUTO_CREATED_URL = str(Path.home() / ".cache" / "traceloop" / "auto_created_url")
3333

3434
__tracer_wrapper: TracerWrapper
35+
__fetcher: Fetcher
3536

3637
@staticmethod
3738
def init(
@@ -57,7 +58,8 @@ def init(
5758
and not exporter
5859
and not processor
5960
):
60-
Fetcher(base_url=api_endpoint, api_key=api_key).run()
61+
Traceloop.__fetcher = Fetcher(base_url=api_endpoint, api_key=api_key)
62+
Traceloop.__fetcher.run()
6163
print(
6264
Fore.GREEN + "Traceloop syncing configuration and prompts" + Fore.RESET
6365
)
@@ -158,3 +160,27 @@ def set_correlation_id(correlation_id: str) -> None:
158160

159161
def set_association_properties(properties: dict) -> None:
160162
set_association_properties(properties)
163+
164+
def report_score(
165+
association_property_name: str,
166+
association_property_id: str,
167+
score: float,
168+
):
169+
if not Traceloop.__fetcher:
170+
print(
171+
Fore.RED
172+
+ "Error: Cannot report score. Missing Traceloop API key,"
173+
+ " go to https://https://app.traceloop.com/settings/api-keys to create one"
174+
)
175+
print("Set the TRACELOOP_API_KEY environment variable to the key")
176+
print(Fore.RESET)
177+
return
178+
179+
Traceloop.__fetcher.post(
180+
"score",
181+
{
182+
"entity_name": f"traceloop.association.properties.{association_property_name}",
183+
"entity_id": association_property_id,
184+
"score": score,
185+
},
186+
)

0 commit comments

Comments
 (0)