diff options
author | polwex <polwex@sortug.com> | 2025-08-17 02:20:42 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-08-17 02:20:42 +0700 |
commit | 9be51e192fca8901d47328875d9e0c690d4b2b99 (patch) | |
tree | 926151e075c539019c5eb65e2140678acb383c5f /src/lib | |
parent | c505750ab36f8164256a91830fc83a807a9d6984 (diff) |
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/services/aitranslation.ts | 14 | ||||
-rw-r--r-- | src/lib/services/llm.ts | 16 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/lib/services/aitranslation.ts b/src/lib/services/aitranslation.ts index 331e10e..fb88323 100644 --- a/src/lib/services/aitranslation.ts +++ b/src/lib/services/aitranslation.ts @@ -1,12 +1,12 @@ import { z } from "zod"; import type { Language, TranslationService } from "../types"; -import AIModelAPI, { type AIModelChoice } from "sortug-ai"; +import AIModelAPI, { type LLMChoice } from "sortug-ai"; import type { AsyncRes } from "@/lib/types"; export class AiTranslator implements TranslationService { endpoint = ""; // doesn't apply here api; - constructor(model: AIModelChoice) { + constructor(model: LLMChoice) { const api = AIModelAPI(model); this.api = api; } @@ -24,12 +24,11 @@ export class AiTranslator implements TranslationService { }, ]; const res = await this.api.send( - `You are a professional, state of the art excellent translation service. Please translate the text given by the user. The prompts will be sent as JSON, in the format "{'text': string, 'sourceLang': string, 'targetLang': string}". You are to translate the 'text' from 'fromLang' to 'targetLang'. Output the desired translation and nothing else. Pause to think the translations as much as you need.`, input, + `You are a professional, state of the art excellent translation service. Please translate the text given by the user. The prompts will be sent as JSON, in the format "{'text': string, 'sourceLang': string, 'targetLang': string}". You are to translate the 'text' from 'fromLang' to 'targetLang'. Output the desired translation and nothing else. Pause to think the translations as much as you need.`, ); console.log({ res }); - if ("error" in res) return res; - else return { ok: res.ok.join(", ") }; + return res; } async getSupportedLanguages() { @@ -49,10 +48,9 @@ export class AiTranslator implements TranslationService { }, ]; const res = await this.api.send( - `You are a professional, state of the art excellent translation service. Please transliterate, the text given by the user. The prompts will be sent as JSON, in the format "{'text': string, 'language': string, 'fromScript': string, 'toScript': string}". You are to transliterate the 'text' belongng to language 'language' from 'fromScript' to 'toScript' to the best of your ability. Output the desired transiteration and nothing else. Pause to think the output as much as you need.`, input, + `You are a professional, state of the art excellent translation service. Please transliterate, the text given by the user. The prompts will be sent as JSON, in the format "{'text': string, 'language': string, 'fromScript': string, 'toScript': string}". You are to transliterate the 'text' belongng to language 'language' from 'fromScript' to 'toScript' to the best of your ability. Output the desired transiteration and nothing else. Pause to think the output as much as you need.`, ); - if ("error" in res) return res; - else return { ok: res.ok.join(", ") }; + return res; } } diff --git a/src/lib/services/llm.ts b/src/lib/services/llm.ts new file mode 100644 index 0000000..508423f --- /dev/null +++ b/src/lib/services/llm.ts @@ -0,0 +1,16 @@ +import AIModelAPI, { type LLMChoice } from "sortug-ai"; +import type { AsyncRes } from "@/lib/types"; + +export class LLM { + private api; + constructor(model: LLMChoice) { + const api = AIModelAPI(model); + this.api = api; + } + + async chat(text: string): AsyncRes<string> { + const res = await this.api.send(text); + console.log({ res }); + return res; + } +} |