1
0
Fork 0

Check for models modality

This commit is contained in:
Pabloader 2026-04-14 14:42:34 +00:00
parent 93a40db640
commit c2ad2cfae4
2 changed files with 39 additions and 9 deletions

View File

@ -30,7 +30,7 @@ export const ConnectionSettings = () => {
const fetchModels = useMemo(() => async (conn: LLM.Connection | null) => { const fetchModels = useMemo(() => async (conn: LLM.Connection | null) => {
if (!conn) return []; if (!conn) return [];
const r = await LLM.getModels(conn); const r = await LLM.getTextModels(conn);
return r.data; return r.data;
}, []); }, []);

View File

@ -118,13 +118,22 @@ namespace LLM {
error: string; error: string;
} }
export interface ModelInfo { type Modality = 'text' | 'image';
interface BaseModelInfo {
id: string; id: string;
object: 'model'; object: 'model';
created: number; created: number;
owned_by: string; owned_by: string;
context_length: number;
supported_parameters: string[]; supported_parameters: string[];
architecture?: {
input_modalities: Modality[];
output_modalities: Modality[];
};
}
interface ModelInfoText extends BaseModelInfo {
context_length: number;
top_provider: { top_provider: {
context_length: number; context_length: number;
max_completion_tokens: number; max_completion_tokens: number;
@ -132,11 +141,22 @@ namespace LLM {
}; };
} }
export interface ModelsResponse { interface ModelInfoImage extends BaseModelInfo {
object: 'list';
data: ModelInfo[];
} }
export type ModelInfo = ModelInfoText | ModelInfoImage;
const isTextModel = (model: ModelInfo): model is ModelInfoText => ('context_length' in model);
const isImageModel = (model: ModelInfo): model is ModelInfoImage => Boolean(
!isTextModel(model) &&
model.architecture &&
(model.architecture.output_modalities).includes('image')
);
export interface ModelsResponse<T extends ModelInfo = ModelInfo> {
object: 'list';
data: T[];
}
interface CountTokensRequestString { interface CountTokensRequestString {
model: string; model: string;
@ -246,8 +266,18 @@ namespace LLM {
return e != null && typeof e === 'object' && 'data' in e && typeof e.data === 'string'; return e != null && typeof e === 'object' && 'data' in e && typeof e.data === 'string';
} }
export async function getModels(connection: Connection): Promise<ModelsResponse> { export async function getTextModels(connection: Connection): Promise<ModelsResponse<ModelInfoText>> {
return request<ModelsResponse>(connection, '/v1/models'); const response = await request<ModelsResponse>(connection, '/v1/models');
response.data = response.data.filter(isTextModel);
return response as ModelsResponse<ModelInfoText>;
}
export async function getImageModels(connection: Connection): Promise<ModelsResponse<ModelInfoImage>> {
const response = await request<ModelsResponse>(connection, '/v1/models');
response.data = response.data.filter(isImageModel);
return response as ModelsResponse<ModelInfoImage>;
} }
export async function countTokens(connection: Connection, body: CountTokensRequest) { export async function countTokens(connection: Connection, body: CountTokensRequest) {