clarified correct type for decoded /v1/models/{model_id} response, added /v1/language-models/{model_id} endpoint

This commit is contained in:
2025-10-05 23:21:50 -06:00
parent b214999d50
commit eb098ce266

View File

@@ -177,8 +177,8 @@ export type ModelsResponse = {
}
type model_id = string
export type ModelRequest = model_id
export type ModelRequest = model_id
export type ModelResponse = model
type modality = 'text' | 'image' | string
@@ -212,12 +212,15 @@ export type LanguageModelsResponse = {
}
}
export type LanguageModelRequest = model_id
export type LanguageModelResponse = LanguageModel
type ApiResponse = {
success: boolean
}
export type SuccessfulApiResponse = ApiResponse & {
response: CompletionsResponse | ModelsResponse | ModelResponse | LanguageModelsResponse
response: CompletionsResponse | ModelsResponse | ModelResponse | LanguageModelsResponse | LanguageModelResponse
}
export type FailedApiResponse = ApiResponse & {
@@ -277,7 +280,7 @@ function xai.create(api_key: string)
}
local response = net.request(config)
if response.ok then
local decoded: ModelsResponse = serde.decode("json", response.body)
local decoded: ModelResponse = serde.decode("json", response.body)
return { success = true, response = decoded } :: SuccessfulApiResponse
else
return { success = false, status = response.status, message = response.body } :: FailedApiResponse
@@ -301,6 +304,23 @@ function xai.create(api_key: string)
end
end
function client:language_model(model_id: LanguageModelRequest): SuccessfulApiResponse | FailedApiResponse
local config = {
url = `{baseUrl}/language-models/{model_id}`,
method = "GET",
headers = {
["Content-Type"] = "application/json",
},
}
local response = net.request(config)
if response.ok then
local decoded: LanguageModelResponse = serde.decode("json", response.body)
return { success = true, response = decoded } :: SuccessfulApiResponse
else
return { success = false, status = response.status, message = response.body } :: FailedApiResponse
end
end
return client
end