added /v1/models/{model_id} endpoint
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
local net = require("@lune/net")
|
||||
local serde = require("@lune/serde")
|
||||
|
||||
export type model = 'grok-4' | 'grok-code-fast-1' | 'grok-4-fast-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-3-mini' | 'grok-3' | 'grok-2-vision'
|
||||
export type AvailableModels = 'grok-4' | 'grok-code-fast-1' | 'grok-4-fast-reasoning' | 'grok-4-fast-non-reasoning' | 'grok-3-mini' | 'grok-3' | 'grok-2-vision'
|
||||
|
||||
export type message = {
|
||||
role: string,
|
||||
@@ -99,7 +99,7 @@ type rsssource = {
|
||||
|
||||
export type CompletionsRequest = {
|
||||
messages: { message },
|
||||
model: model,
|
||||
model: AvailableModels,
|
||||
stream: false?,
|
||||
search_parameters: {
|
||||
mode: 'auto' | 'on' | 'off',
|
||||
@@ -162,16 +162,25 @@ export type CompletionsRequest = {
|
||||
}?
|
||||
}
|
||||
|
||||
type model = {
|
||||
created: number,
|
||||
id: string,
|
||||
object: "model",
|
||||
owned_by: string
|
||||
}
|
||||
|
||||
export type ModelsResponse = {
|
||||
data : {
|
||||
created: number,
|
||||
id: string,
|
||||
object: "model",
|
||||
owned_by: string
|
||||
model
|
||||
},
|
||||
object: "list"
|
||||
}
|
||||
|
||||
type model_id = string
|
||||
export type ModelRequest = model_id
|
||||
|
||||
export type ModelResponse = model
|
||||
|
||||
type modality = 'text' | 'image' | string
|
||||
|
||||
export type LanguageModel = {
|
||||
@@ -208,7 +217,7 @@ type ApiResponse = {
|
||||
}
|
||||
|
||||
export type SuccessfulApiResponse = ApiResponse & {
|
||||
response: CompletionsResponse | ModelsResponse | LanguageModelsResponse
|
||||
response: CompletionsResponse | ModelsResponse | ModelResponse | LanguageModelsResponse
|
||||
}
|
||||
|
||||
export type FailedApiResponse = ApiResponse & {
|
||||
@@ -258,6 +267,23 @@ function xai.create(api_key: string)
|
||||
end
|
||||
end
|
||||
|
||||
function client:model(model_id: ModelRequest): SuccessfulApiResponse | FailedApiResponse
|
||||
local config = {
|
||||
url = `{baseUrl}/models/{model_id}`,
|
||||
method = "GET",
|
||||
headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
},
|
||||
}
|
||||
local response = net.request(config)
|
||||
if response.ok then
|
||||
local decoded: ModelsResponse = serde.decode("json", response.body)
|
||||
return { success = true, response = decoded } :: SuccessfulApiResponse
|
||||
else
|
||||
return { success = false, status = response.status, message = response.body } :: FailedApiResponse
|
||||
end
|
||||
end
|
||||
|
||||
function client:language_models(): SuccessfulApiResponse | FailedApiResponse
|
||||
local config = {
|
||||
url = `{baseUrl}/language-models`,
|
||||
|
||||
Reference in New Issue
Block a user