feat: add OpenCode Go provider and support for custom models
- Introduced OpenCode Go provider with relevant configurations. - Enhanced model management by allowing users to add and delete custom models. - Updated UI components to support model selection for image types. - Adjusted sidebar visibility to include image media kinds.
This commit is contained in:
48
src/app/api/models/custom/route.js
Normal file
48
src/app/api/models/custom/route.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getCustomModels, addCustomModel, deleteCustomModel } from "@/models";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// GET /api/models/custom - List all custom models
|
||||
export async function GET() {
|
||||
try {
|
||||
const models = await getCustomModels();
|
||||
return NextResponse.json({ models });
|
||||
} catch (error) {
|
||||
console.log("Error fetching custom models:", error);
|
||||
return NextResponse.json({ error: "Failed to fetch custom models" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/models/custom - Add custom model
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const { providerAlias, id, type, name } = await request.json();
|
||||
if (!providerAlias || !id) {
|
||||
return NextResponse.json({ error: "providerAlias and id required" }, { status: 400 });
|
||||
}
|
||||
const added = await addCustomModel({ providerAlias, id, type: type || "llm", name });
|
||||
return NextResponse.json({ success: true, added });
|
||||
} catch (error) {
|
||||
console.log("Error adding custom model:", error);
|
||||
return NextResponse.json({ error: "Failed to add custom model" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/models/custom?providerAlias=xxx&id=yyy&type=zzz
|
||||
export async function DELETE(request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const providerAlias = searchParams.get("providerAlias");
|
||||
const id = searchParams.get("id");
|
||||
const type = searchParams.get("type") || "llm";
|
||||
if (!providerAlias || !id) {
|
||||
return NextResponse.json({ error: "providerAlias and id required" }, { status: 400 });
|
||||
}
|
||||
await deleteCustomModel({ providerAlias, id, type });
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.log("Error deleting custom model:", error);
|
||||
return NextResponse.json({ error: "Failed to delete custom model" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
16
src/app/api/v1/images/generations/route.js
Normal file
16
src/app/api/v1/images/generations/route.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { handleImageGeneration } from "@/sse/handlers/imageGeneration.js";
|
||||
|
||||
export async function OPTIONS() {
|
||||
return new Response(null, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "*",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** POST /v1/images/generations - OpenAI-compatible image generation endpoint */
|
||||
export async function POST(request) {
|
||||
return await handleImageGeneration(request);
|
||||
}
|
||||
Reference in New Issue
Block a user