sam prompt 모듈 개발
This commit is contained in:
50
prt/ref/services/geminiService.ts
Normal file
50
prt/ref/services/geminiService.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
|
||||
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
|
||||
|
||||
export const optimizePrompt = async (originalPrompt: string, field: string): Promise<string> => {
|
||||
try {
|
||||
const response = await ai.models.generateContent({
|
||||
model: 'gemini-3-flash-preview',
|
||||
contents: `You are an expert Prompt Engineer specializing in the ${field} field.
|
||||
Refine the following AI prompt to be more effective, professional, and clear.
|
||||
Maintain the original intent but improve structure, context, and constraints.
|
||||
Please provide the optimized prompt in the same language as the original.
|
||||
|
||||
Original Prompt:
|
||||
"${originalPrompt}"
|
||||
|
||||
Optimized Prompt (Provide only the text of the prompt):`,
|
||||
config: {
|
||||
temperature: 0.7,
|
||||
topP: 0.95,
|
||||
}
|
||||
});
|
||||
|
||||
return response.text || originalPrompt;
|
||||
} catch (error) {
|
||||
console.error("Gemini optimization failed:", error);
|
||||
return originalPrompt;
|
||||
}
|
||||
};
|
||||
|
||||
export const generatePromptTitle = async (content: string): Promise<string> => {
|
||||
try {
|
||||
const response = await ai.models.generateContent({
|
||||
model: 'gemini-3-flash-preview',
|
||||
contents: `다음 AI 프롬프트를 요약하여 3-5단어 내외의 짧고 명확한 한국어 제목으로 만들어주세요:
|
||||
|
||||
"${content}"
|
||||
|
||||
제목:`,
|
||||
config: {
|
||||
maxOutputTokens: 20
|
||||
}
|
||||
});
|
||||
|
||||
return response.text?.trim() || "새 프롬프트";
|
||||
} catch (error) {
|
||||
return "새 프롬프트";
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user