If the method succeeds, the return value is the number of models
which match the specified options. If the method fails, the return
value is LLM_ERROR. To get extended error information, call
GetLastError.
The EnumModels method enumerates the models available for
the provider associated with the client session. The client must have been
successfully connected before calling this method. The returned list is
based on the provider metadata available to the library and, when supported
by the provider, information returned by the provider itself.
To determine how many models match the specified options, call this
method with the lpModelList parameter set to NULL and the
nMaxModels parameter set to zero. If the method succeeds, the
return value is the number of matching models. You can then allocate an
array of LLM_MODEL_INFO structures and call the method again to retrieve
the model information.
Each LLM_MODEL_INFO structure should have its dwSize member initialized
to the size of the structure before calling this method. This enables the
library to validate the structure version and maintain compatibility with
future releases.
The model list may be cached for a limited period of time to avoid
unnecessary requests to the provider. Use GetCacheTime and
SetCacheTime to determine or change the cache lifetime for the
client session.
The model capabilities reported by this method are intended to help an
application select an appropriate model. Providers may change their model
availability, capabilities, or status over time, and the provider remains
the final authority on whether a specific model can be used for a request.
LONG nModels = llmClient.EnumModels(LLM_MODEL_OPTION_DEFAULT);
if (nModels > 0)
{
LPLLM_MODEL_INFO lpModelList;
lpModelList = (LPLLM_MODEL_INFO)calloc(nModels, sizeof(LLM_MODEL_INFO));
if (lpModelList != NULL)
{
for (LONG nIndex = 0; nIndex < nModels; nIndex++)
lpModelList[nIndex].dwSize = sizeof(LLM_MODEL_INFO);
nModels = llmClient.EnumModels(lpModelList, nModels, LLM_MODEL_OPTION_DEFAULT);
if (nModels != LLM_ERROR)
{
for (LONG nIndex = 0; nIndex < nModels; nIndex++)
_tprintf(_T("%s\n"), lpModelList[nIndex].szName);
}
free(lpModelList);
}
}
else if (nModels == LLM_ERROR)
{
DWORD dwError = LlmGetLastError();
_tprintf(_T("Unable to enumerate models, error 0x%08lx\n"), dwError);
}