forked from calcom/cal.com
-
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.
feat: AI description - DB model + frontend + backend (fetch only) (ca…
…lcom#17651) * feat: AI description - DB model + frontend + backend (fetch only) * fix types and add validation to backend * improve log * improve * import type * fix replexica error * fix * fix test * update replexica type * Renamed descriptionTranslations to fieldTranslations * Moved the eventTypeId column to 2nd --------- Co-authored-by: Keith Williams <[email protected]>
- Loading branch information
1 parent
f9afca2
commit 5401bcc
Showing
20 changed files
with
621 additions
and
9 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
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
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
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ReplexicaEngine } from "@replexica/sdk"; | ||
|
||
import { REPLEXICA_API_KEY } from "@calcom/lib/constants"; | ||
|
||
export class ReplexicaService { | ||
private static engine = new ReplexicaEngine({ | ||
apiKey: REPLEXICA_API_KEY, | ||
}); | ||
|
||
/** | ||
* Localizes text from one language to another | ||
* @param text The text to localize | ||
* @param sourceLocale The source language locale | ||
* @param targetLocale The target language locale | ||
* @returns The localized text | ||
*/ | ||
static async localizeText(text: string, sourceLocale: string, targetLocale: string): Promise<string> { | ||
if (!text?.trim()) { | ||
return text; | ||
} | ||
|
||
try { | ||
const result = await this.engine.localizeText(text, { | ||
sourceLocale, | ||
targetLocale, | ||
}); | ||
|
||
return result; | ||
} catch (error) { | ||
return text; | ||
} | ||
} | ||
|
||
/** | ||
* Localizes an array of texts from one language to another | ||
* @param texts Array of texts to localize | ||
* @param sourceLocale The source language locale | ||
* @param targetLocale The target language locale | ||
* @returns The localized texts array | ||
*/ | ||
static async localizeTexts(texts: string[], sourceLocale: string, targetLocale: string): Promise<string[]> { | ||
if (!texts.length) { | ||
return texts; | ||
} | ||
|
||
try { | ||
const result = await this.engine.localizeChat( | ||
texts.map((text) => ({ name: "NO_NAME", text: text.trim() })), | ||
{ | ||
sourceLocale, | ||
targetLocale, | ||
} | ||
); | ||
|
||
return result.map((chat: { name: string; text: string }) => chat.text); | ||
} catch (error) { | ||
return texts; | ||
} | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
packages/prisma/migrations/20241114210330_add_event_type_translation_model/migration.sql
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- CreateEnum | ||
CREATE TYPE "EventTypeAutoTranslatedField" AS ENUM ('DESCRIPTION'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "EventType" ADD COLUMN "autoTranslateDescriptionEnabled" BOOLEAN NOT NULL DEFAULT false; | ||
|
||
-- CreateTable | ||
CREATE TABLE "EventTypeTranslation" ( | ||
"id" TEXT NOT NULL, | ||
"eventTypeId" INTEGER NOT NULL, | ||
"field" "EventTypeAutoTranslatedField" NOT NULL, | ||
"sourceLang" TEXT NOT NULL, | ||
"targetLang" TEXT NOT NULL, | ||
"translatedText" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"createdBy" INTEGER NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"updatedBy" INTEGER, | ||
|
||
CONSTRAINT "EventTypeTranslation_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "EventTypeTranslation_eventTypeId_field_targetLang_idx" ON "EventTypeTranslation"("eventTypeId", "field", "targetLang"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "EventTypeTranslation_eventTypeId_field_targetLang_key" ON "EventTypeTranslation"("eventTypeId", "field", "targetLang"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "EventTypeTranslation" ADD CONSTRAINT "EventTypeTranslation_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
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
Oops, something went wrong.