from freeplay import Freeplay, RecordPayload, CallInfo, ResponseInfo, SessionInfo, CallInfo, SessionInfo
from uuid import uuid4
## PROMPT FETCH
# set the prompt variables
prompt_vars = {"keyA": "valueA"}
# get a formatted prompt
formatted_prompt = fpClient.prompts.get_formatted(project_id=project_id,
template_name="template_name",
environment="latest",
variables=prompt_vars)
## LLM CALL
# Make an LLM call to your provider of choice
start = time.time()
chat_response = openaiClient.chat.completions.create(
model=formatted_prompt.prompt_info.model,
messages=formatted_prompt.llm_prompt,
\*\*formatted_prompt.prompt_info.model_parameters
)
end = time.time()
# add the response to your message set
all_messages = formatted_prompt.all_messages(
{'role': chat_response.choices[0].message.role,
'content': chat_response.choices[0].message.content}
)
## RECORD
### CUSTOM IDS
# create your Ids (must be UUIDs)
session_id = uuid4()
completion_id = uuid4()
# Create sessionInfo with custom Ids
session_info = SessionInfo(
session_id=session_id,
custom_metadata={'keyA': 'valueA'}
)
### Extra data
call_info = CallInfo(
provider=formatted_prompt.prompt_info.provider,
model=formatted_prompt.prompt_info.model,
start_time=s,
end_time=e,
model_parameters=all_params # pass the full parameter set
)
# build the record payload
payload = RecordPayload(
project_id=project_id,
all_messages=all_messages,
inputs=prompt_vars, # Pass the custom session_info and completion_id
session_info=session_info,
completion_id=completion_id,
prompt_version_info=formatted_prompt.prompt_info,
call_info=call_info,
)
# record the LLM interaction
fpClient.recordings.create(payload)