nuxt-chatgpt
Version:
ChatGPT integration for Nuxt 3
56 lines (55 loc) • 1.26 kB
JavaScript
import { createError } from "h3";
export const useChatgpt = () => {
const chat = async (message, model, options) => {
try {
return await $fetch("/api/chat", {
method: "POST",
body: {
message,
model,
options
}
});
} catch (error) {
throw createError({
statusCode: 500,
message: "Failed to forward request to server"
});
}
};
const chatCompletion = async (messages, model, options) => {
try {
return await $fetch("/api/chat-completion", {
method: "POST",
body: {
messages,
model,
options
}
});
} catch (error) {
throw createError({
statusCode: 500,
message: "Failed to forward request to server"
});
}
};
const generateImage = async (message, model, options) => {
try {
return await $fetch("/api/image-generate", {
method: "POST",
body: {
message,
model,
options
}
});
} catch (error) {
throw createError({
statusCode: 500,
message: "Failed to forward request to server"
});
}
};
return { chat, chatCompletion, generateImage };
};