Feat: add Enjoy AI as option (#206)

* add enjoyAI as option

* use enjoyai config

* may call enjoyai

* may set default ai engine

* refactor setting context

* refactor preferences

* add warning when openai key not provided

* tweak locale

* update duration for audio/video

* add balance settings

* may select ai role when create conversation

* may forward message from conversation

* tweak ui

* refactor transcribe method

* refactor ai commands to hooks

* fix webapi

* tweak playback rate options

* add playMode, next & prev, ref: #124

* upgrade deps

* may skip whisper model download

* audios/videos default order by updated_At
This commit is contained in:
an-lee
2024-01-31 00:04:59 +08:00
committed by GitHub
parent 58dcd1523e
commit 00cbc8403b
56 changed files with 1590 additions and 858 deletions

View File

@@ -30,6 +30,7 @@ import path from "path";
import Ffmpeg from "@main/ffmpeg";
import whisper from "@main/whisper";
import { hashFile } from "@/utils";
import { WEB_API_URL } from "@/constants";
const logger = log.scope("db/models/conversation");
@Table({
@@ -136,7 +137,22 @@ export class Conversation extends Model<Conversation> {
// choose llm based on engine
llm() {
if (this.engine == "openai") {
if (this.engine === "enjoyai") {
return new ChatOpenAI({
modelName: this.model,
configuration: {
baseURL: `${process.env.WEB_API_URL || WEB_API_URL}/api/ai`,
defaultHeaders: {
Authorization: `Bearer ${settings.getSync("user.accessToken")}`,
},
},
temperature: this.configuration.temperature,
n: this.configuration.numberOfChoices,
maxTokens: this.configuration.maxTokens,
frequencyPenalty: this.configuration.frequencyPenalty,
presencePenalty: this.configuration.presencePenalty,
});
} else if (this.engine === "openai") {
const key = settings.getSync("openai.key") as string;
if (!key) {
throw new Error(t("openaiKeyRequired"));