added /language-models endpoint
This commit is contained in:
@@ -172,6 +172,37 @@ export type ModelsResponse = {
|
||||
object: "list"
|
||||
}
|
||||
|
||||
type modality = 'text' | 'image' | string
|
||||
|
||||
export type LanguageModel = {
|
||||
aliases: {
|
||||
string
|
||||
},
|
||||
cached_prompt_text_token_price: number,
|
||||
completion_text_token_price: number,
|
||||
created: number,
|
||||
fingerprint: string,
|
||||
id: string,
|
||||
input_modalities: {
|
||||
modality
|
||||
},
|
||||
object: string,
|
||||
output_modalities: {
|
||||
modality
|
||||
},
|
||||
owned_by: string,
|
||||
prompt_image_token_price: number,
|
||||
prompt_text_token_price: number,
|
||||
search_price: number,
|
||||
version: string
|
||||
}
|
||||
|
||||
export type LangaugeModelsResponse = {
|
||||
models: {
|
||||
LanguageModel
|
||||
}
|
||||
}
|
||||
|
||||
local xai = {}
|
||||
local baseUrl = "https://api.x.ai/v1"
|
||||
|
||||
@@ -214,6 +245,23 @@ function xai.create(api_key: string)
|
||||
end
|
||||
end
|
||||
|
||||
function client:language_models(): LangaugeModelsResponse
|
||||
local config = {
|
||||
url = `{baseUrl}/language-models`,
|
||||
method = "GET",
|
||||
headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
},
|
||||
}
|
||||
local response = net.request(config)
|
||||
if response.ok then
|
||||
local decoded: LangaugeModelsResponse = serde.decode("json", response.body)
|
||||
return decoded
|
||||
else
|
||||
error(`API request failed with status {response.statusCode}: {response.statusMessage}`)
|
||||
end
|
||||
end
|
||||
|
||||
return client
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user