...
This commit is contained in:
32
src/utils.ts
32
src/utils.ts
@@ -1,6 +1,3 @@
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
import { env } from "process";
|
||||
|
||||
export function inspect(word: string) {
|
||||
const goto = (url: string) => {
|
||||
window.open(url, '_blank');
|
||||
@@ -14,32 +11,3 @@ export function inspect(word: string) {
|
||||
export function urlGoto(url: string) {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
const api_key = env.GEMINI_API_KEY;
|
||||
const ai = new GoogleGenAI(api_key ? { apiKey: api_key } : {});
|
||||
const prompt = `[TEXT]
|
||||
请推断以上文本的语言,并返回其宽式国际音标(IPA),以JSON格式
|
||||
如:
|
||||
{
|
||||
"lang": "german",
|
||||
"ipa": "[ˈɡuːtn̩ ˈtaːk]"
|
||||
}
|
||||
注意:直接返回json文本,
|
||||
不要带markdown记号,
|
||||
ipa一定要加[],
|
||||
lang的值是小写英语的语言名称`;
|
||||
export async function getIPA(text: string) {
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash",
|
||||
contents: prompt.replace("[TEXT]", text),
|
||||
});
|
||||
if (response.text === undefined) return null;
|
||||
return JSON.parse(response.text);
|
||||
}
|
||||
|
||||
export async function ggetIPA(text: string): Promise<{ lang: string, ipa: string } | null> {
|
||||
return {
|
||||
lang: `(这是的${text}的lang)`,
|
||||
ipa: `(这是的${text}的ipa)`
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user