mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-26 03:30:26 -04:00
feat: In-app AI Provider Configuration (#7650)
This commit is contained in:
55
frontend/app/composables/use-ai-providers.ts
Normal file
55
frontend/app/composables/use-ai-providers.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import type { AIProviderCreate, AIProviderUpdate } from "~/lib/api/types/group";
|
||||
|
||||
export function useAIProviders() {
|
||||
const api = useUserApi();
|
||||
const loading = ref(false);
|
||||
|
||||
async function getOne(id: string) {
|
||||
loading.value = true;
|
||||
try {
|
||||
return await api.aiProviders.getOne(id);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createOne(payload: AIProviderCreate) {
|
||||
loading.value = true;
|
||||
try {
|
||||
return await api.aiProviders.createOne(payload);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateOne(id: string, payload: AIProviderUpdate) {
|
||||
loading.value = true;
|
||||
try {
|
||||
return await api.aiProviders.updateOne(id, payload);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteOne(id: string) {
|
||||
loading.value = true;
|
||||
try {
|
||||
return await api.aiProviders.deleteOne(id);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loading: readonly(loading),
|
||||
getOne,
|
||||
createOne,
|
||||
updateOne,
|
||||
deleteOne,
|
||||
};
|
||||
}
|
||||
@@ -22,7 +22,10 @@ const allAnnouncements: Announcement[] = Object.entries(_announcementsUnsorted)
|
||||
.map(([path, mod]) => {
|
||||
const key = path.split("/").at(-1)!.replace(".vue", "");
|
||||
|
||||
const parsed = new Date(key.split("_", 1)[0]!);
|
||||
const dateParts = key.split("_", 1)[0]!.split("-").map(Number);
|
||||
const parsed = dateParts.length === 3
|
||||
? new Date(dateParts[0]!, dateParts[1]! - 1, dateParts[2]!)
|
||||
: new Date(NaN);
|
||||
const date = isNaN(parsed.getTime()) ? undefined : parsed;
|
||||
|
||||
return {
|
||||
|
||||
@@ -42,6 +42,25 @@ export const useGroupSelf = function () {
|
||||
|
||||
return data || undefined;
|
||||
},
|
||||
async updateAIProviderSettings() {
|
||||
if (!groupSelfRef.value) {
|
||||
await refreshGroupSelf();
|
||||
}
|
||||
if (!groupSelfRef.value?.aiProviderSettings) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = await api.groups.setAIProviderSettings(groupSelfRef.value.aiProviderSettings);
|
||||
|
||||
if (data) {
|
||||
groupSelfRef.value.aiProviderSettings = data;
|
||||
}
|
||||
|
||||
return data || undefined;
|
||||
},
|
||||
async refresh() {
|
||||
await refreshGroupSelf();
|
||||
},
|
||||
};
|
||||
|
||||
const group = actions.get();
|
||||
|
||||
Reference in New Issue
Block a user