import { Lira } from 'lira'

const lira = new Lira()

await lira.store.openai.message({
  input: ChatCompletionCreateParams & LiraMetadata
  output?: Stream<ChatCompletionChunk> | ChatCompletion
  reqTime?: { start: number; end: number }
  error?: unknown
})

Options object

input
ChatCompletionCreateParams & LiraMetadata
required

ChatCompletionCreateParams is exactly the same as the one defined in the OpenAI API documentation.

{
  ...ChatCompletionCreateParams
  endUser?: {
    id: string
    name?: string
    passIdToUnderlyingLLM?: boolean
  }
  sessionId?: string
  tags?: string[]
  store?: {
    disabled?: boolean
    callback?: LiraStore.Callback
  }
}
output
Stream<ChatCompletionChunk> | ChatCompletion

The output type depends on the stream parameter passed in the request input.

Here are the properties defined in the OpenAI API documentation:

reqTime
{ start: number; end: number }

The time it took to process the request. In order to calculate the time it took to process the request, you can use the following code:

const start = Date.now()
await openai.chat.completions.create()
const end = Date.now()

const reqTime = { start, end }
error
unknown

The error that occurred while processing the request.