mirror of
https://github.com/hpware/news-analyze.git
synced 2025-07-16 19:19:33 +08:00
Remove stuff including the chat function & TOS & Privacy Policy windows
& simplified the archive URL.
This commit is contained in:
parent
aa8fb3a2d2
commit
3a3c2c81e2
@ -1,224 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
History,
|
||||
Plus,
|
||||
Send,
|
||||
Square,
|
||||
User,
|
||||
BotMessageSquare,
|
||||
} from "lucide-vue-next";
|
||||
import { Input } from "~/components/ui/input";
|
||||
import blurPageBeforeLogin from "~/components/blurPageBeforeLogin.vue";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
const { t } = useI18n();
|
||||
const cookie = useCookie("lastChatId");
|
||||
const cookieChatId = cookie.value;
|
||||
const chatId = ref();
|
||||
const inputMessage = ref();
|
||||
const messageIndex = ref();
|
||||
const aiGenerating = ref(false);
|
||||
const messages = ref<any[]>([]);
|
||||
const newsId = ref("");
|
||||
const isStreaming = ref(false);
|
||||
const streamingMessage = ref("");
|
||||
const messagesContainer = ref(null);
|
||||
|
||||
// Great, there are now no errors ig
|
||||
const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
||||
const props = defineProps<{
|
||||
values?: string;
|
||||
}>();
|
||||
|
||||
const sendChatData = async (event?: KeyboardEvent) => {
|
||||
if (event?.shiftKey) return;
|
||||
if (inputMessage.value === "") return;
|
||||
const userMessage = inputMessage.value;
|
||||
inputMessage.value = "";
|
||||
aiGenerating.value = true;
|
||||
await sendMessage(userMessage);
|
||||
};
|
||||
|
||||
const stopChatGenerate = () => {
|
||||
aiGenerating.value = false;
|
||||
};
|
||||
|
||||
const chatUuid = ref("");
|
||||
|
||||
onMounted(() => {
|
||||
chatUuid.value = uuidv4();
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
/*const {
|
||||
data: getData,
|
||||
pending,
|
||||
error,
|
||||
} = useFetch(`/api/ai/chat/${chatId.value}`);*/
|
||||
});
|
||||
|
||||
const sendMessage = async (newMessage: any) => {
|
||||
if (!newMessage.trim() || !newsId.value.trim() || isStreaming.value) {
|
||||
return;
|
||||
}
|
||||
messages.value.push({
|
||||
index: messageIndex.value,
|
||||
id: uuidv4(),
|
||||
message: newMessage,
|
||||
user: true,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
messageIndex.value += 1;
|
||||
|
||||
try {
|
||||
isStreaming.value = true;
|
||||
streamingMessage.value = "";
|
||||
|
||||
const response = await fetch(`/api/ai/chat/${chatUuid.value}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
message: newMessage,
|
||||
newsid: newsId.value,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const reader = response.body?.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
if (reader) {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
|
||||
if (done) break;
|
||||
|
||||
const chunk = decoder.decode(value, { stream: true });
|
||||
streamingMessage.value += chunk;
|
||||
await scrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the complete assistant message
|
||||
if (streamingMessage.value) {
|
||||
messages.value.push({
|
||||
role: "assistant",
|
||||
content: streamingMessage.value,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error sending message:", error);
|
||||
messages.value.push({
|
||||
role: "assistant",
|
||||
content: "Sorry, there was an error processing your message.",
|
||||
timestamp: new Date(),
|
||||
});
|
||||
} finally {
|
||||
isStreaming.value = false;
|
||||
streamingMessage.value = "";
|
||||
await scrollToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
const formatMessage = (content: any) => {
|
||||
// Simple markdown-like formatting
|
||||
return content
|
||||
.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>")
|
||||
.replace(/\*(.*?)\*/g, "<em>$1</em>")
|
||||
.replace(/\n/g, "<br>");
|
||||
};
|
||||
const formatTime = (timestamp: any) => {
|
||||
return new Intl.DateTimeFormat("zh-TW", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
}).format(timestamp);
|
||||
};
|
||||
const scrollToBottom = () => {};
|
||||
</script>
|
||||
<template>
|
||||
<blurPageBeforeLogin>
|
||||
<div class="flex flex-col h-[100%] w-full">
|
||||
<div>
|
||||
<div
|
||||
class="justify-center align-center text-center flex flex-col sticky top-0 pt-2 min-h-0 border rounded-2xl gray-500/80 backdrop-blur-sm"
|
||||
>
|
||||
<div class="flex flex-row justify-between p-2">
|
||||
<h2 class="text-xl ml-4 text-bold">Chat Name</h2>
|
||||
<div class="flex flex-row justify-center align-center text-center">
|
||||
<div
|
||||
class="flex flex-row justify-center align-center text-center gap-2"
|
||||
>
|
||||
<button
|
||||
class="p-2 rounded-xl hover:bg-gray-300 transition-all duration-400"
|
||||
>
|
||||
<History class="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
class="p-2 rounded-xl hover:bg-gray-300 transition-all duration-400"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
ref="chatContainerRef"
|
||||
class="flex-1 overflow-y-auto p-4 space-y-4"
|
||||
>
|
||||
<div
|
||||
v-for="message in messages"
|
||||
class="max-w-[80%] p-3 bg-gray-300/70 rounded-xl"
|
||||
>
|
||||
<div v-if="message.user" class="flex flex-row gap-2">
|
||||
<User class="w-5 h-5" />{{ message.message }}
|
||||
</div>
|
||||
<div v-else class="flex flex-row gap-2">
|
||||
<BotMessageSquare class="w-5 h-5" />{{ message.message }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isStreaming" class="">
|
||||
<div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="h-[75px]"></div>
|
||||
<div
|
||||
class="space-x-2 absolute bottom-2 inset-x-4 border-t p-2 min-h-0 border rounded-xl gray-500/80 backdrop-blur-sm"
|
||||
>
|
||||
<div class="text-black w-full flex flex-row">
|
||||
<Input
|
||||
class="flex-1 rounded-xl"
|
||||
placeholder="Type a message..."
|
||||
v-model="inputMessage"
|
||||
@keyup.enter="sendChatData($event)"
|
||||
:disabled="aiGenerating"
|
||||
/>
|
||||
<button
|
||||
class="pl-2 pr-2 mr-1 ml-1 bg-black text-white rounded-full hover:bg-gray-700 hover:translate-y-[-4px] transition-all duration-300 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:bg-color-500"
|
||||
:disabled="!inputMessage?.trim()"
|
||||
@click="sendChatData()"
|
||||
v-if="!aiGenerating"
|
||||
>
|
||||
<Send class="w-5 h-5" />
|
||||
</button>
|
||||
<button
|
||||
class="pl-2 pr-2 mr-1 ml-1 bg-black text-white rounded-full hover:bg-gray-700 hover:translate-y-[-4px] transition-all duration-300 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:bg-color-500"
|
||||
@click="stopChatGenerate"
|
||||
v-else
|
||||
>
|
||||
<Square class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<span class="text-xs text-center justify-center align-center w-full"
|
||||
>Note: AI might create imbalanced views.</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</blurPageBeforeLogin>
|
||||
</template>
|
@ -53,7 +53,7 @@ const contentArray = ref([]);
|
||||
const errorr = ref(false);
|
||||
const switchTabs = ref(false);
|
||||
const tabs = ref([]);
|
||||
const primary = ref<string>("domestic"); // Hard code default value as top is just pure garbage.
|
||||
const primary = ref<string>("top"); // This will be later overwritten, so values set here will be useless.
|
||||
const canNotLoadTabUI = ref(false);
|
||||
const isDataCached = ref(false);
|
||||
const pullTabsData = async () => {
|
||||
|
@ -117,7 +117,7 @@ const starArticle = async () => {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const req = await fetch(`/user/${slug}/star`);
|
||||
const req = await fetch(`/api/user/${slug}/star`);
|
||||
const res = await req.json();
|
||||
staredStatus.value = res;
|
||||
});
|
||||
@ -137,7 +137,7 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div
|
||||
v-if="loadingTranslations"
|
||||
class="flex flex-col bg-gray-200/50 text-black w-full h-full absolute inset-0 justify-center align-middle text-center z-[20] backdrop-blur-sm"
|
||||
class="flex flex-col bg-gray-200/50 text-black w-full h-full fixed inset-0 justify-center align-middle text-center z-[20] backdrop-blur-sm"
|
||||
>
|
||||
<!--Spinner from https://flowbite.com/docs/components/spinner/-->
|
||||
<div role="status">
|
||||
@ -164,10 +164,7 @@ onMounted(async () => {
|
||||
class="justify-center align-center text-center flex flex-col md:flex-row flex-wrap"
|
||||
>
|
||||
<div class="flex flex-col">
|
||||
<div class="p-4 w-full h-fit pt-0 mt-0">
|
||||
<img v-if="data.images[0]" :src="data.images[0]" class="rounded" />
|
||||
</div>
|
||||
<div class="group -translate-y-12 backdrop-blur-lg bg-gray-300/40">
|
||||
<div class="group translate-y-12">
|
||||
<h2 class="text-3xl text-bold">
|
||||
{{
|
||||
displayTranslatedText
|
||||
@ -189,6 +186,9 @@ onMounted(async () => {
|
||||
}}</span
|
||||
>
|
||||
</div>
|
||||
<div class="p-4 w-full h-fit pt-0 mt-0">
|
||||
<img v-if="data.images[0]" :src="data.images[0]" class="rounded" />
|
||||
</div>
|
||||
<div class="text-center" v-for="item in data.paragraph">
|
||||
{{ displayTranslatedText ? translateItem[item]?.translateText : item }}
|
||||
</div>
|
||||
@ -212,16 +212,6 @@ onMounted(async () => {
|
||||
<div v-else>{{ summaryText }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="flex flex-col bg-gray-500">
|
||||
<!--Similar articles-->
|
||||
<!--<div class="flex flex-row" v-for="item in likeart">
|
||||
<img /><!--Image-->
|
||||
<!--<div class="flex flex-col">
|
||||
<h2>title</h2>
|
||||
<span>description</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
<button
|
||||
@click="starArticle"
|
||||
:class="[
|
||||
|
@ -1,9 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
<template>
|
||||
<div class="justify-center align-center text-center">
|
||||
<h1 class="text-2xl text-bold">{{ t("pages.privacypolicy.title") }}</h1>
|
||||
<p>{{ t("pages.privacypolicy.content") }}</p>
|
||||
</div>
|
||||
</template>
|
@ -380,23 +380,6 @@ const submitUserPassword = async () => {
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div
|
||||
class="flex flex-row gap-2 m-1 p-2 justify-center align-center text-center"
|
||||
>
|
||||
<button
|
||||
class="bg-sky-400 p-1 rounded hover:bg-sky-600 transition-all duration-200 w-32"
|
||||
@click="() => emit('windowopener', 'privacypolicy')"
|
||||
>
|
||||
Privacy Policy
|
||||
</button>
|
||||
<button
|
||||
class="bg-sky-400 p-1 rounded hover:bg-sky-600 transition-all duration-200 w-32"
|
||||
@click="() => emit('windowopener', 'tos')"
|
||||
>
|
||||
TOS
|
||||
</button>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="justiy-center align-center text-center">
|
||||
{{ t("app.settings") }} v0.0.3 || Version: {{ getVersionTag() }}
|
||||
</div>
|
||||
|
@ -1,9 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
<template>
|
||||
<div class="justify-center align-center text-center">
|
||||
<h1 class="text-2xl text-bold">{{ t("pages.tos.title") }}</h1>
|
||||
<p>{{ t("pages.tos.content") }}</p>
|
||||
</div>
|
||||
</template>
|
@ -1,78 +0,0 @@
|
||||
<script setup lamng="ts">
|
||||
// Great, there are now no errors ig
|
||||
const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
||||
import sha512 from "crypto-js/sha512";
|
||||
import Input from "~/components/ui/input/Input.vue";
|
||||
const userAccount = ref("");
|
||||
const userPassword = ref("");
|
||||
const error = ref(false);
|
||||
const errormsg = ref("");
|
||||
const success = ref(false);
|
||||
const submitUserPassword = async () => {
|
||||
error.value = false;
|
||||
errormsg.value = "";
|
||||
// Encrypt password during transit
|
||||
const password = sha512(userPassword.value).toString();
|
||||
|
||||
// Send data.
|
||||
const sendData = await fetch("/api/user/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: userAccount.value,
|
||||
password: password,
|
||||
}),
|
||||
});
|
||||
const res = await sendData.json();
|
||||
|
||||
if (!res.error) {
|
||||
error.value = false;
|
||||
success.value = true;
|
||||
console.log(res);
|
||||
userAccount.value = "";
|
||||
} else {
|
||||
error.value = true;
|
||||
errormsg.value = res.error;
|
||||
}
|
||||
userPassword.value = "";
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<div class="">
|
||||
<form
|
||||
class="flex flex-col items-center justify-center h-full"
|
||||
@submit.prevent="submitUserPassword"
|
||||
v-if="!success"
|
||||
>
|
||||
<span class="text-2xl text-bold mb-0">Login / Register</span>
|
||||
<span class="mb-4 text-sm mt-0"
|
||||
>We will create a account for you if you don't have one.</span
|
||||
>
|
||||
<div class="">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
class="mb-2 p-2 border rounded"
|
||||
v-model="userAccount"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
class="p-2 border rounded mb-2"
|
||||
v-model="userPassword"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<span v-if="error" class="text-red-600 text-xs m-2"
|
||||
>Error: {{ errormsg }}</span
|
||||
>
|
||||
<button class="bg-black text-white p-2 rounded transition duration-200">
|
||||
Log In
|
||||
</button>
|
||||
</form>
|
||||
<div v-else>Hi! ${user}</div>
|
||||
</div>
|
||||
</template>
|
@ -45,11 +45,11 @@
|
||||
"apis": "APIs"
|
||||
},
|
||||
"description": {
|
||||
"find": "You can easily find the same topic from different news sources.",
|
||||
"interface": "Use a desktop like interface, the one that you already got used to.",
|
||||
"documentation": "We provide a documentation for you to learn how to use the app.",
|
||||
"opensource": "This platform is open source! minus the database part, but I'm going to try!",
|
||||
"apis": "We use api's that are made via reverse engineering."
|
||||
"find": "You can find the same topic from different news sources.",
|
||||
"interface": "This platform uses a desktop like interface, the one that you already got used to.",
|
||||
"documentation": "We provide a video for you to learn how to use the basics of the application.",
|
||||
"opensource": "This platform is open source!",
|
||||
"apis": "We use api's that are made via reverse engineering, here https://github.com/hpware/reverse_engineering"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -116,16 +116,6 @@
|
||||
"noadlinetoday": "Provides free, no ads Line today."
|
||||
}
|
||||
},
|
||||
"pages": {
|
||||
"privacypolicy": {
|
||||
"title": "Privacy Policy",
|
||||
"content": "Ummmm"
|
||||
},
|
||||
"tos": {
|
||||
"title": "Terms of service",
|
||||
"content": "N/A"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
"why": "Why make this website?",
|
||||
"bulletpoints": {
|
||||
|
@ -48,7 +48,7 @@
|
||||
"find": "你可以輕鬆地從不同的新聞來源找到相同的主題。",
|
||||
"interface": "這個網站使用類似 Xfce / MacOS / DSM 的介面,讓你可以簡單使用這個網站。",
|
||||
"documentation": "我做了一組教學,讓你可以學會如何使用這個網站 UI。",
|
||||
"opensource": "這個平台的所有程式碼都放在Github上,沒有開源的資料庫,我會想辦法把它用其他方式開源!",
|
||||
"opensource": "這個平台的所有程式碼都放在Github上!",
|
||||
"apis": "我們使用LINE Today 的資訊來做出一個 API。"
|
||||
}
|
||||
}
|
||||
|
@ -51,18 +51,14 @@ import translate from "translate";
|
||||
import checkAppVersion from "~/components/checkAppVersion";
|
||||
|
||||
// Import Windows
|
||||
import UserWindow from "~/components/app/windows/user.vue";
|
||||
import SourcesWindow from "~/components/app/windows/sources.vue";
|
||||
import AboutWindow from "~/components/app/windows/about.vue";
|
||||
import ChatbotWindow from "~/components/app/windows/chatbot.vue";
|
||||
import AboutNewsOrgWindow from "~/components/app/windows/aboutNewsOrg.vue";
|
||||
import TTYWindow from "~/components/app/windows/tty.vue";
|
||||
import FavStaredWindow from "~/components/app/windows/fav.vue";
|
||||
import NewsWindow from "~/components/app/windows/news.vue";
|
||||
import NewsViewWindow from "~/components/app/windows/newsView.vue";
|
||||
import SettingsWindow from "~/components/app/windows/settings.vue";
|
||||
import PrivacyPolicyWindow from "~/components/app/windows/privacypolicy.vue";
|
||||
import TOSWindow from "~/components/app/windows/tos.vue";
|
||||
import onBoardingWindow from "~/components/app/windows/onBoarding.vue";
|
||||
|
||||
// Import Icons
|
||||
@ -83,7 +79,6 @@ const route = useRoute();
|
||||
// values
|
||||
const popMessage = ref(null);
|
||||
const menuOpen = ref(false);
|
||||
2;
|
||||
const currentNavBar = ref<currentNavBarInterface[]>([]);
|
||||
const bootingAnimation = ref(true);
|
||||
const activeWindows = ref<associAppWindowInterface[]>([]);
|
||||
@ -107,7 +102,6 @@ const menuItems = [
|
||||
{ name: t("app.news"), windowName: "news" },
|
||||
{ name: t("app.sources"), windowName: "sources" },
|
||||
{ name: t("app.starred"), windowName: "starred" },
|
||||
{ name: t("app.chatbot"), windowName: "chatbot" },
|
||||
{ name: t("app.about"), windowName: "about" },
|
||||
{ name: t("app.terminal"), windowName: "tty" },
|
||||
{ name: t("app.settings"), windowName: "settings" },
|
||||
@ -115,13 +109,6 @@ const menuItems = [
|
||||
];
|
||||
|
||||
const associAppWindow = [
|
||||
{
|
||||
name: "login",
|
||||
id: "2",
|
||||
title: t("app.login"),
|
||||
component: UserWindow,
|
||||
translatable: false,
|
||||
},
|
||||
{
|
||||
name: "sources",
|
||||
id: "3",
|
||||
@ -161,15 +148,6 @@ const associAppWindow = [
|
||||
component: FavStaredWindow,
|
||||
translatable: true,
|
||||
},
|
||||
{
|
||||
name: "chatbot",
|
||||
id: "8",
|
||||
title: t("app.chatbot"),
|
||||
component: ChatbotWindow,
|
||||
width: "400px",
|
||||
height: "600px",
|
||||
translatable: false,
|
||||
},
|
||||
{
|
||||
name: "aboutNewsOrg",
|
||||
id: "9",
|
||||
@ -192,20 +170,6 @@ const associAppWindow = [
|
||||
component: NewsViewWindow,
|
||||
translatable: true,
|
||||
},
|
||||
{
|
||||
name: "privacypolicy",
|
||||
id: "12",
|
||||
title: t("app.privacypolicy"),
|
||||
component: PrivacyPolicyWindow,
|
||||
translatable: false,
|
||||
},
|
||||
{
|
||||
name: "tos",
|
||||
id: "13",
|
||||
title: t("app.tos"),
|
||||
component: TOSWindow,
|
||||
translatable: false,
|
||||
},
|
||||
{
|
||||
name: "onboard",
|
||||
id: "14",
|
||||
@ -749,7 +713,10 @@ setInterval(async () => {
|
||||
>
|
||||
{{ t("popup.stay") }}
|
||||
</Button>
|
||||
<Button @click="() => switchLocalePath()" variant="outline">
|
||||
<Button
|
||||
@click="() => switchLocalePath(`${lang !== en' ? 'en' : 'zh-TW'}`)"
|
||||
variant="outline"
|
||||
>
|
||||
{{ t("popup.change") }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
@ -820,7 +787,8 @@ setInterval(async () => {
|
||||
</DraggableWindow>
|
||||
</div>
|
||||
</Transition>
|
||||
<div v-if="confetiActive">
|
||||
<!--TODO: ADD CONFETI-->
|
||||
<!-- <div v-if="confetiActive">
|
||||
<div v-ref="successcanvas"></div>
|
||||
</div>
|
||||
</div>-->
|
||||
</template>
|
||||
|
@ -1,95 +0,0 @@
|
||||
import { Groq } from "groq-sdk";
|
||||
import sql from "~/server/components/postgres";
|
||||
|
||||
const groq = new Groq();
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const host = getRequestHost(event);
|
||||
const protocol = getRequestProtocol(event);
|
||||
const hears = getRequestHeaders(event);
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const body = await readBody(event);
|
||||
if (!slug) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "A UUID is required for this action.",
|
||||
});
|
||||
}
|
||||
|
||||
const getChatHistory = await sql`
|
||||
select * from chat_history
|
||||
where uuid = ${slug}
|
||||
order by created_at asc
|
||||
`;
|
||||
|
||||
const buildURL = protocol + "://" + host + "/api/news/get/lt/" + "LX30VwG";
|
||||
const data = await fetch(buildURL);
|
||||
const fetchNewsArticle = await data.json();
|
||||
|
||||
// Set headers for Server-Sent Events
|
||||
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
||||
setHeader(event, "Cache-Control", "no-cache");
|
||||
setHeader(event, "Connection", "keep-alive");
|
||||
setHeader(event, "Access-Control-Allow-Origin", "*");
|
||||
|
||||
const chatCompletion = await groq.chat.completions.create({
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: `You are a news chat, the following content will be used to chat with the user title: ${fetchNewsArticle.title} article: ${fetchNewsArticle.paragraph} origin: ${fetchNewsArticle.origin} author: ${fetchNewsArticle.author}`,
|
||||
},
|
||||
...getChatHistory.map((chat) => ({
|
||||
role: chat.role,
|
||||
content: chat.content,
|
||||
})),
|
||||
{
|
||||
role: "user",
|
||||
content: body.message,
|
||||
},
|
||||
],
|
||||
model: "gemma2-9b-it",
|
||||
temperature: 0.71,
|
||||
max_completion_tokens: 1024,
|
||||
top_p: 1,
|
||||
stream: true,
|
||||
stop: null,
|
||||
});
|
||||
|
||||
/*
|
||||
await sql`
|
||||
INSERT INTO chat_history (uuid, role, content)
|
||||
VALUES (${slug}, 'user', ${body.message})
|
||||
`; */
|
||||
|
||||
let assistantResponse = "";
|
||||
|
||||
// Create a readable stream
|
||||
const stream = new ReadableStream({
|
||||
async start(controller) {
|
||||
try {
|
||||
for await (const chunk of chatCompletion) {
|
||||
const content = chunk.choices[0]?.delta?.content || "";
|
||||
if (content) {
|
||||
assistantResponse += content;
|
||||
// Send chunk to client
|
||||
controller.enqueue(new TextEncoder().encode(content));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (assistantResponse) {
|
||||
await sql`
|
||||
INSERT INTO chat_history (uuid, role, content)
|
||||
VALUES (${slug}, 'assistant', ${assistantResponse})
|
||||
`;
|
||||
} */
|
||||
|
||||
controller.close();
|
||||
} catch (error) {
|
||||
controller.error(error);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return sendStream(event, stream);
|
||||
});
|
@ -1,5 +0,0 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
return {
|
||||
hello: "hello",
|
||||
};
|
||||
});
|
@ -1,64 +0,0 @@
|
||||
# Server Fixed
|
||||
(This file is NOT related to neighbourhood, but it is some stuff I learned during the down time of the server)
|
||||
|
||||
## Timeline
|
||||
Aprox. 10 PM UTC+8 - I found out that the server is running an outdated version of the app and tried using `docker compose pull`, but saw 192.168.1.1:53 is not a Server, and tried to fix it, and broke off the connection to the internet.
|
||||
|
||||
11:40-ish PM UTC+8 Server is back online.
|
||||
|
||||
## So what is the issue?
|
||||
Well, My issue is one of my config files included a "on", which is why the PPPoE conenction does not work anymore.
|
||||
|
||||
Image:
|
||||

|
||||
|
||||
And also I wrote a super stupid cron fix, which is below.
|
||||
|
||||
## My stupid cron fix:
|
||||
Cron Job:
|
||||
```
|
||||
0 * * * * "bun run /hardpushrevolvconf.ts" > /dev/null
|
||||
```
|
||||
|
||||
Here is the script I used to force the change of my resolv.conf file:
|
||||
```typescript
|
||||
import { file, $ } from "bun";
|
||||
|
||||
function sendDataToSlack(text: string) {
|
||||
fetch("{slack_web_hook_to_one_of_my_channels_in_hackclub}", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application-json"
|
||||
},
|
||||
body: JSON.stringify({ text: text })
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
const resolvConfPath = "/etc/resolv.conf";
|
||||
const resolvConf = file(resolvConfPath);
|
||||
const resolvConfText = await resolvConf.text();
|
||||
|
||||
if (resolvConfText.includes("192.168.1.1")) {
|
||||
// Auto git config
|
||||
await $`git add .`
|
||||
await $`git commit -a -m "Auto Commit by the server ${Date().now}, before doing stuff into resolvConf"`
|
||||
try {
|
||||
await resolvConf.write("nameserver 8.8.8.8\n");
|
||||
sendDataToSlack(`${resolvConfPath} updated successfully.`);
|
||||
} catch (error) {
|
||||
sendDataToSlack(`Failed to write to ${resolvConfPath}:`, error);
|
||||
sendDataToSlack(
|
||||
"This likely happened because you didn't run the script with root privileges (e.g., 'sudo bun run script.ts')."
|
||||
);
|
||||
}
|
||||
await $`git add .`
|
||||
await $`git commit -a -m "Auto Commit by the server ${Date().now}, after doing stuff into resolvConf"`
|
||||
await $`git push`
|
||||
} else {
|
||||
sendDataToSlack(
|
||||
"Did not find '192.168.1.1'. No changes have been made."
|
||||
);
|
||||
}
|
||||
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user