You said: // app/api/your-route/route.ts import { NextRequest, NextResponse } from…
- User
You said: // app/api/your-route/route.ts
import { NextRequest, NextResponse } from 'next/server'; import axios from 'axios';
export async function POST(req: NextRequest) { try { const url = new URL(req.url); const text = url.searchParams.get('text'); const selectedOption = url.searchParams.get('selectedOption');
if (!text || !selectedOption) { return NextResponse.json({ error: 'Text and selectedOption are required' }, { status: 400 }); } let apiUrl = ''; if (selectedOption === 'notebook') { apiUrl = https://editorchoice-api.vercel.app/write?text=${encodeURIComponent(text)}; } else if (selectedOption === 'carbon') { apiUrl = https://editorchoice-api.vercel.app/carbon?code=${encodeURIComponent(text)}; } else { return NextResponse.json({ error: 'Invalid selectedOption' }, { status: 400 }); } const response = await axios.get(apiUrl, { responseType: 'arraybuffer', }); return new NextResponse(response.data, { status: 200, headers: { 'Content-Type': 'image/jpeg', // Set content type based on image type }, });} catch (error) { console.error('Error generating image:', error); return NextResponse.json({ error: 'Error generating image' }, { status: 500 }); } }
const options = { method: 'POST', url: 'https://api.kellyai.pro/write/notes', headers: {'Content-Type': 'application/json', Authorization: 'YOUR_TOKEN'}, data: {code: 'Hello World', responseType: 'binarydata'} };
const options = { method: 'POST', url: 'https://api.kellyai.pro/write/code', headers: {'Content-Type': 'application/json', Authorization: 'YOUR_TOKEN'}, data: {code: 'Hello World', responseType: 'binarydata'} };
use this as editor choice write api and for carbon api use write code
- Assistant
Certainly! Here's your revised route file where I have updated the API endpoints as per your provided information and corrected the syntax issues:
// app/api/your-route/route.ts import { NextRequest, NextResponse } from 'next/server'; import axios from 'axios'; export async function POST(req: NextRequest) { try { const { text, selectedOption } = await req.json(); // Updated to read JSON payload if (!text || !selectedOption) { return NextResponse.json({ error: 'Text and selectedOption are required' }, { status: 400 }); } let apiUrl = ''; let data = {}; if (selectedOption === 'notebook') { apiUrl = 'https://api.kellyai.pro/write/notes'; data = { code: text, responseType: 'binarydata' }; } else if (selectedOption === 'carbon') { apiUrl = 'https://api.kellyai.pro/write/code'; data = { code: text, responseType: 'binarydata' }; } else { return NextResponse.json({ error: 'Invalid selectedOption' }, { status: 400 }); } const response = await axios.post(apiUrl, data, { headers: { 'Content-Type': 'application/json', 'Authorization': 'YOUR_TOKEN' }, responseType: 'arraybuffer', }); return new NextResponse(response.data, { status: 200, headers: { 'Content-Type': 'image/jpeg', // Adjust if necessary based on actual content type }, }); } catch (error) { console.error('Error generating image:', error); return NextResponse.json({ error: 'Error generating image' }, { status: 500 }); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.