|
1 | | -import { graphql, readFragment, type FragmentType } from "@/gql"; |
| 1 | +import { type FragmentType, graphql, readFragment } from "@/gql"; |
2 | 2 | import { getClient } from "@/lib/apollo.rsc"; |
3 | 3 | import { getAuthorizedUserInfo } from "@/lib/auth.rsc"; |
| 4 | +import { createPostHogClient } from "@/lib/posthog.rsc"; |
4 | 5 | import { anthropic, type AnthropicProviderOptions } from "@ai-sdk/anthropic"; |
| 6 | +import { withTracing } from "@posthog/ai"; |
5 | 7 | import { convertToModelMessages, stepCountIs, streamText, tool, type UIMessage } from "ai"; |
6 | | -import { withTracing } from "@posthog/ai" |
7 | 8 | import { NextResponse } from "next/server"; |
8 | 9 | import { z } from "zod"; |
9 | | -import { createPostHogClient } from "@/lib/posthog.rsc"; |
10 | 10 |
|
11 | 11 | export const maxDuration = 30; |
12 | 12 |
|
@@ -123,19 +123,19 @@ export async function POST(req: Request) { |
123 | 123 | providerOptions: { |
124 | 124 | anthropic: { |
125 | 125 | cacheControl: { |
126 | | - type: 'ephemeral', |
| 126 | + type: "ephemeral", |
127 | 127 | }, |
128 | 128 | } satisfies AnthropicProviderOptions, |
129 | | - } |
| 129 | + }, |
130 | 130 | }, |
131 | 131 | { |
132 | 132 | role: "system", |
133 | 133 | content: contextSystemPrompt(data.question), |
134 | 134 | providerOptions: { |
135 | 135 | anthropic: { |
136 | | - cacheControl: { type: 'ephemeral' }, |
| 136 | + cacheControl: { type: "ephemeral" }, |
137 | 137 | } satisfies AnthropicProviderOptions, |
138 | | - } |
| 138 | + }, |
139 | 139 | }, |
140 | 140 | ...convertToModelMessages(messages), |
141 | 141 | ], |
@@ -302,15 +302,16 @@ Step 5: 產生回應 (Generate Response) |
302 | 302 | export const contextSystemPrompt = (fragment: FragmentType<typeof QUESTION_INFO_FRAGMENT>) => { |
303 | 303 | const { title, description, difficulty, category } = readFragment(QUESTION_INFO_FRAGMENT, fragment); |
304 | 304 |
|
305 | | - const contextPrompt = `輸入資訊 (Input Information):這個問題是「{{QUESTION_TITLE}}」,難度 {{QUESTION_DIFFICULTY}},分類 {{QUESTION_CATEGORY}} |
| 305 | + const contextPrompt = |
| 306 | + `輸入資訊 (Input Information):這個問題是「{{QUESTION_TITLE}}」,難度 {{QUESTION_DIFFICULTY}},分類 {{QUESTION_CATEGORY}} |
306 | 307 |
|
307 | 308 | 題幹如下: |
308 | 309 |
|
309 | 310 | {{QUESTION_DESCRIPTION}} |
310 | 311 |
|
311 | 312 | 其他情境,您可以使用工具進行取回。`; |
312 | 313 |
|
313 | | - return contextPrompt.replace("{{QUESTION_TITLE}}", title) |
| 314 | + return contextPrompt.replace("{{QUESTION_TITLE}}", title) |
314 | 315 | .replace("{{QUESTION_DESCRIPTION}}", description) |
315 | 316 | .replace("{{QUESTION_DIFFICULTY}}", difficulty) |
316 | 317 | .replace("{{QUESTION_CATEGORY}}", category); |
|
0 commit comments