Add Together AI model discovery with dynamic API key support

This commit is contained in:
Riccardo Giorato committed 2026-01-26 16:07:09 +01:00
1 parent 39cd9102c1
commit 7d4d53366e
4 files changed
+221 -117

No files matched your search

+4 -4
View File
@@ -5,21 +5,21 @@ export async function applyDefaultModelChoice(params: {
config: ClawdbotConfig;
setDefaultModel: boolean;
defaultModel: string;
applyDefaultConfig: (config: ClawdbotConfig) => ClawdbotConfig;
applyProviderConfig: (config: ClawdbotConfig) => ClawdbotConfig;
applyDefaultConfig: (config: ClawdbotConfig) => ClawdbotConfig | Promise<ClawdbotConfig>;
applyProviderConfig: (config: ClawdbotConfig) => ClawdbotConfig | Promise<ClawdbotConfig>;
noteDefault?: string;
noteAgentModel: (model: string) => Promise<void>;
prompter: WizardPrompter;
}): Promise<{ config: ClawdbotConfig; agentModelOverride?: string }> {
if (params.setDefaultModel) {
const next = params.applyDefaultConfig(params.config);
const next = await params.applyDefaultConfig(params.config);
if (params.noteDefault) {
await params.prompter.note(`Default model set to ${params.noteDefault}`, "Model configured");
}
return { config: next };
}
const next = params.applyProviderConfig(params.config);
const next = await params.applyProviderConfig(params.config);
await params.noteAgentModel(params.defaultModel);
return { config: next, agentModelOverride: params.defaultModel };
}
+29 -10
View File
@@ -4,6 +4,7 @@ import {
SYNTHETIC_DEFAULT_MODEL_REF,
SYNTHETIC_MODEL_CATALOG,
} from "../agents/synthetic-models.js";
import { discoverTogetherModels } from "../agents/together-models.js";
// Together AI constants and models - inline to avoid separate models file
const TOGETHER_BASE_URL = "https://api.together.xyz/v1";
@@ -518,7 +519,7 @@ export function applyVeniceConfig(cfg: ClawdbotConfig): ClawdbotConfig {
};
}
export function applyTogetherProviderConfig(cfg: ClawdbotConfig): ClawdbotConfig {
export async function applyTogetherProviderConfig(cfg: ClawdbotConfig): Promise<ClawdbotConfig> {
const models = { ...cfg.agents?.defaults?.models };
models[TOGETHER_DEFAULT_MODEL_REF] = {
...models[TOGETHER_DEFAULT_MODEL_REF],
@@ -528,19 +529,37 @@ export function applyTogetherProviderConfig(cfg: ClawdbotConfig): ClawdbotConfig
const providers = { ...cfg.models?.providers };
const existingProvider = providers.together;
const existingModels = Array.isArray(existingProvider?.models) ? existingProvider.models : [];
const togetherModels = TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition);
const mergedModels = [
...existingModels,
...togetherModels.filter(
(model) => !existingModels.some((existing) => existing.id === model.id),
),
];
// Try dynamic discovery if API key is available, otherwise fall back to static catalog
const { apiKey: existingApiKey, ...existingProviderRest } = (existingProvider ?? {}) as Record<
string,
unknown
> as { apiKey?: string };
const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : undefined;
const normalizedApiKey = resolvedApiKey?.trim();
let togetherModels;
if (normalizedApiKey) {
// Try dynamic discovery with API key
try {
togetherModels = await discoverTogetherModels(normalizedApiKey);
console.log(`[together-models] Dynamic discovery found ${togetherModels.length} models`);
} catch (error) {
console.warn(`[together-models] Dynamic discovery failed, using static catalog: ${error}`);
togetherModels = TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition);
}
} else {
// No API key, use static catalog
togetherModels = TOGETHER_MODEL_CATALOG.map(buildTogetherModelDefinition);
}
const mergedModels = [
...existingModels,
...togetherModels.filter(
(model) => !existingModels.some((existing) => existing.id === model.id),
),
];
providers.together = {
...existingProviderRest,
baseUrl: TOGETHER_BASE_URL,
@@ -565,8 +584,8 @@ export function applyTogetherProviderConfig(cfg: ClawdbotConfig): ClawdbotConfig
};
}
export function applyTogetherConfig(cfg: ClawdbotConfig): ClawdbotConfig {
const next = applyTogetherProviderConfig(cfg);
export async function applyTogetherConfig(cfg: ClawdbotConfig): Promise<ClawdbotConfig> {
const next = await applyTogetherProviderConfig(cfg);
const existingModel = next.agents?.defaults?.model;
return {
...next,