clarified correct type for decoded /v1/models/{model_id} response, added /v1/language-models/{model_id} endpoint
This commit is contained in:
@@ -177,8 +177,8 @@ export type ModelsResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type model_id = string
|
type model_id = string
|
||||||
export type ModelRequest = model_id
|
|
||||||
|
|
||||||
|
export type ModelRequest = model_id
|
||||||
export type ModelResponse = model
|
export type ModelResponse = model
|
||||||
|
|
||||||
type modality = 'text' | 'image' | string
|
type modality = 'text' | 'image' | string
|
||||||
@@ -212,12 +212,15 @@ export type LanguageModelsResponse = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LanguageModelRequest = model_id
|
||||||
|
export type LanguageModelResponse = LanguageModel
|
||||||
|
|
||||||
type ApiResponse = {
|
type ApiResponse = {
|
||||||
success: boolean
|
success: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SuccessfulApiResponse = ApiResponse & {
|
export type SuccessfulApiResponse = ApiResponse & {
|
||||||
response: CompletionsResponse | ModelsResponse | ModelResponse | LanguageModelsResponse
|
response: CompletionsResponse | ModelsResponse | ModelResponse | LanguageModelsResponse | LanguageModelResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FailedApiResponse = ApiResponse & {
|
export type FailedApiResponse = ApiResponse & {
|
||||||
@@ -277,7 +280,7 @@ function xai.create(api_key: string)
|
|||||||
}
|
}
|
||||||
local response = net.request(config)
|
local response = net.request(config)
|
||||||
if response.ok then
|
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
|
return { success = true, response = decoded } :: SuccessfulApiResponse
|
||||||
else
|
else
|
||||||
return { success = false, status = response.status, message = response.body } :: FailedApiResponse
|
return { success = false, status = response.status, message = response.body } :: FailedApiResponse
|
||||||
@@ -301,6 +304,23 @@ function xai.create(api_key: string)
|
|||||||
end
|
end
|
||||||
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
|
return client
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user