nuxt-chatgpt 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.6"
7
+ "version": "0.1.7"
8
8
  }
package/dist/module.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { fileURLToPath } from 'url';
2
2
  import { defineNuxtModule, createResolver, addImportsDir, addServerHandler } from '@nuxt/kit';
3
+ import { defu } from 'defu';
3
4
 
4
5
  const configKey = "chatgpt";
5
6
  const moduleName = "nuxt-chatgpt";
@@ -26,9 +27,9 @@ const module = defineNuxtModule({
26
27
  if (!options.isEnabled) {
27
28
  return console.warn(`[${moduleName}] module is disabled and will not be loaded.`);
28
29
  }
29
- nuxt.options.runtimeConfig.public[configKey] = {
30
+ nuxt.options.runtimeConfig[configKey] = defu(nuxt.options.runtimeConfig[configKey], {
30
31
  apiKey: options.apiKey
31
- };
32
+ });
32
33
  addImportsDir(resolve("./runtime/composables"));
33
34
  addServerHandler({
34
35
  route: "/api/openai",
@@ -1,12 +1,10 @@
1
1
  import { createError } from "h3";
2
- import { getBody, getHeaders } from "../utils/index.mjs";
3
2
  export const useChatgpt = () => {
4
3
  const send = async (message) => {
5
4
  try {
6
5
  return await $fetch("/api/openai", {
7
6
  method: "POST",
8
- headers: getHeaders(),
9
- body: getBody(message)
7
+ body: message
10
8
  });
11
9
  } catch (error) {
12
10
  throw createError({
@@ -4,7 +4,7 @@ import { useRuntimeConfig } from "#imports";
4
4
  export default defineEventHandler(async (event) => {
5
5
  const { prompt } = await readBody(event);
6
6
  const configuration = new Configuration({
7
- apiKey: useRuntimeConfig().public.chatgpt.apiKey
7
+ apiKey: useRuntimeConfig().chatgpt.apiKey
8
8
  });
9
9
  const openai = new OpenAIApi(configuration);
10
10
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-chatgpt",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "ChatGPT integration for Nuxt 3",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -54,7 +54,8 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@nuxt/kit": "^3.1.1",
57
- "openai": "^3.2.1"
57
+ "openai": "^3.2.1",
58
+ "defu": "^6.1.2"
58
59
  },
59
60
  "devDependencies": {
60
61
  "@nuxt/eslint-config": "^0.1.1",
@@ -1,3 +0,0 @@
1
- import type { IHeaders, IMessage } from "../types";
2
- export declare const getBody: (message: IMessage) => string;
3
- export declare const getHeaders: () => IHeaders;
@@ -1,8 +0,0 @@
1
- export const getBody = (message) => {
2
- return JSON.stringify({ prompt: message });
3
- };
4
- export const getHeaders = () => {
5
- return {
6
- "Content-Type": "application/json"
7
- };
8
- };