Skip to content

Commit 577bd3c

Browse files
authored
Merge pull request #1010 from parea-ai/PAI-1402-add-history-via-p-completion
feat(history): add history to completion
2 parents 1eeec4b + 9c69612 commit 577bd3c

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

cookbook/parea_llm_proxy/deployments/tracing_with_deployed_prompt.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dotenv import load_dotenv
99

1010
from parea import Parea, get_current_trace_id, trace
11-
from parea.schemas import Completion, CompletionResponse, FeedbackRequest
11+
from parea.schemas import Completion, CompletionResponse, LLMInputs, Message, Role
1212

1313
load_dotenv()
1414

@@ -18,60 +18,64 @@
1818
def deployed_argument_generator(query: str, additional_description: str = "") -> str:
1919
return p.completion(
2020
Completion(
21-
deployment_id="p-RG8d9rfJc_0cctwfpb_n6",
21+
deployment_id="p-XOh3kp8B0nIE82WgioPnr",
2222
llm_inputs={
2323
"additional_description": additional_description,
2424
"date": f"{datetime.now()}",
2525
"query": query,
2626
},
27+
llm_configuration=LLMInputs(history=[Message(role=Role.user, content="Some history")]),
2728
)
2829
).content
2930

3031

3132
def deployed_critic(argument: str) -> str:
3233
return p.completion(
3334
Completion(
34-
deployment_id="p-fXgZytT3dJjXD_71TDR4s",
35+
deployment_id="p-PSOwRyIPaQRq4xQW3MbpV",
3536
llm_inputs={"argument": argument},
37+
llm_configuration=LLMInputs(history=[Message(role=Role.user, content="Some history")]),
3638
)
3739
).content
3840

3941

4042
def deployed_refiner(query: str, additional_description: str, current_arg: str, criticism: str) -> str:
4143
return p.completion(
4244
Completion(
43-
deployment_id="p--G2s9okMTvBEh3d8YqLY2",
45+
deployment_id="p-bJ3-UKh9-ixapZafaRBsj",
4446
llm_inputs={
4547
"additional_description": additional_description,
4648
"date": f"{datetime.now()}",
4749
"query": query,
4850
"argument": current_arg,
4951
"criticism": criticism,
5052
},
53+
llm_configuration=LLMInputs(history=[Message(role=Role.user, content="Some history")]),
5154
)
5255
).content
5356

5457

5558
def deployed_refiner2(query: str, additional_description: str, current_arg: str, criticism: str) -> CompletionResponse:
5659
return p.completion(
5760
Completion(
58-
deployment_id="p--G2s9okMTvBEh3d8YqLY2",
61+
deployment_id="p-bJ3-UKh9-ixapZafaRBsj",
5962
llm_inputs={
6063
"additional_description": additional_description,
6164
"date": f"{datetime.now()}",
6265
"query": query,
6366
"argument": current_arg,
6467
"criticism": criticism,
6568
},
69+
llm_configuration=LLMInputs(history=[Message(role=Role.user, content="Some history")]),
6670
)
6771
)
6872

6973

70-
# @trace
71-
# def deployed_argument_chain(query: str, additional_description: str = "") -> str:
72-
# argument = deployed_argument_generator(query, additional_description)
73-
# criticism = deployed_critic(argument)
74-
# return deployed_refiner(query, additional_description, argument, criticism)
74+
@trace
75+
def deployed_argument_chain(query: str, additional_description: str = "") -> str:
76+
argument = deployed_argument_generator(query, additional_description)
77+
criticism = deployed_critic(argument)
78+
return deployed_refiner(query, additional_description, argument, criticism)
7579

7680

7781
@trace(
@@ -86,21 +90,21 @@ def deployed_argument_chain_tags_metadata(query: str, additional_description: st
8690

8791

8892
if __name__ == "__main__":
89-
# result1 = deployed_argument_chain(
90-
# "Whether coffee is good for you.",
91-
# additional_description="Provide a concise, few sentence argument on why coffee is good for you.",
92-
# )
93-
# print(result1)
93+
result1 = deployed_argument_chain(
94+
"Whether coffee is good for you.",
95+
additional_description="Provide a concise, few sentence argument on why coffee is good for you.",
96+
)
97+
print(result1)
9498

9599
result2, trace_id = deployed_argument_chain_tags_metadata(
96100
"Whether coffee is good for you.",
97101
additional_description="Provide a concise, few sentence argument on why coffee is good for you.",
98102
)
99103
print(json.dumps(asdict(result2), indent=2))
100-
p.record_feedback(
101-
FeedbackRequest(
102-
trace_id=trace_id,
103-
score=0.7, # 0.0 (bad) to 1.0 (good)
104-
target="Coffee is wonderful. End of story.",
105-
)
106-
)
104+
# p.record_feedback(
105+
# FeedbackRequest(
106+
# trace_id=trace_id,
107+
# score=0.7, # 0.0 (bad) to 1.0 (good)
108+
# target="Coffee is wonderful. End of story.",
109+
# )
110+
# )

cookbook/parea_llm_proxy/tracing_without_deployed_prompt.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dotenv import load_dotenv
77

88
from parea import Parea, get_current_trace_id, trace
9-
from parea.schemas import Completion, CompletionResponse, FeedbackRequest, LLMInputs, Message, ModelParams
9+
from parea.schemas import Completion, CompletionResponse, FeedbackRequest, LLMInputs, Message, ModelParams, Role
1010

1111
load_dotenv()
1212

@@ -21,9 +21,7 @@ def call_llm(
2121
return p.completion(
2222
data=Completion(
2323
llm_configuration=LLMInputs(
24-
model=model,
25-
model_params=ModelParams(temp=temperature),
26-
messages=[Message(**d) for d in data],
24+
model=model, model_params=ModelParams(temp=temperature), messages=[Message(**d) for d in data], history=[Message(role=Role.user, content="Some history")]
2725
)
2826
)
2927
)

parea/schemas/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LLMInputs:
5050
provider: Optional[str] = None
5151
model_params: Optional[ModelParams] = ModelParams()
5252
messages: Optional[List[Message]] = None
53+
history: Optional[List[Message]] = None
5354
functions: Optional[List[Any]] = None
5455
function_call: Optional[Union[str, Dict[str, str]]] = None
5556

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
66
[tool.poetry]
77
name = "parea-ai"
88
packages = [{ include = "parea" }]
9-
version = "0.2.188"
9+
version = "0.2.189"
1010
description = "Parea python sdk"
1111
readme = "README.md"
1212
authors = ["joel-parea-ai <[email protected]>"]

0 commit comments

Comments
 (0)