mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-19 12:03:54 +02:00
Add flow to query history CSV (#2492)
This commit is contained in:
@@ -133,6 +133,12 @@ class AuthType(str, Enum):
|
||||
SAML = "saml"
|
||||
|
||||
|
||||
class SessionType(str, Enum):
|
||||
CHAT = "Chat"
|
||||
SEARCH = "Search"
|
||||
SLACK = "Slack"
|
||||
|
||||
|
||||
class QAFeedbackType(str, Enum):
|
||||
LIKE = "like" # User likes the answer, used for metrics
|
||||
DISLIKE = "dislike" # User dislikes the answer, used for metrics
|
||||
|
@@ -17,6 +17,7 @@ from danswer.auth.users import get_display_email
|
||||
from danswer.chat.chat_utils import create_chat_chain
|
||||
from danswer.configs.constants import MessageType
|
||||
from danswer.configs.constants import QAFeedbackType
|
||||
from danswer.configs.constants import SessionType
|
||||
from danswer.db.chat import get_chat_session_by_id
|
||||
from danswer.db.engine import get_session
|
||||
from danswer.db.models import ChatMessage
|
||||
@@ -90,6 +91,7 @@ class ChatSessionMinimal(BaseModel):
|
||||
persona_name: str | None
|
||||
time_created: datetime
|
||||
feedback_type: QAFeedbackType | Literal["mixed"] | None
|
||||
flow_type: SessionType
|
||||
|
||||
|
||||
class ChatSessionSnapshot(BaseModel):
|
||||
@@ -99,6 +101,7 @@ class ChatSessionSnapshot(BaseModel):
|
||||
messages: list[MessageSnapshot]
|
||||
persona_name: str | None
|
||||
time_created: datetime
|
||||
flow_type: SessionType
|
||||
|
||||
|
||||
class QuestionAnswerPairSnapshot(BaseModel):
|
||||
@@ -114,6 +117,7 @@ class QuestionAnswerPairSnapshot(BaseModel):
|
||||
persona_name: str | None
|
||||
user_email: str
|
||||
time_created: datetime
|
||||
flow_type: SessionType
|
||||
|
||||
@classmethod
|
||||
def from_chat_session_snapshot(
|
||||
@@ -141,6 +145,7 @@ class QuestionAnswerPairSnapshot(BaseModel):
|
||||
persona_name=chat_session_snapshot.persona_name,
|
||||
user_email=get_display_email(chat_session_snapshot.user_email),
|
||||
time_created=user_message.time_created,
|
||||
flow_type=chat_session_snapshot.flow_type,
|
||||
)
|
||||
for ind, (user_message, ai_message) in enumerate(message_pairs)
|
||||
]
|
||||
@@ -162,9 +167,20 @@ class QuestionAnswerPairSnapshot(BaseModel):
|
||||
"persona_name": self.persona_name,
|
||||
"user_email": self.user_email,
|
||||
"time_created": str(self.time_created),
|
||||
"flow_type": self.flow_type,
|
||||
}
|
||||
|
||||
|
||||
def determine_flow_type(chat_session: ChatSession) -> SessionType:
|
||||
return (
|
||||
SessionType.SLACK
|
||||
if chat_session.danswerbot_flow
|
||||
else SessionType.SEARCH
|
||||
if chat_session.one_shot
|
||||
else SessionType.CHAT
|
||||
)
|
||||
|
||||
|
||||
def fetch_and_process_chat_session_history_minimal(
|
||||
db_session: Session,
|
||||
start: datetime,
|
||||
@@ -226,6 +242,8 @@ def fetch_and_process_chat_session_history_minimal(
|
||||
if feedback_filter == QAFeedbackType.DISLIKE and not has_negative_feedback:
|
||||
continue
|
||||
|
||||
flow_type = determine_flow_type(chat_session)
|
||||
|
||||
minimal_sessions.append(
|
||||
ChatSessionMinimal(
|
||||
id=chat_session.id,
|
||||
@@ -240,6 +258,7 @@ def fetch_and_process_chat_session_history_minimal(
|
||||
else None,
|
||||
time_created=chat_session.time_created,
|
||||
feedback_type=feedback_type,
|
||||
flow_type=flow_type,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -291,6 +310,8 @@ def snapshot_from_chat_session(
|
||||
except RuntimeError:
|
||||
return None
|
||||
|
||||
flow_type = determine_flow_type(chat_session)
|
||||
|
||||
return ChatSessionSnapshot(
|
||||
id=chat_session.id,
|
||||
user_email=get_display_email(
|
||||
@@ -304,6 +325,7 @@ def snapshot_from_chat_session(
|
||||
],
|
||||
persona_name=chat_session.persona.name if chat_session.persona else None,
|
||||
time_created=chat_session.time_created,
|
||||
flow_type=flow_type,
|
||||
)
|
||||
|
||||
|
||||
|
@@ -85,7 +85,8 @@ export default function QueryPage({ params }: { params: { id: string } }) {
|
||||
|
||||
<Text className="flex flex-wrap whitespace-normal mt-1 text-xs">
|
||||
{chatSessionSnapshot.user_email || "-"},{" "}
|
||||
{timestampToReadableDate(chatSessionSnapshot.time_created)}
|
||||
{timestampToReadableDate(chatSessionSnapshot.time_created)},{" "}
|
||||
{chatSessionSnapshot.flow_type}
|
||||
</Text>
|
||||
|
||||
<Divider />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Feedback } from "@/lib/types";
|
||||
import { Feedback, SessionType } from "@/lib/types";
|
||||
|
||||
export interface QueryAnalytics {
|
||||
total_queries: number;
|
||||
@@ -40,6 +40,7 @@ export interface ChatSessionSnapshot {
|
||||
messages: MessageSnapshot[];
|
||||
persona_name: string | null;
|
||||
time_created: string;
|
||||
flow_type: SessionType;
|
||||
}
|
||||
|
||||
export interface ChatSessionMinimal {
|
||||
@@ -51,6 +52,7 @@ export interface ChatSessionMinimal {
|
||||
persona_name: string | null;
|
||||
time_created: string;
|
||||
feedback_type: Feedback | "mixed" | null;
|
||||
flow_type: SessionType;
|
||||
}
|
||||
|
||||
export interface UsageReport {
|
||||
|
@@ -49,6 +49,7 @@ export type ValidStatuses =
|
||||
| "not_started";
|
||||
export type TaskStatus = "PENDING" | "STARTED" | "SUCCESS" | "FAILURE";
|
||||
export type Feedback = "like" | "dislike";
|
||||
export type SessionType = "Chat" | "Search" | "Slack";
|
||||
|
||||
export interface DocumentBoostStatus {
|
||||
document_id: string;
|
||||
|
Reference in New Issue
Block a user