MCPcopy Index your code
hub / github.com/SchnapsterDog/nuxt-chatgpt

github.com/SchnapsterDog/nuxt-chatgpt @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
16 symbols 40 edges 15 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Hausly + Image Generator🔥(Hausly)🔥

ReplyGuard + Generate Email Reply🔥(ReplyGuard)🔥

Nuxt Chatgpt + Image Generator🔥(Nuxt ChatGPT)🔥

Logo

ChatGPT integration for Nuxt 3.

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![License][license-src]][license-href]

About the project

Nuxt ChatGPT is a project built to showcase the capabilities of the Nuxt3 ChatGPT module. It functions as a ChatGPT clone with enhanced features, including the ability to organize and sort created documents into folders, offering an improved user experience for managing conversations and outputs.

About the module

This user-friendly module boasts of an easy integration process that enables seamless implementation into any Nuxt 3 project. With type-safe integration, you can integrate ChatGPT into your Nuxt 3 project without breaking a sweat. Enjoy easy access to the chat, and chatCompletion methods through the useChatgpt() composable. Additionally, the module guarantees security as requests are routed through a Nitro Server, thus preventing the exposure of your API Key. The module use openai library version 4.0.0 behind the scene.

Features

  • 💪   Easy implementation into any Nuxt 3 project.
  • 👉   Type-safe integration of Chatgpt into your Nuxt 3 project.
  • 🕹️   Provides a useChatgpt() composable that grants easy access to the chat, and chatCompletion, and generateImage methods.
  • 🕹️   Provides chatCompletionStream for real-time streamed responses (SSE).
  • 🔥   Ensures security by routing requests through a Nitro Server, preventing the API Key from being exposed.
  • 🧱   It is lightweight and performs well.

Recommended Node Version

min v18.20.5 or higher

recommended v20.19.0

Getting Started

  1. Add nuxt-chatgpt dependency to your project sh npx nuxt module add nuxt-chatgpt
  2. Add nuxt-chatgpt to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: ["nuxt-chatgpt"],

  // entirely optional
  chatgpt: {
    apiKey: 'Your apiKey here goes here'
  },
})

That's it! You can now use Nuxt Chatgpt in your Nuxt app 🔥

Usage & Examples

To access the chat, chatCompletion, chatCompletionStream, and generateImage methods in the nuxt-chatgpt module, you can use the useChatgpt() composable, which provides easy access to them.

The chat, and chatCompletion methods requires three parameters:

Name Type Default Description
message String available only for chat() A string representing the text message that you want to send to the GPT model for processing.
messages Array available only for chatCompletion() and chatCompletionStream() An array of objects that contains role and content
model String gpt-5-mini for chat() and gpt-5-mini for chatCompletion() Represent certain model for different types of natural language processing tasks.
options Object { temperature: 0.5, max_tokens: 2048, top_p: 1 frequency_penalty: 0, presence_penalty: 0 } An optional object that specifies any additional options you want to pass to the API request, such as, the number of responses to generate, and the maximum length of each response.

The generateImage method requires one parameters:

Name Type Default Description
message String A text description of the desired image(s). The maximum length is 1000 characters.
model String gpt-image-1-mini The model to use for image generation.
options Object { n: 1, quality: 'standard', response_format: 'url', size: '1024x1024', style: 'natural' } An optional object that specifies any additional options you want to pass to the API request, such as, the number of images to generate, quality, size and style of the generated images.

Available models:

  • text-davinci-002
  • text-davinci-003
  • gpt-3.5-turbo
  • gpt-3.5-turbo-0301
  • gpt-3.5-turbo-1106
  • gpt-4
  • gpt-4o
  • gpt-4o-mini
  • gpt-4-turbo
  • gpt-4-1106-preview
  • gpt-4-0314
  • gpt-4-0314
  • gpt-4-0613
  • gpt-4-32k
  • gpt-4-32k-0314
  • gpt-4-32k-0613
  • gpt-5-nano
  • gpt-5-mini
  • gpt-5-pro
  • gpt-5.1
  • gpt-5.2-pro
  • gpt-5.2
  • dall-e-3
  • gpt-image-1
  • gpt-image-1-mini
  • gpt-image-1.5

Simple chat usage

In the following example, the model is unspecified, and the gpt-4o-mini model will be used by default.

const { chat } = useChatgpt()

const data = ref('')
const inputData = ref('')

async function sendMessage() {
  try {
    const response = await chat(inputData.value)
    data.value = response
  } catch(error) {
    alert(`Verify your organization if you want to use GPT-5 models: ${error}`)
  }
}

<template>



    <input v-model="inputData">
    <button
      @click="sendMessage"
      v-text="'Send'"
    />


{{ data }}





</template>

Usage of chat with different model

const { chat } = useChatgpt()

const data = ref('')
const inputData = ref('')

async function sendMessage() {
  try {
    const response = await chat(inputData.value, 'gpt-5-mini')
    data.value = response
  } catch(error) {
    alert(`Verify your organization if you want to use GPT-5 models: ${error}`)
  }
}

<template>



    <input v-model="inputData">
    <button
      @click="sendMessage"
      v-text="'Send'"
    />


{{ data }}





</template>

Simple chatCompletion usage

In the following example, the model is unspecified, and the gpt-4o-mini model will be used by default.

const { chatCompletion } = useChatgpt()

const chatTree = ref([])
const inputData = ref('')

async function sendMessage() {
  try {
    const message = {
      role: 'user',
      content: `${inputData.value}`,
    }

    chatTree.value.push(message)

    const response = await chatCompletion(chatTree.value)

    const responseMessage = {
      role: response[0].message.role,
      content: response[0].message.content
    }

    chatTree.value.push(responseMessage)
  } catch(error) {
    alert(`Verify your organization if you want to use GPT-5 models: ${error}`)
  }
}

<template>



    <input v-model="inputData">
    <button
      @click="sendMessage"
      v-text="'Send'"
    />






        <strong>{{ chat.role }} :</strong>


{{ chat.content }} 











</template>

Usage of chatCompletion with different model

const { chatCompletion } = useChatgpt()

const chatTree = ref([])
const inputData = ref('')

async function sendMessage() {
  try {
    const message = {
      role: 'user',
      content: `${inputData.value}`,
    }

    chatTree.value.push(message)

    const response = await chatCompletion(chatTree.value, 'gpt-5-mini')

    const responseMessage = {
      role: response[0].message.role,
      content: response[0].message.content
    }

    chatTree.value.push(responseMessage)
  } catch(error) {
    alert(`Verify your organization if you want to use GPT-5 models: ${error}`)
  }
}

<template>



    <input v-model="inputData">
    <button
      @click="sendMessage"
      v-text="'Send'"
    />






        <strong>{{ chat.role }} :</strong>


{{ chat.content }} 











</template>

Simple chatCompletionStream usage (streaming)

In the following example, the model is unspecified, and the gpt-4o-mini model will be used by default.

const { chatCompletionStream } = useChatgpt()

const chatTree = ref([])
const inputData = ref('')

async function sendStreamedMessage() {
  try {
    const message = {
      role: 'user',
      content: `${inputData.value}`,
    }

    chatTree.value.push(message)

    const assistantMessage = {
      role: 'assistant',
      content: ''
    }

    chatTree.value.push(assistantMessage)

    // IMPORTANT: do not send the placeholder assistant message to the server
    const payloadMessages = chatTree.value.slice(0, -1)

    await chatCompletionStream(payloadMessages, undefined, undefined, {
      onToken(token) {
        assistantMessage.content += token
      },
      onDone() {
        // streaming finished
      },
      onError(err) {
        alert(`Stream error: ${typeof err === "string" ? err : err?.message || "Unknown"}`)
      }
    })
  } catch(error) {
    alert(`Verify your organization if you want to use GPT-5 models: ${error}`)
  }
}

<template>



    <input v-model="inputData">
    <button
      @click="sendStreamedMessage"
      v-text="'Send Streamed'"
    />






        <strong>{{ chat.role }} :</strong>


{{ chat.content }} 











</template>

Simple generateImage usage

In the following example, the model is unspecified, and the gpt-image-1-mini model will be used by default.

const { generateImage } = useChatgpt()

const images = ref([])
const inputData = ref('')
const loading = ref(false)

function b64ToBlobUrl(b64) {
  const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
  const blob = new Blob([bytes], { type: "image/png" });
  return URL.createObjectURL(blob);
}

async function sendPrompt() {
  loading.value = true;
  try {
    const result = await generateImage(inputData.value);
    images.value = result.map((img) => ({
      url: b64ToBlobUrl(img.b64_json),
    }));
  } catch (error) {
    alert(`Error: ${error}`);
  }
  loading.value = false;
}

<template>






      <input v-model="inputData">
      <button
        @click="sendPrompt"
        v-text="'Send Prompt'"
      />





Generating, please wait ...





      <img v-for="image in images" :key="image.url" :src="https://github.com/SchnapsterDog/nuxt-chatgpt/raw/v0.4.0/image.url" alt="generated-image"/>






</template>

Usage of generateImage with different model, and options

const { generateImage } = useChatgpt()

const images = ref([])
const inputData = ref('')
const loading = ref(false)

async function sendPrompt() {
  loading.value = true
  try {
    images.value = await generateImage(inputData.value, 'dall-e-3', {
      n: 1,
      quality: 'standard',
      response_format: 'url',
      size: '1024x1024',
      style: 'natural'
    })
  } catch (error) {
    alert(`Error: ${error}`)
  }
  loading.value = false
}
<template>






      <input v-model="inputData">
      <button
        @click="sendPrompt"
        v-text="'Send Prompt'"
      />





Generating, please wait ...





      <img v-for="image in images" :key="image.url" :src="https://github.com/SchnapsterDog/nuxt-chatgpt/raw/v0.4.0/image.url" alt="generated-image"/>






</template>

chat vs chatCompletion

The chat method allows the user to

Extension points exported contracts — how you extend this code

ModuleOptions (Interface)
(no doc)
src/module.ts
IChatgptClient (Interface)
(no doc)
src/runtime/types/index.d.ts
IMessage (Interface)
(no doc)
src/runtime/types/index.d.ts
IModel (Interface)
(no doc)
src/runtime/types/index.d.ts
IOptions (Interface)
(no doc)
src/runtime/types/index.d.ts

Core symbols most depended-on inside this repo

writeEvent
called by 4
src/runtime/server/api/chat-completion-stream.ts
emit
called by 2
src/runtime/composables/useChatgpt.ts
setup
called by 1
src/module.ts
chat
called by 0
src/runtime/types/index.d.ts
chatCompletion
called by 0
src/runtime/types/index.d.ts
generateImage
called by 0
src/runtime/types/index.d.ts
useChatgpt
called by 0
src/runtime/composables/useChatgpt.ts
chat
called by 0
src/runtime/composables/useChatgpt.ts

Shape

Function 8
Interface 5
Method 3

Languages

TypeScript100%

Modules by API surface

src/runtime/types/index.d.ts7 symbols
src/runtime/composables/useChatgpt.ts6 symbols
src/module.ts2 symbols
src/runtime/server/api/chat-completion-stream.ts1 symbols

For agents

$ claude mcp add nuxt-chatgpt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page