Skip to content

Commit 77bb5e2

Browse files
committed
feat(log): add session_id
1 parent eeb5c0d commit 77bb5e2

File tree

8 files changed

+457
-516
lines changed

8 files changed

+457
-516
lines changed

parea/cookbook/tracing_anthropic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
client = anthropic.Anthropic()
1414
aclient = anthropic.AsyncAnthropic()
1515

16-
p = Parea(api_key=os.getenv("PAREA_API_KEY"), project_name="testing")
16+
p = Parea(api_key=os.getenv("PAREA_API_KEY"))
1717
p.wrap_anthropic_client(client)
1818
p.wrap_anthropic_client(aclient)
1919

parea/cookbook/tracing_with_open_ai_endpoint_directly.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dotenv import load_dotenv
77
from openai import OpenAI
88

9-
from parea import Parea, get_current_trace_id, trace
9+
from parea import Parea, get_current_trace_id, trace, trace_insert
1010
from parea.schemas import FeedbackRequest
1111

1212
load_dotenv()
@@ -73,13 +73,14 @@ def refiner(query: str, additional_description: str, argument: str, criticism: s
7373
@trace
7474
def argument_chain(query: str, additional_description: str = "") -> Tuple[str, str]:
7575
trace_id = get_current_trace_id()
76+
trace_insert({"session_id": "cus_1234", "end_user_identifier": "user_1234"}, trace_id)
7677
argument = argumentor(query, additional_description)
7778
criticism = critic(argument)
7879
refined_argument = refiner(query, additional_description, argument, criticism)
7980
return refined_argument, trace_id
8081

8182

82-
@trace
83+
@trace(session_id="cus_1234", end_user_identifier="user_1234")
8384
def json_call() -> str:
8485
completion = client.chat.completions.create(
8586
model="gpt-4-turbo-2024-04-09",
@@ -95,11 +96,11 @@ def json_call() -> str:
9596
additional_description="Provide a concise, few sentence argument on why sparkling wine is good for you.",
9697
)
9798
print(result)
98-
# p.record_feedback(
99-
# FeedbackRequest(
100-
# trace_id=trace_id,
101-
# score=0.7, # 0.0 (bad) to 1.0 (good)
102-
# )
103-
# )
99+
p.record_feedback(
100+
FeedbackRequest(
101+
trace_id=trace_id,
102+
score=0.7, # 0.0 (bad) to 1.0 (good)
103+
)
104+
)
104105

105106
print(json_call())

parea/schemas/log.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -43,67 +43,7 @@ class ModelParams:
4343

4444
@define
4545
class LLMInputs:
46-
"""
47-
model choice should match an enabled model on the Parea platform.
48-
model options are:
49-
OPENAI_MODELS
50-
"gpt-3.5-turbo"
51-
"gpt-3.5-turbo-0301"
52-
"gpt-3.5-turbo-0613"
53-
"gpt-3.5-turbo-16k"
54-
"gpt-3.5-turbo-16k-0301"
55-
"gpt-3.5-turbo-16k-0613"
56-
"gpt-3.5-turbo-1106"
57-
"gpt-3.5-turbo-0125"
58-
"gpt-3.5-turbo-instruct"
59-
"gpt-4"
60-
"gpt-4-0314"
61-
"gpt-4-0613"
62-
"gpt-4-32k"
63-
"gpt-4-32k-0314"
64-
"gpt-4-32k-0613"
65-
"gpt-4-turbo-preview"
66-
"gpt-4-1106-preview"
67-
"gpt-4-0125-preview"
68-
You can use Azure models by providing your model name prefixed with azure_, e.g. azure_gpt-3.5-turbo
69-
ANTHROPIC_MODELS
70-
"claude-instant-1.1"
71-
"claude-instant-1"
72-
"claude-instant-1.2"
73-
"claude-instant-1-100k"
74-
"claude-instant-1.1-100k"
75-
"claude-1"
76-
"claude-2"
77-
"claude-1-100k"
78-
"claude-1.2"
79-
"claude-1.3"
80-
"claude-1.3-100k"
81-
"claude-2.1"
82-
AWS_ANTHROPIC_MODELS
83-
"anthropic.claude-instant-v1"
84-
"anthropic.claude-v1"
85-
"anthropic.claude-v2"
86-
"anthropic.claude-v2:1"
87-
ANYSCALE_MODELS
88-
"meta-llama/Llama-2-7b-chat-hf"
89-
"meta-llama/Llama-2-13b-chat-hf"
90-
"meta-llama/Llama-2-70b-chat-hf"
91-
"codellama/CodeLlama-34b-Instruct-hf"
92-
"mistralai/Mistral-7B-Instruct-v0.1"
93-
"mistralai/Mixtral-8x7B-Instruct-v0.1"
94-
"HuggingFaceH4/zephyr-7b-beta"
95-
"Open-Orca/Mistral-7B-OpenOrca"
96-
VERTEX_MODELS
97-
"gemini-pro"
98-
"text-bison@001"
99-
"text-bison@002"
100-
"text-bison"
101-
"text-bison-32k"
102-
"chat-bison@002"
103-
"chat-bison@001"
104-
"chat-bison"
105-
"chat-bison-32k
106-
"""
46+
"""model choice should match an enabled model on the Parea platform."""
10747

10848
model: Optional[str] = None
10949
provider: Optional[str] = None

parea/schemas/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class TraceLog(EvaluatedLog):
114114
# metrics filled from either decorator or completion
115115
end_timestamp: Optional[str] = None
116116
end_user_identifier: Optional[str] = None
117+
session_id: Optional[str] = None
117118
metadata: Optional[Dict[str, Any]] = None
118119
tags: Optional[List[str]] = field(factory=list)
119120
experiment_uuid: Optional[str] = None

parea/utils/trace_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def trace_insert(data: Dict[str, Any], trace_id: Optional[str] = None):
8989
Insert data into the trace log for the current or specified trace id. Data should be a dictionary with keys that correspond to the fields of the TraceLog model.
9090
If the field already has an existing value that is extensible (dict, set, list, etc.), the new value will be merged with the existing value.
9191
Args:
92-
data: Keys can be one of: trace_name, end_user_identifier, metadata, tags, deployment_id, images
92+
data: Keys can be one of: trace_name, end_user_identifier, metadata, tags, deployment_id, images, session_id
9393
trace_id: The trace id to insert the data into. If not provided, the current trace id will be used.
9494
"""
9595
try:
@@ -128,6 +128,7 @@ def trace(
128128
tags: Optional[List[str]] = None,
129129
metadata: Optional[Dict[str, Any]] = None,
130130
end_user_identifier: Optional[str] = None,
131+
session_id: Optional[str] = None,
131132
eval_funcs_names: Optional[List[str]] = None,
132133
eval_funcs: Optional[List[Callable]] = None,
133134
access_output_of_func: Optional[Callable] = None,
@@ -171,6 +172,7 @@ def init_trace(func_name, _parea_target_field, args, kwargs, func) -> Tuple[str,
171172
start_timestamp=start_time.isoformat(),
172173
trace_name=name or func_name,
173174
end_user_identifier=end_user_identifier,
175+
session_id=session_id,
174176
metadata=metadata,
175177
target=_parea_target_field,
176178
tags=tags,

parea/wrapper/wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _init_trace(self) -> Tuple[str, datetime, contextvars.Token]:
8989
start_timestamp=start_time.isoformat(),
9090
trace_name="LLM",
9191
end_user_identifier=None,
92+
session_id=None,
9293
metadata=None,
9394
target=None,
9495
tags=None,

0 commit comments

Comments
 (0)