Skip to content

Commit

Permalink
sort and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jalexanderII committed Aug 26, 2023
1 parent e279481 commit a04bc9c
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions parea/cookbook/tracing_with_parea_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,46 @@ def refiner(query: str, additional_description: str, current_arg: str, criticism
).content


@trace
def deployed_argument_generator(query: str, additional_description: str = "") -> str:
return p.completion(
Completion(
deployment_id="p-Ar-Oi14-nBxHUiradyql9",
llm_inputs={
"additional_description": additional_description,
"date": f"{datetime.now()}",
"query": query,
},
)
).content


@trace
def deployed_critic(argument: str) -> str:
return p.completion(
Completion(
deployment_id="p-W2yPy93tAczYrxkipjli6",
llm_inputs={"argument": argument},
)
).content


@trace
def deployed_refiner(query: str, additional_description: str, current_arg: str, criticism: str) -> str:
return p.completion(
Completion(
deployment_id="p-8Er1Xo0GDGF2xtpmMOpbn",
llm_inputs={
"additional_description": additional_description,
"date": f"{datetime.now()}",
"query": query,
"current_arg": current_arg,
"criticism": criticism,
},
)
).content


@trace
def argument_chain(query: str, additional_description: str = "") -> str:
argument = argument_generator(query, additional_description)
Expand Down Expand Up @@ -123,6 +163,22 @@ def refiner2(query: str, additional_description: str, current_arg: str, criticis
)


@trace
def deployed_refiner2(query: str, additional_description: str, current_arg: str, criticism: str) -> CompletionResponse:
return p.completion(
Completion(
deployment_id="p-8Er1Xo0GDGF2xtpmMOpbn",
llm_inputs={
"additional_description": additional_description,
"date": f"{datetime.now()}",
"query": query,
"current_arg": current_arg,
"criticism": criticism,
},
)
)


@trace(
tags=["cookbook-example", "feedback_tracked"],
metadata={"source": "python-sdk"},
Expand All @@ -133,6 +189,31 @@ def argument_chain3(query: str, additional_description: str = "") -> CompletionR
return refiner2(query, additional_description, argument, criticism)


@trace
def deployed_argument_chain(query: str, additional_description: str = "") -> str:
argument = deployed_argument_generator(query, additional_description)
criticism = deployed_critic(argument)
return deployed_refiner(query, additional_description, argument, criticism)


@trace
def deployed_argument_chain2(query: str, additional_description: str = "") -> tuple[str, str]:
trace_id = get_current_trace_id()
argument = deployed_argument_generator(query, additional_description)
criticism = deployed_critic(argument)
return deployed_refiner(query, additional_description, argument, criticism), trace_id


@trace(
tags=["cookbook-example-deployed", "feedback_tracked-deployed"],
metadata={"source": "python-sdk", "deployed": True},
)
def deployed_argument_chain3(query: str, additional_description: str = "") -> CompletionResponse:
argument = deployed_argument_generator(query, additional_description)
criticism = deployed_critic(argument)
return deployed_refiner2(query, additional_description, argument, criticism)


@trace
def expound_task(main_objective: str, current_task: str) -> list[dict[str, str]]:
prompt = [
Expand Down Expand Up @@ -227,3 +308,37 @@ def run_agent(main_objective: str, initial_task: str = "") -> list[dict[str, str

result4 = run_agent("Become a machine learning expert.", "Learn about tensors.")
print(result4)

result5 = deployed_argument_chain(
"Whether coffee is good for you.",
additional_description="Provide a concise, few sentence argument on why coffee is good for you.",
)
print(result5)

result6, trace_id2 = deployed_argument_chain2(
"Whether wine is good for you.",
additional_description="Provide a concise, few sentence argument on why wine is good for you.",
)
time.sleep(3)
p.record_feedback(
FeedbackRequest(
trace_id=trace_id2,
score=0.0, # 0.0 (bad) to 1.0 (good)
target="Moonshine is wonderful.",
)
)
print(result6)

result7 = deployed_argument_chain3(
"Whether moonshine is good for you.",
additional_description="Provide a concise, few sentence argument on why moonshine is good for you.",
)
time.sleep(3)
p.record_feedback(
FeedbackRequest(
trace_id=result7.inference_id,
score=0.7, # 0.0 (bad) to 1.0 (good)
target="Moonshine is wonderful. End of story.",
)
)
print(result7.error or result7.content)

0 comments on commit a04bc9c

Please sign in to comment.