File tree 11 files changed +34
-411
lines changed
11 files changed +34
-411
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import "./globals.css" ;
2
2
import type { Metadata , Viewport } from "next" ;
3
3
import React from "react" ;
4
- import { Analytics } from "@vercel/analytics/react" ;
5
- import { ThemeProvider } from "@/components/theme-provider" ;
6
4
import Umami from "@/components/umami" ;
5
+ import { ThemeProvider } from "next-themes" ;
7
6
8
7
export const metadata : Metadata = {
9
8
title : "AI 算卦 - 在线卜卦 GPT4 解读" ,
@@ -34,14 +33,13 @@ export default function RootLayout({
34
33
< html lang = "cn" suppressHydrationWarning >
35
34
< body >
36
35
< ThemeProvider
36
+ enableSystem
37
37
attribute = "class"
38
38
defaultTheme = "system"
39
- enableSystem
40
39
disableTransitionOnChange
41
40
>
42
41
{ children }
43
42
</ ThemeProvider >
44
- { process . env . VERCEL && < Analytics /> }
45
43
< Umami />
46
44
</ body >
47
45
</ html >
Original file line number Diff line number Diff line change 2
2
import { streamText } from "ai" ;
3
3
import { createOpenAI } from "@ai-sdk/openai" ;
4
4
import { createStreamableValue } from "ai/rsc" ;
5
+ import { ERROR_PREFIX } from "@/lib/constant" ;
5
6
6
7
const model = process . env . OPENAI_MODEL ?? "gpt-3.5-turbo" ;
7
8
const openai = createOpenAI ( { baseURL : process . env . OPENAI_BASE_URL } ) ;
@@ -15,6 +16,7 @@ export async function getAnswer(
15
16
guaName : string ,
16
17
guaChange : string ,
17
18
) {
19
+ console . log ( prompt , guaName , guaChange ) ;
18
20
const stream = createStreamableValue ( ) ;
19
21
try {
20
22
// const res = await fetch(
@@ -68,7 +70,7 @@ export async function getAnswer(
68
70
break ;
69
71
case "error" :
70
72
const err = part . error as any ;
71
- buffer += err . message ?? err . toString ( ) ;
73
+ stream . update ( ERROR_PREFIX + ( err . message ?? err . toString ( ) ) ) ;
72
74
break ;
73
75
}
74
76
}
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { getAnswer } from "@/app/server";
13
13
import { readStreamableValue } from "ai/rsc" ;
14
14
import { Button } from "./ui/button" ;
15
15
import { BrainCircuit , ListRestart } from "lucide-react" ;
16
+ import { ERROR_PREFIX } from "@/lib/constant" ;
16
17
17
18
const AUTO_DELAY = 1000 ;
18
19
@@ -39,6 +40,10 @@ function Divination() {
39
40
if ( data ) {
40
41
let ret = "" ;
41
42
for await ( const delta of readStreamableValue ( data ) ) {
43
+ if ( delta . startsWith ( ERROR_PREFIX ) ) {
44
+ setError ( delta . slice ( ERROR_PREFIX . length ) ) ;
45
+ return ;
46
+ }
42
47
ret += delta ;
43
48
setCompletion ( ret ) ;
44
49
}
@@ -209,7 +214,7 @@ function Divination() {
209
214
) }
210
215
211
216
{ ! inputQuestion && hexagramList . length != 0 && (
212
- < div className = "flex gap-2" >
217
+ < div className = "flex max-w-md gap-2" >
213
218
< Hexagram list = { hexagramList } />
214
219
{ showResult && (
215
220
< div className = "flex flex-col justify-around" >
Original file line number Diff line number Diff line change @@ -55,8 +55,9 @@ function ResultAI({
55
55
return (
56
56
< div className = "h-0 w-full flex-1 sm:max-w-md md:max-w-2xl" >
57
57
{ 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" >
60
61
< RotateCw size = { 16 } className = "animate-spin" />
61
62
< span className = "ml-1 text-sm" > AI 分析中...</ span >
62
63
</ div >
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export interface ResultObj {
9
9
10
10
function Result ( props : ResultObj ) {
11
11
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 " >
13
13
< a
14
14
className = "flex items-center gap-1 font-medium text-primary/80 underline underline-offset-4 transition-colors hover:text-primary/100"
15
15
href = { `https://zhouyi.sunls.de/${ props . guaMark } /` }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
export const ERROR_PREFIX = "::error::" ;
2
-
3
- export interface History {
4
- date : string ;
5
- prompt : string ;
6
- gua : string ;
7
- change : string ;
8
- }
9
-
10
2
export const VERSION = "1.2.3" ;
Original file line number Diff line number Diff line change @@ -4,14 +4,3 @@ import { twMerge } from "tailwind-merge";
4
4
export function cn ( ...inputs : ClassValue [ ] ) {
5
5
return twMerge ( clsx ( inputs ) ) ;
6
6
}
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 12
12
"@ai-sdk/openai" : " ^1.0.8" ,
13
13
"@radix-ui/react-dropdown-menu" : " ^2.1.3" ,
14
14
"@radix-ui/react-slot" : " ^1.1.1" ,
15
- "@vercel/analytics" : " ^1.4.1" ,
16
15
"ai" : " ^4.0.18" ,
17
16
"aimless.js" : " ^1.0.4" ,
18
17
"class-variance-authority" : " ^0.7.1" ,
You can’t perform that action at this time.
0 commit comments