File tree Expand file tree Collapse file tree 11 files changed +34
-411
lines changed
Expand file tree Collapse file tree 11 files changed +34
-411
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import "./globals.css" ;
22import type { Metadata , Viewport } from "next" ;
33import React from "react" ;
4- import { Analytics } from "@vercel/analytics/react" ;
5- import { ThemeProvider } from "@/components/theme-provider" ;
64import Umami from "@/components/umami" ;
5+ import { ThemeProvider } from "next-themes" ;
76
87export const metadata : Metadata = {
98 title : "AI 算卦 - 在线卜卦 GPT4 解读" ,
@@ -34,14 +33,13 @@ export default function RootLayout({
3433 < html lang = "cn" suppressHydrationWarning >
3534 < body >
3635 < ThemeProvider
36+ enableSystem
3737 attribute = "class"
3838 defaultTheme = "system"
39- enableSystem
4039 disableTransitionOnChange
4140 >
4241 { children }
4342 </ ThemeProvider >
44- { process . env . VERCEL && < Analytics /> }
4543 < Umami />
4644 </ body >
4745 </ html >
Original file line number Diff line number Diff line change 22import { streamText } from "ai" ;
33import { createOpenAI } from "@ai-sdk/openai" ;
44import { createStreamableValue } from "ai/rsc" ;
5+ import { ERROR_PREFIX } from "@/lib/constant" ;
56
67const model = process . env . OPENAI_MODEL ?? "gpt-3.5-turbo" ;
78const openai = createOpenAI ( { baseURL : process . env . OPENAI_BASE_URL } ) ;
@@ -15,6 +16,7 @@ export async function getAnswer(
1516 guaName : string ,
1617 guaChange : string ,
1718) {
19+ console . log ( prompt , guaName , guaChange ) ;
1820 const stream = createStreamableValue ( ) ;
1921 try {
2022 // const res = await fetch(
@@ -68,7 +70,7 @@ export async function getAnswer(
6870 break ;
6971 case "error" :
7072 const err = part . error as any ;
71- buffer += err . message ?? err . toString ( ) ;
73+ stream . update ( ERROR_PREFIX + ( err . message ?? err . toString ( ) ) ) ;
7274 break ;
7375 }
7476 }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { getAnswer } from "@/app/server";
1313import { readStreamableValue } from "ai/rsc" ;
1414import { Button } from "./ui/button" ;
1515import { BrainCircuit , ListRestart } from "lucide-react" ;
16+ import { ERROR_PREFIX } from "@/lib/constant" ;
1617
1718const AUTO_DELAY = 1000 ;
1819
@@ -39,6 +40,10 @@ function Divination() {
3940 if ( data ) {
4041 let ret = "" ;
4142 for await ( const delta of readStreamableValue ( data ) ) {
43+ if ( delta . startsWith ( ERROR_PREFIX ) ) {
44+ setError ( delta . slice ( ERROR_PREFIX . length ) ) ;
45+ return ;
46+ }
4247 ret += delta ;
4348 setCompletion ( ret ) ;
4449 }
@@ -209,7 +214,7 @@ function Divination() {
209214 ) }
210215
211216 { ! inputQuestion && hexagramList . length != 0 && (
212- < div className = "flex gap-2" >
217+ < div className = "flex max-w-md gap-2" >
213218 < Hexagram list = { hexagramList } />
214219 { showResult && (
215220 < div className = "flex flex-col justify-around" >
Original file line number Diff line number Diff line change @@ -55,8 +55,9 @@ function ResultAI({
5555 return (
5656 < div className = "h-0 w-full flex-1 sm:max-w-md md:max-w-2xl" >
5757 { isLoading && (
58- < div className = "h-0" >
59- < div className = "relative -top-8 flex w-fit items-center text-muted-foreground sm:left-2" >
58+ < div className = "flex h-0" >
59+ < span className = "flex-1" />
60+ < div className = "relative -top-4 flex w-fit items-center pr-1 text-muted-foreground sm:left-2 sm:pr-3" >
6061 < RotateCw size = { 16 } className = "animate-spin" />
6162 < span className = "ml-1 text-sm" > AI 分析中...</ span >
6263 </ div >
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export interface ResultObj {
99
1010function Result ( props : ResultObj ) {
1111 return (
12- < div className = "flex flex-col items-start justify-center gap-2" >
12+ < div className = "flex flex-col items-start justify-center gap-2 sm:gap-3 " >
1313 < a
1414 className = "flex items-center gap-1 font-medium text-primary/80 underline underline-offset-4 transition-colors hover:text-primary/100"
1515 href = { `https://zhouyi.sunls.de/${ props . guaMark } /` }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11export const ERROR_PREFIX = "::error::" ;
2-
3- export interface History {
4- date : string ;
5- prompt : string ;
6- gua : string ;
7- change : string ;
8- }
9-
102export const VERSION = "1.2.3" ;
Original file line number Diff line number Diff line change @@ -4,14 +4,3 @@ import { twMerge } from "tailwind-merge";
44export function cn ( ...inputs : ClassValue [ ] ) {
55 return twMerge ( clsx ( inputs ) ) ;
66}
7-
8- export function getLocaleTime ( ) : string {
9- return fmtLocaleTime ( new Date ( ) ) ;
10- }
11-
12- export function fmtLocaleTime ( time : Date ) : string {
13- return time . toLocaleString ( "zh-CN" , {
14- timeZone : "Asia/Shanghai" ,
15- hourCycle : "h23" ,
16- } ) ;
17- }
Original file line number Diff line number Diff line change 1212 "@ai-sdk/openai" : " ^1.0.8" ,
1313 "@radix-ui/react-dropdown-menu" : " ^2.1.3" ,
1414 "@radix-ui/react-slot" : " ^1.1.1" ,
15- "@vercel/analytics" : " ^1.4.1" ,
1615 "ai" : " ^4.0.18" ,
1716 "aimless.js" : " ^1.0.4" ,
1817 "class-variance-authority" : " ^0.7.1" ,
You can’t perform that action at this time.
0 commit comments