Skip to content

Commit

Permalink
Specialized fetch function (renamed), small margin added to feedbacks…
Browse files Browse the repository at this point in the history
…, more loaded at once
  • Loading branch information
overmode committed Jan 2, 2025
1 parent e5be49d commit 567745b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Button,
ChatBubbleBottomCenterTextIcon,
cn,
ContentMessage,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
Expand Down Expand Up @@ -50,15 +49,15 @@ import { ConfirmContext } from "@app/components/Confirm";
import { ACTION_SPECIFICATIONS } from "@app/lib/api/assistant/actions/utils";
import type { AgentMessageFeedbackWithMetadataType } from "@app/lib/api/assistant/feedback";
import {
useAgentConfigurationFeedbacks,
useAgentConfigurationFeedbacksByDescVersion,
useAgentConfigurationHistory,
} from "@app/lib/swr/assistants";
import { useUser } from "@app/lib/swr/user";
import { timeAgoFrom } from "@app/lib/utils";
import type { FetchAssistantTemplateResponse } from "@app/pages/api/w/[wId]/assistant/builder/templates/[tId]";

const MAX_FEEDBACKS_TO_DISPLAY = 500;
const FEEDBACKS_BATCH_SIZE = 50;
const FEEDBACKS_BATCH_SIZE = 100;

interface AssistantBuilderRightPanelProps {
screen: BuilderScreen;
Expand Down Expand Up @@ -433,8 +432,9 @@ const FeedbacksSection = ({
const [feedbacks, setFeedbacks] = useState<
AgentMessageFeedbackWithMetadataType[]
>([]);
// Decreasing version, paginated decreasing id.
const { agentConfigurationFeedbacks, isAgentConfigurationFeedbacksLoading } =
useAgentConfigurationFeedbacks({
useAgentConfigurationFeedbacksByDescVersion({
workspaceId: owner.sId,
agentConfigurationId: assistantId ?? "",
withMetadata: true,
Expand Down Expand Up @@ -536,7 +536,7 @@ const FeedbacksSection = ({
/>
)}
{!isNewVersion && !isFirstFeedback && (
<div className="mx-4">
<div className="mx-4 my-1">
<Page.Separator />
</div>
)}
Expand Down
15 changes: 9 additions & 6 deletions front/lib/api/assistant/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,15 @@ export async function getAgentFeedbacks({
return new Err(new Error("agent_configuration_not_found"));
}

const feedbacksRes = await AgentMessageFeedbackResource.fetch({
workspace: owner,
agentConfiguration,
paginationParams,
withMetadata,
});
const feedbacksRes =
await AgentMessageFeedbackResource.getAgentConfigurationFeedbacksByDescVersion(
{
workspace: owner,
agentConfiguration,
paginationParams,
withMetadata,
}
);

if (!withMetadata) {
return new Ok(feedbacksRes);
Expand Down
10 changes: 5 additions & 5 deletions front/lib/resources/agent_message_feedback_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ConversationError,
ConversationType,
ConversationWithoutContentType,
LightAgentConfigurationType,
MessageType,
Result,
UserType,
Expand Down Expand Up @@ -91,22 +92,23 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
});
}

static async fetch({
static async getAgentConfigurationFeedbacksByDescVersion({
workspace,
withMetadata,
agentConfiguration,
paginationParams,
}: {
workspace: WorkspaceType;
withMetadata: boolean;
agentConfiguration?: AgentConfigurationType;
agentConfiguration: LightAgentConfigurationType;
paginationParams: PaginationParams;
}): Promise<
(AgentMessageFeedbackType | AgentMessageFeedbackWithMetadataType)[]
> {
const where: WhereOptions<AgentMessageFeedback> = {
// IMPORTANT: Necessary for global models who share ids across workspaces.
workspaceId: workspace.id,
agentConfigurationId: agentConfiguration.sId.toString(),
};

if (paginationParams.lastValue) {
Expand All @@ -115,9 +117,6 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
[op]: paginationParams.lastValue,
};
}
if (agentConfiguration) {
where.agentConfigurationId = agentConfiguration.sId.toString();
}

const agentMessageFeedback = await AgentMessageFeedback.findAll({
where,
Expand Down Expand Up @@ -148,6 +147,7 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
},
],
order: [
["agentConfigurationVersion", "DESC"],
[
paginationParams.orderColumn,
paginationParams.orderDirection === "desc" ? "DESC" : "ASC",
Expand Down
2 changes: 1 addition & 1 deletion front/lib/swr/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function useAgentConfiguration({
};
}

export function useAgentConfigurationFeedbacks({
export function useAgentConfigurationFeedbacksByDescVersion({
workspaceId,
agentConfigurationId,
withMetadata,
Expand Down

0 comments on commit 567745b

Please sign in to comment.