import { Lira } from 'lira'

const lira = new Lira()

await lira.store.custom.message({
  input: {
    lira?: LiraMetadata
    max_tokens?: number
    messages: Array<Message>
    model: AnthropicModels | OpenAIModels
    provider: 'anthropic' | 'openai' | string
    temperature?: number
    top_p?: number
    tools?: Array<Tool>
    tool_choice?: ToolChoice
    stop_sequences?: Array<string>
    stream?: boolean
  }
  output?: {
    id: string
    model: string
    usage?: Usage
    message: AssistantResponse | ToolUseResponse
    logprobs?: Logprobs
    stop_reason: 'max_tokens' | 'stop_sequence' | 'stop'
    stop_sequence?: string
  }
  reqTime?: { start: number, end: number }
  error?: unknown
})

Input

lira
LiraMetadata

All this information are useful for tracking the usage of the API.

{
  endUser?: {
    id: string
    name?: string
  }
  sessionId?: string
  tags?: string[]
}
max_tokens
number

The maximum number of tokens to generate. Mind that in case the model generates more tokens than this value, the response will be truncated.

messages
Array<Message>

The array of messages to use as context for the model.

model
string

The model to use for generating the text.

provider
'anthropic' | 'openai' | string

The provider to use for generating the text. It can be either anthropic or openai or a custom provider.

temperature
number

The temperature value to use for generating the text.

top_p
number

The top_p value to use for generating the text.

tools
Array<Tool>

The array of tools to be eventually used by the model.

{
  type: 'function'
  data: {
    name: string
    description?: string
    properties?: Record<string, unknown>
    required?: Array<string>
  }
}
tool_choice
ToolChoice

The choice of the tool to be used by the model.


Behavior: If the type is auto, the model will choose the tool automatically.

{
  type: 'auto'
}

Behavior: If the type is tool, the model will use the tool with the given name.

{
  type: 'tool'
  name: string
}

Behavior: If the type is required, the model will be forced to use one of the available tools

{
  type: 'required'
}

Behavior: If the type is none, the model will not use any tool.

{
  type: 'none'
}
stop_sequences
Array<string>

The array of strings that will cause the model to stop generating tokens.

stream
boolean

If true, the model will generate the text in a streaming fashion.

Output

id
string

The unique identifier of the response.

model
string

The model used to generate the response.

Usually the model is the same as the one used in the request. But in some cases, the model name can be slightly different.

message
AssistantResponse | ToolUseResponse
required

The response message generated by the model.

stop_reason
'max_tokens' | 'stop_sequence' | 'stop'

The reason why the model stopped generating tokens.

  • max_tokens: The model reached the maximum token limit.

  • stop_sequence: The model incountered one of the provided stop_sequence tokens.

  • stop: The normal stop condition, the model reached the end of the response.

stop_sequence
string

The stop_sequence token that caused the model to stop generating tokens. In case the stop_reason is not stop_sequence, this field will be undefined.

usage
Usage

The usage object contains the number of tokens used in the input and output.

{
  input_tokens?: number
  output_tokens?: number
}
logprobs
Logprobs

The logprobs object contains the log probabilities of the tokens generated by the model.

Array<{
  token: string
  logprob: number
  bytes?: Array<number>
  top_logprobs?: Array<{ token: string; logprob: number; bytes?: Array<number> }>
}>

Request Time

start
number

The start time of the request in milliseconds.

end
number

The end time of the request in milliseconds.

To get the request time, you can use the following code snippet:

const start = Date.now()
// Your call to the LLM provider (or custom LLM)
const end = Date.now()

Error

error
unknown

The error object in case the request fails.