-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a79b4e
commit 0752d01
Showing
1 changed file
with
11 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,16 @@ | ||
const { | ||
GoogleGenerativeAI, | ||
HarmCategory, | ||
HarmBlockThreshold, | ||
} = require("@google/generative-ai"); | ||
|
||
const MODEL_NAME = "gemini-pro"; | ||
const API_KEY = process.env.GEMINI_API_KEY; | ||
import { GoogleGenerativeAI } from "@google/generative-ai"; | ||
|
||
export async function model(old: Object, input: string) { | ||
const genAI = new GoogleGenerativeAI(API_KEY); | ||
const model = genAI.getGenerativeModel({ model: MODEL_NAME }); | ||
|
||
const generationConfig = { | ||
temperature: 0.9, | ||
topK: 1, | ||
topP: 0.9, | ||
maxOutputTokens: 5000, | ||
}; | ||
|
||
const safetySettings = [ | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_HARASSMENT, | ||
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, | ||
}, | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, | ||
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, | ||
}, | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, | ||
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, | ||
}, | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, | ||
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, | ||
}, | ||
]; | ||
|
||
const parts = [ | ||
{ | ||
text: `understand and generate a parsable json file in the format given (do not include submit button) from the given description:\nformat:\nexport type FormData = {\n title: string\n action: 'create' | 'update' | 'delete' // understand what user wanted to do\n fields: FormField[]\n}\n\nexport type FormField = {\n id?: string\n field: string // html element\n type: string // type of form element\n name: string\n label: string\n value?: string\n placeholder?: string\n disabled?: boolean\n required?: boolean\n options?: {\n value: string\n label: string\n name?: string\n }[]\n}\n\ndescription: "${input}" \n comeup with title, description and atleast one field \n\nold: "${JSON.stringify( | ||
old, | ||
)}"`, | ||
}, | ||
]; | ||
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY ?? ""); | ||
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); | ||
const prompt = `understand and generate a parsable json file in the format given (do not include submit button) from the given description:\nformat:\nexport type FormData = {\n title: string\n action: 'create' | 'update' | 'delete' // understand what user wanted to do\n fields: FormField[]\n}\n\nexport type FormField = {\n id?: string\n field: string // html element\n type: string // type of form element\n name: string\n label: string\n value?: string\n placeholder?: string\n disabled?: boolean\n required?: boolean\n options?: {\n value: string\n label: string\n name?: string\n }[]\n}\n\ndescription: "${input}" \n comeup with title, description and atleast one field \n\nold: "${JSON.stringify( | ||
old | ||
)}"`; | ||
|
||
const result = await model.generateContent({ | ||
contents: [{ role: "user", parts }], | ||
generationConfig, | ||
safetySettings, | ||
}); | ||
const result = await model.generateContent(prompt); | ||
const response = await result.response; | ||
const responseText = response.text(); | ||
console.log({ responseText }); | ||
|
||
const response = result.response; | ||
return response.text(); | ||
return responseText; | ||
} |