Skip to content

Commit

Permalink
Hoist session id keys into constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalization committed Dec 5, 2024
1 parent 8dcf675 commit 56a6c89
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import { withSafety } from "@arizeai/openinference-core";
export const RETRIEVAL_DOCUMENTS =
`${SemanticAttributePrefixes.retrieval}.${RetrievalAttributePostfixes.documents}` as const;

export const SESSION_ID_KEYS = [
"session_id",
"thread_id",
"conversation_id",
] as const;

/**
* Handler for any unexpected errors that occur during processing.
*/
Expand Down Expand Up @@ -659,15 +665,14 @@ function formatMetadata(run: Run) {
* @returns The OpenInference attributes for the session id
*/
function formatSessionId(run: Run) {
const sessionKeys = ["session_id", "thread_id", "conversation_id"];
if (!isObject(run.extra)) {
return null;
}
const metadata = run.extra.metadata;
if (!isObject(metadata)) {
return null;
}
const sessionId = sessionKeys.find((key) => isString(metadata[key]));
const sessionId = SESSION_ID_KEYS.find((key) => isString(metadata[key]));
if (sessionId == null) {
return null;
}
Expand Down

0 comments on commit 56a6c89

Please sign in to comment.