mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
take model for /ai/chat
This commit is contained in:
@@ -10,7 +10,7 @@ export default async function aiChat(req: AuthedRequest) {
|
|||||||
const parsed = parseQueryParams(url, ChatRequestSchema);
|
const parsed = parseQueryParams(url, ChatRequestSchema);
|
||||||
if ("error" in parsed) return parsed.error;
|
if ("error" in parsed) return parsed.error;
|
||||||
|
|
||||||
const { orgId, projectId, message } = parsed.data;
|
const { orgId, projectId, message, model } = parsed.data;
|
||||||
|
|
||||||
const user = await getUserById(req.userId);
|
const user = await getUserById(req.userId);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -20,7 +20,7 @@ export default async function aiChat(req: AuthedRequest) {
|
|||||||
const context = await buildContext(orgId, projectId, user);
|
const context = await buildContext(orgId, projectId, user);
|
||||||
|
|
||||||
const fullPrompt = `${SYSTEM_PROMPT}\n\n${context}\n\n<user_query>${message}</user_query>`;
|
const fullPrompt = `${SYSTEM_PROMPT}\n\n${context}\n\n<user_query>${message}</user_query>`;
|
||||||
const response = await callAI(fullPrompt);
|
const response = await callAI(fullPrompt, model);
|
||||||
|
|
||||||
return Response.json(response);
|
return Response.json(response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { ChatRequest, ChatResponse, ModelsResponse } from "@sprint/shared";
|
|||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { apiClient } from "@/lib/server";
|
import { apiClient } from "@/lib/server";
|
||||||
|
|
||||||
export function useChatMutation() {
|
export function useChat() {
|
||||||
return useMutation<ChatResponse, Error, ChatRequest>({
|
return useMutation<ChatResponse, Error, ChatRequest>({
|
||||||
mutationKey: ["ai", "chat"],
|
mutationKey: ["ai", "chat"],
|
||||||
mutationFn: async (input) => {
|
mutationFn: async (input) => {
|
||||||
|
|||||||
@@ -671,6 +671,7 @@ export const ChatRequestSchema = z.object({
|
|||||||
orgId: z.coerce.number().int().positive("orgId must be a positive integer"),
|
orgId: z.coerce.number().int().positive("orgId must be a positive integer"),
|
||||||
projectId: z.coerce.number().int().positive("projectId must be a positive integer"),
|
projectId: z.coerce.number().int().positive("projectId must be a positive integer"),
|
||||||
message: z.string().min(1, "Message is required"),
|
message: z.string().min(1, "Message is required"),
|
||||||
|
model: z.string().min(1, "Model is required"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ChatRequest = z.infer<typeof ChatRequestSchema>;
|
export type ChatRequest = z.infer<typeof ChatRequestSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user