This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
"use client";
|
||||
|
||||
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 MenuItem from "@/components/listview/MenuItem";
|
||||
import MenuItemRenderer from "@/components/listview/MenuItemRenderer";
|
||||
import { toast } from "@/components/Toast";
|
||||
import { extractErrorMessage } from "@/lib/func";
|
||||
import { glassSurfaceFlat } from "@/lib/styles/glassSurface";
|
||||
@@ -11,11 +14,13 @@ import { FormEvent, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useChat } from "./hooks/useAiData";
|
||||
import { AI_SUGGESTIONS } from "./suggestions";
|
||||
import type { ChatFood } from "./types/Types";
|
||||
|
||||
type Message = {
|
||||
id: string;
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
foods?: ChatFood[];
|
||||
};
|
||||
|
||||
function getGreetingKey() {
|
||||
@@ -26,6 +31,26 @@ function getGreetingKey() {
|
||||
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() {
|
||||
const { t } = useTranslation("common", { keyPrefix: "AI" });
|
||||
const { data: about } = useGetAbout();
|
||||
@@ -62,6 +87,7 @@ function AiPage() {
|
||||
id: `a-${Date.now()}`,
|
||||
role: "assistant",
|
||||
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">
|
||||
{messages.map((message) => {
|
||||
const isUser = message.role === "user";
|
||||
const hasFoods = !isUser && !!message.foods?.length;
|
||||
|
||||
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
|
||||
className={
|
||||
isUser
|
||||
@@ -97,6 +125,16 @@ function AiPage() {
|
||||
>
|
||||
<p className="text-xs2 leading-5 whitespace-pre-wrap">{message.content}</p>
|
||||
</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>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -4,8 +4,20 @@ export type ChatRequest = {
|
||||
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 = {
|
||||
answer: string;
|
||||
foods?: ChatFood[];
|
||||
consumedTokens: number;
|
||||
cost: 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 = "http://192.168.99.131:2000";
|
||||
export const API_BASE_URL = "https://dmenu-api.danakcorp.com";
|
||||
export const API_BASE_URL = "http://10.202.59.88:2000";
|
||||
// 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");
|
||||
export const TOKEN_NAME = "dmenu-t";
|
||||
export const REFRESH_TOKEN_NAME = "dmenu-rt";
|
||||
|
||||
Reference in New Issue
Block a user