This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useGetAbout } from "@/app/[name]/(Main)/about/hooks/useAboutData";
|
import { useGetAbout } from "@/app/[name]/(Main)/about/hooks/useAboutData";
|
||||||
|
import type { Food } from "@/app/[name]/(Main)/types/Types";
|
||||||
import { useGetProfile } from "@/app/[name]/(Profile)/profile/hooks/userProfileData";
|
import { useGetProfile } from "@/app/[name]/(Profile)/profile/hooks/userProfileData";
|
||||||
|
import MenuItem from "@/components/listview/MenuItem";
|
||||||
|
import MenuItemRenderer from "@/components/listview/MenuItemRenderer";
|
||||||
import { toast } from "@/components/Toast";
|
import { toast } from "@/components/Toast";
|
||||||
import { extractErrorMessage } from "@/lib/func";
|
import { extractErrorMessage } from "@/lib/func";
|
||||||
import { glassSurfaceFlat } from "@/lib/styles/glassSurface";
|
import { glassSurfaceFlat } from "@/lib/styles/glassSurface";
|
||||||
@@ -11,11 +14,13 @@ import { FormEvent, useEffect, useRef, useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useChat } from "./hooks/useAiData";
|
import { useChat } from "./hooks/useAiData";
|
||||||
import { AI_SUGGESTIONS } from "./suggestions";
|
import { AI_SUGGESTIONS } from "./suggestions";
|
||||||
|
import type { ChatFood } from "./types/Types";
|
||||||
|
|
||||||
type Message = {
|
type Message = {
|
||||||
id: string;
|
id: string;
|
||||||
role: "user" | "assistant";
|
role: "user" | "assistant";
|
||||||
content: string;
|
content: string;
|
||||||
|
foods?: ChatFood[];
|
||||||
};
|
};
|
||||||
|
|
||||||
function getGreetingKey() {
|
function getGreetingKey() {
|
||||||
@@ -26,6 +31,26 @@ function getGreetingKey() {
|
|||||||
return "evening";
|
return "evening";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toFood(food: ChatFood): Food {
|
||||||
|
return {
|
||||||
|
id: food.id,
|
||||||
|
category: "",
|
||||||
|
title: food.title,
|
||||||
|
desc: food.desc,
|
||||||
|
content: food.content ?? [],
|
||||||
|
price: food.price,
|
||||||
|
prepareTime: 0,
|
||||||
|
isActive: true,
|
||||||
|
images: food.images ?? [],
|
||||||
|
inPlaceServe: true,
|
||||||
|
pickupServe: true,
|
||||||
|
discount: food.discount ?? 0,
|
||||||
|
isSpecialOffer: food.isSpecialOffer ?? false,
|
||||||
|
isAvailable: true,
|
||||||
|
unavailabilityMessage: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function AiPage() {
|
function AiPage() {
|
||||||
const { t } = useTranslation("common", { keyPrefix: "AI" });
|
const { t } = useTranslation("common", { keyPrefix: "AI" });
|
||||||
const { data: about } = useGetAbout();
|
const { data: about } = useGetAbout();
|
||||||
@@ -62,6 +87,7 @@ function AiPage() {
|
|||||||
id: `a-${Date.now()}`,
|
id: `a-${Date.now()}`,
|
||||||
role: "assistant",
|
role: "assistant",
|
||||||
content: res.data.answer,
|
content: res.data.answer,
|
||||||
|
foods: res.data.foods?.length ? res.data.foods : undefined,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
@@ -86,8 +112,10 @@ function AiPage() {
|
|||||||
<ul ref={listRef} className="noscrollbar flex-1 space-y-3 overflow-y-auto pb-4">
|
<ul ref={listRef} className="noscrollbar flex-1 space-y-3 overflow-y-auto pb-4">
|
||||||
{messages.map((message) => {
|
{messages.map((message) => {
|
||||||
const isUser = message.role === "user";
|
const isUser = message.role === "user";
|
||||||
|
const hasFoods = !isUser && !!message.foods?.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={message.id} className={`flex ${isUser ? "justify-end" : "justify-start"}`}>
|
<li key={message.id} className={`flex flex-col gap-2 ${isUser ? "items-end" : "items-start"}`}>
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
isUser
|
isUser
|
||||||
@@ -97,6 +125,16 @@ function AiPage() {
|
|||||||
>
|
>
|
||||||
<p className="text-xs2 leading-5 whitespace-pre-wrap">{message.content}</p>
|
<p className="text-xs2 leading-5 whitespace-pre-wrap">{message.content}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{hasFoods && (
|
||||||
|
<div className="flex w-full flex-col gap-2">
|
||||||
|
{message.foods!.map((food) => (
|
||||||
|
<MenuItemRenderer key={food.id}>
|
||||||
|
<MenuItem food={toFood(food)} />
|
||||||
|
</MenuItemRenderer>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -4,8 +4,20 @@ export type ChatRequest = {
|
|||||||
question: string;
|
question: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ChatFood = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
desc: string;
|
||||||
|
content: string[] | null;
|
||||||
|
price: number;
|
||||||
|
images: string[];
|
||||||
|
discount: number;
|
||||||
|
isSpecialOffer: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type ChatData = {
|
export type ChatData = {
|
||||||
answer: string;
|
answer: string;
|
||||||
|
foods?: ChatFood[];
|
||||||
consumedTokens: number;
|
consumedTokens: number;
|
||||||
cost: number;
|
cost: number;
|
||||||
promptTokens: number;
|
promptTokens: number;
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
// export const API_BASE_URL = "https://dmenuplus-api-production.dev.danakcorp.com";
|
// export const API_BASE_URL = "https://dmenuplus-api-production.dev.danakcorp.com";
|
||||||
// export const API_BASE_URL = "http://192.168.99.131:2000";
|
export const API_BASE_URL = "http://10.202.59.88:2000";
|
||||||
export const API_BASE_URL = "https://dmenu-api.danakcorp.com";
|
// export const API_BASE_URL = "https://dmenu-api.danakcorp.com";
|
||||||
process.env.NEXT_PUBLIC_API_URL ?? (process.env.NODE_ENV === "development" ? "http://192.168.99.131:2000" : "https://dmenu-api.danakcorp.com");
|
process.env.NEXT_PUBLIC_API_URL ?? (process.env.NODE_ENV === "development" ? "http://192.168.99.131:2000" : "https://dmenu-api.danakcorp.com");
|
||||||
export const TOKEN_NAME = "dmenu-t";
|
export const TOKEN_NAME = "dmenu-t";
|
||||||
export const REFRESH_TOKEN_NAME = "dmenu-rt";
|
export const REFRESH_TOKEN_NAME = "dmenu-rt";
|
||||||
|
|||||||
Reference in New Issue
Block a user