mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-06-06 19:35:44 +02:00
api: use default project profile if not specified
This commit is contained in:
parent
8840da2261
commit
ee5b6d477d
1 changed files with 19 additions and 11 deletions
|
|
@ -18,9 +18,9 @@ export async function POST(
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const { projectId } = await params;
|
const { projectId } = await params;
|
||||||
const requestId = crypto.randomUUID();
|
const requestId = crypto.randomUUID();
|
||||||
const logger = new PrefixLogger(`[${requestId}]`);
|
const logger = new PrefixLogger(`${requestId}`);
|
||||||
|
|
||||||
logger.log(`Processing chat request for project ${projectId}`);
|
logger.log(`Got chat request for project ${projectId}`);
|
||||||
|
|
||||||
// check query limit
|
// check query limit
|
||||||
if (!await check_query_limit(projectId)) {
|
if (!await check_query_limit(projectId)) {
|
||||||
|
|
@ -37,6 +37,7 @@ export async function POST(
|
||||||
logger.log(`Invalid JSON in request body: ${e}`);
|
logger.log(`Invalid JSON in request body: ${e}`);
|
||||||
return Response.json({ error: "Invalid JSON in request body" }, { status: 400 });
|
return Response.json({ error: "Invalid JSON in request body" }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
logger.log(`Request json: ${JSON.stringify(body, null, 2)}`);
|
||||||
const result = ApiRequest.safeParse(body);
|
const result = ApiRequest.safeParse(body);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
logger.log(`Invalid request body: ${result.error.message}`);
|
logger.log(`Invalid request body: ${result.error.message}`);
|
||||||
|
|
@ -71,15 +72,7 @@ export async function POST(
|
||||||
}
|
}
|
||||||
|
|
||||||
// if test profile is provided in the request, use it
|
// if test profile is provided in the request, use it
|
||||||
let profile: z.infer<typeof TestProfile> = {
|
let profile: z.infer<typeof TestProfile> | null = null;
|
||||||
projectId: projectId,
|
|
||||||
name: 'Default',
|
|
||||||
createdAt: new Date().toISOString(),
|
|
||||||
lastUpdatedAt: new Date().toISOString(),
|
|
||||||
context: '',
|
|
||||||
mockTools: false,
|
|
||||||
mockPrompt: '',
|
|
||||||
};
|
|
||||||
if (result.data.testProfileId) {
|
if (result.data.testProfileId) {
|
||||||
const testProfile = await testProfilesCollection.findOne({
|
const testProfile = await testProfilesCollection.findOne({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
|
@ -90,6 +83,21 @@ export async function POST(
|
||||||
return Response.json({ error: "Test profile not found" }, { status: 404 });
|
return Response.json({ error: "Test profile not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
profile = testProfile;
|
profile = testProfile;
|
||||||
|
} else {
|
||||||
|
// if no test profile is provided, use the default profile
|
||||||
|
const defaultProfile = await testProfilesCollection.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
_id: new ObjectId(project.defaultTestProfileId),
|
||||||
|
});
|
||||||
|
if (!defaultProfile) {
|
||||||
|
logger.log(`Default test profile not found for project ${projectId}`);
|
||||||
|
return Response.json({ error: "Default test profile not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
profile = defaultProfile;
|
||||||
|
}
|
||||||
|
if (!profile) {
|
||||||
|
logger.log(`No test profile found for project ${projectId}`);
|
||||||
|
return Response.json({ error: "No test profile found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// if profile has a context available, overwrite the system message in the request (if there is one)
|
// if profile has a context available, overwrite the system message in the request (if there is one)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue