Skip to main content

OpenAI

Activation

Set your OpenAI key in your .env file

SERVER_OPENAI_API_KEY=YOUR_API_KEY

Usage

Use the Ai api in your front-end.

import { Api } from '@/core/trpc'

const { mutateAsync: generateText } = Api.ai.generateText.useMutation()

const { mutateAsync: generateImage } = Api.ai.generateImage.useMutation()

function generateText() {
const generatedText = await generateText({
prompt: 'What is the most expensive marble in the world?',
})
}

function generatePicture() {
const { url } = await generateImage({
prompt: 'A beautiful green marble',
})
}

Available endpoints

Api.ai.generateText
Api.ai.generateImage
Api.ai.textToAudio
Api.ai.audioToText

Model Configuration

Adjust the AI model used by modifying the configuration in the src/server/libraries/openai/internal/openai.ts file

enum OpenaiModel {
DEFAULT = 'gpt-3.5-turbo-16k',
IMAGE = 'dall-e-3',
AUDIO_TO_TEXT = 'whisper-1',
TEXT_TO_AUDIO = 'tts-1',
}

Read More

Learn more on the official OpenAI documentation