Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
nuxt-chatgpt
Advanced tools
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.
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.
useChatgpt()
composable that grants easy access to the chat
, and chatCompletion
, and generateImage
methods.npm install --save-dev nuxt-chatgpt
pnpm add -D nuxt-chatgpt
yarn add --dev nuxt-chatgpt
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 🔥
To access the chat
, chatCompletion
, 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() | An array of objects that contains role and content |
model | String | gpt-4o-mini for chat() and gpt-4o-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 | dall-e-2 or dall-e-3 | The model to use for image generation. Only dall-e-2 is supported at this time. |
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:
chat
usageIn 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(`Join the waiting list if you want to use GPT-4 models: ${error}`)
}
}
<template>
<div>
<input v-model="inputData">
<button
@click="sendMessage"
v-text="'Send'"
/>
<div>{{ data }}</div>
</div>
</template>
chat
with different modelconst { chat } = useChatgpt()
const data = ref('')
const inputData = ref('')
async function sendMessage() {
try {
const response = await chat(inputData.value, 'gpt-4o-mini')
data.value = response
} catch(error) {
alert(`Join the waiting list if you want to use GPT-4 models: ${error}`)
}
}
<template>
<div>
<input v-model="inputData">
<button
@click="sendMessage"
v-text="'Send'"
/>
<div>{{ data }}</div>
</div>
</template>
chatCompletion
usageIn 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(`Join the waiting list if you want to use GPT-4 models: ${error}`)
}
}
<template>
<div>
<input v-model="inputData">
<button
@click="sendMessage"
v-text="'Send'"
/>
<div>
<div
v-for="chat in chatTree"
:key="chat"
>
<strong>{{ chat.role }} :</strong>
<div>{{ chat.content }} </div>
</div>
</div>
</div>
</template>
chatCompletion
with different modelconst { 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-4o-mini')
const responseMessage = {
role: response[0].message.role,
content: response[0].message.content
}
chatTree.value.push(responseMessage)
} catch(error) {
alert(`Join the waiting list if you want to use GPT-4 models: ${error}`)
}
}
<template>
<div>
<input v-model="inputData">
<button
@click="sendMessage"
v-text="'Send'"
/>
<div>
<div
v-for="chat in chatTree"
:key="chat"
>
<strong>{{ chat.role }} :</strong>
<div>{{ chat.content }} </div>
</div>
</div>
</div>
</template>
generateImage
usageIn the following example, the model is unspecified, and the dall-e-2 model will be used by default.
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)
} catch (error) {
alert(`Error: ${error}`)
}
loading.value = false
}
<template>
<div>
<div v-if="!loading && !images.length">
<input v-model="inputData">
<button
@click="sendPrompt"
v-text="'Send Prompt'"
/>
</div>
<div v-else-if="loading">Generating, please wait ...</div>
<div v-if="images && !loading" >
<img v-for="image in images" :key="image.url" :src="image.url" alt="generated-image"/>
</div>
</div>
</template>
generateImage
with different model, and optionsconst { 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-2', {
n: 1,
quality: 'standard',
response_format: 'url',
size: '1024x1024',
style: 'natural'
})
} catch (error) {
alert(`Error: ${error}`)
}
loading.value = false
}
<template>
<div>
<div v-if="!loading && !images.length">
<input v-model="inputData">
<button
@click="sendPrompt"
v-text="'Send Prompt'"
/>
</div>
<div v-else-if="loading">Generating, please wait ...</div>
<div v-if="images && !loading" >
<img v-for="image in images" :key="image.url" :src="image.url" alt="generated-image"/>
</div>
</div>
</template>
The chat
method allows the user to send a prompt to the OpenAI API and receive a response. You can use this endpoint to build conversational interfaces that can interact with users in a natural way. For example, you could use the chat method to build a chatbot that can answer customer service questions or provide information about a product or service.
The chatCompletion
method is similar to the chat
method, but it provides additional functionality for generating longer, more complex responses. Specifically, the chatCompletion method allows you to provide a conversation history as input, which the API can use to generate a response that is consistent with the context of the conversation. This makes it possible to build chatbots that can engage in longer, more natural conversations with users.
Name | Type | Default | Description |
---|---|---|---|
apiKey | String | xxxxxx | Your apiKey here goes here |
isEnabled | Boolean | true | Enable or disable the module. True by default. |
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE.txt
for more information.
Oliver Trajceski - LinkedIn - oliver@akrinum.com
Project Link: https://nuxtchatgpt.com
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release
Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!
v0.2.5
FAQs
ChatGPT integration for Nuxt 3
The npm package nuxt-chatgpt receives a total of 199 weekly downloads. As such, nuxt-chatgpt popularity was classified as not popular.
We found that nuxt-chatgpt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.