Skip to content

Commit 6c45d06

Browse files
chore: changed route for ai
1 parent 2f04708 commit 6c45d06

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

app/(chat)/(routes)/chat/[[...slug]]/_components/chat-main/chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const Chat = ({ conversations = [], initialData, isEmbed, isShared }: Cha
115115

116116
try {
117117
if (isImageGeneration) {
118-
const imageGeneration = await fetcher.post('api/openai/image', {
118+
const imageGeneration = await fetcher.post('api/ai/image', {
119119
responseType: 'json',
120120
body: {
121121
model: IMAGE_MODELS[0].value,
@@ -136,7 +136,7 @@ export const Chat = ({ conversations = [], initialData, isEmbed, isShared }: Cha
136136
abortControllerRef.current = new AbortController();
137137
const signal = abortControllerRef.current.signal;
138138

139-
const completionStream = await fetcher.post('/api/openai/completions', {
139+
const completionStream = await fetcher.post('/api/ai/completions', {
140140
body: {
141141
messages: [...messages, ...(options?.regenerate ? [] : messagesForApi)].map(
142142
({ content, role }) => ({

app/(dashboard)/(routes)/preview-course/[courseId]/_components/preview-description.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Price } from '@/components/common/price';
1212
import { TextBadge } from '@/components/common/text-badge';
1313
import { ChatCompletionRole, USER_TRANSLATE_PROMPT } from '@/constants/ai';
1414
import { TIMESTAMP_PREVIEW_TEMPLATE } from '@/constants/common';
15+
import { useCurrentUser } from '@/hooks/use-current-user';
1516

1617
type PreviewDescriptionProps = {
1718
author?: string | null;
@@ -46,6 +47,7 @@ export const PreviewDescription = ({
4647
}: PreviewDescriptionProps) => {
4748
const t = useTranslations('courses.preview.preview');
4849
const currentLocale = useLocale();
50+
const { user } = useCurrentUser();
4951

5052
const [translatedDescription, setTranslatedDescription] = useState('');
5153

@@ -56,7 +58,7 @@ export const PreviewDescription = ({
5658
<IconBadge size="sm" icon={BookOpen} />
5759
<span className="text-xs">{t('chapter', { amount: chaptersLength })}</span>
5860
</div>
59-
{language !== currentLocale && (
61+
{Boolean(user?.userId) && language !== currentLocale && (
6062
<div className="my-2">
6163
<GenerateTextResponseAi
6264
cacheKey={`course-description-[${id}]-[${currentLocale}]`}

app/api/openai/completions/route.ts renamed to app/api/ai/completions/route.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { NextRequest, NextResponse } from 'next/server';
44

55
import { getCurrentUser } from '@/actions/auth/get-current-user';
66
import { getAppConfig } from '@/actions/configs/get-app-config';
7-
import { SYSTEM_TRANSLATE_PROMPT } from '@/constants/ai';
87
import { isOwner } from '@/lib/owner';
98
import { AIProvider } from '@/server/ai-provider';
109

@@ -19,9 +18,7 @@ export const POST = async (req: NextRequest) => {
1918
try {
2019
const { messages, model, system } = await req.json();
2120

22-
const isTranslator = system?.content === SYSTEM_TRANSLATE_PROMPT;
23-
24-
if (!isTranslator && !user) {
21+
if (!user) {
2522
return new NextResponse(ReasonPhrases.UNAUTHORIZED, { status: StatusCodes.UNAUTHORIZED });
2623
}
2724

File renamed without changes.

components/ai/generate-text-response-ai.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const GenerateTextResponseAi = ({
6363
abortControllerRef.current = new AbortController();
6464
const signal = abortControllerRef.current.signal;
6565

66-
const completionStream = await fetcher.post('/api/openai/completions', {
66+
const completionStream = await fetcher.post('/api/ai/completions', {
6767
body: {
6868
messages,
6969
system: {

components/common/preview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useLocale } from 'next-intl';
77
import { useMemo, useState } from 'react';
88

99
import { ChatCompletionRole, USER_TRANSLATE_PROMPT } from '@/constants/ai';
10+
import { useCurrentUser } from '@/hooks/use-current-user';
1011

1112
import { GenerateTextResponseAi } from '../ai/generate-text-response-ai';
1213

@@ -21,12 +22,13 @@ export const Preview = ({ enableTranslate, id, language, value }: PreviewProps)
2122
const ReactQuill = useMemo(() => dynamic(() => import('react-quill'), { ssr: false }), []);
2223

2324
const currentLocale = useLocale();
25+
const { user } = useCurrentUser();
2426

2527
const [translatedDescription, setTranslatedDescription] = useState('');
2628

2729
return (
2830
<>
29-
{enableTranslate && language !== currentLocale && (
31+
{Boolean(user?.userId) && enableTranslate && language !== currentLocale && (
3032
<div className="p-4">
3133
<GenerateTextResponseAi
3234
cacheKey={`chapter-description-[${id}]-[${currentLocale}]`}

0 commit comments

Comments
 (0)