feat: 添加 大模型平台 sdk api 调用接口
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { client, getInfo } from '@/utils/common'
|
||||
import { client, getInfo } from '@/app/api/utils/common'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json()
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { client, getInfo } from '@/app/api/utils/common'
|
||||
|
||||
export async function POST(request: NextRequest, { params }: {
|
||||
params: { conversationId: string }
|
||||
}) {
|
||||
const body = await request.json()
|
||||
const {
|
||||
auto_generate,
|
||||
name,
|
||||
} = body
|
||||
const { conversationId } = params
|
||||
const { user } = getInfo(request)
|
||||
|
||||
// auto generate name
|
||||
const { data } = await client.renameConversation(conversationId, name, user, auto_generate)
|
||||
return NextResponse.json(data)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { client, getInfo, setSession } from '@/app/api/utils/common'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { sessionId, user } = getInfo(request)
|
||||
try {
|
||||
const { data }: any = await client.getConversations(user)
|
||||
return NextResponse.json(data, {
|
||||
headers: setSession(sessionId),
|
||||
})
|
||||
}
|
||||
catch (error: any) {
|
||||
return NextResponse.json({
|
||||
data: [],
|
||||
error: error.message,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { client, getInfo } from '@/app/api/utils/common'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const formData = await request.formData()
|
||||
const { user } = getInfo(request)
|
||||
formData.append('user', user)
|
||||
const res = await client.fileUpload(formData)
|
||||
return new Response(res.data.id as any)
|
||||
}
|
||||
catch (e: any) {
|
||||
return new Response(e.message)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { client, getInfo } from '@/app/api/utils/common'
|
||||
|
||||
export async function POST(request: NextRequest, { params }: {
|
||||
params: { messageId: string }
|
||||
}) {
|
||||
const body = await request.json()
|
||||
const {
|
||||
rating,
|
||||
} = body
|
||||
const { messageId } = params
|
||||
const { user } = getInfo(request)
|
||||
const { data } = await client.messageFeedback(messageId, rating, user)
|
||||
return NextResponse.json(data)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { type NextRequest } from 'next/server'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { client, getInfo, setSession } from '@/app/api/utils/common'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { sessionId, user } = getInfo(request)
|
||||
const { searchParams } = new URL(request.url)
|
||||
const conversationId = searchParams.get('conversation_id')
|
||||
const { data }: any = await client.getConversationMessages(user, conversationId as string)
|
||||
return NextResponse.json(data, {
|
||||
headers: setSession(sessionId),
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { client } from '@/utils/common';
|
||||
import { client } from '@/app/api/utils/common';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
// 模拟获取请求信息的函数
|
||||
function getInfo(request: NextRequest) {
|
||||
|
||||
Reference in New Issue
Block a user