Examples

Here are some real-world application examples of AI for your codebase.

These are just some useful examples. Please feel free to add more via Pull Requests.

Full Chat (Demo)

<script setup lang="ts">
    const { messages, send } = useGPT().createChat()
    const input = ref<string>('')
</script>

<template>
   <pre>{{ messages }}</pre>
   <input
      type="text"
      v-model="input"
      @keyup.enter="send(input, () => (input = ''))" />
</template>

Single message

const { answer } = useGPT('Give me 5 alternative search terms for sneakers').send()

Check spelling

const res = await useGPT('Check spelling of "kaola bear" and correct it if neccessary')
.toStructured(
  z.object({
    isCorrect: z.boolean(),
    correctedText: z.string()
  })
)
// Output
{
  isCorrect: false,
  correctedText: 'koala bear'
}

const response = useGPT('Provide 5 alternative search terms')
   .addContextData('sneakers')
   .toStructured(
      z.object({
         suggestions: z.array(z.string()),
      }),
   )
// Output
{
  suggestions: [
    'trainers',
    'athletic shoes',
    'running shoes',
    'casual sneakers',
    'sport shoes'
  ]
}
Note: This example uses .addContextData for the base term. The term could of course also be added in the prompt itself.

Read article aloud

const audioURLBase64 = await useGPT(articleRef.value.textContent)
.toSpeech()

Get Weather

const res = await useGPT('Current weather in San Francisco')
.toStructured(
  z.object({
    celsius: z.number(),
    fahrenheit: z.number(),
    weatherLabel: z.object({
      en: z.string(),
      de: z.string(),
    })
  })
)
// Output
{
  celsius: 15,
  fahrenheit: 59,
  weatherLabel: {
    en: "Partly Cloudy"
    de: "Teilweise bewölkt",
  }
}