mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
fixes model initialization for mlx
This commit is contained in:
@@ -126,31 +126,38 @@ const ChatService = types
|
||||
// ----- Helpers ----------------------------------------------------------
|
||||
const logger = console;
|
||||
|
||||
// ----- 1. Try cached value ---------------------------------------------
|
||||
try {
|
||||
const cached = yield self.env.KV_STORAGE.get('supportedModels');
|
||||
if (cached) {
|
||||
const parsed = JSON.parse(cached as string);
|
||||
if (Array.isArray(parsed)) {
|
||||
logger.info('Cache hit – returning supportedModels from KV');
|
||||
return new Response(JSON.stringify(parsed), { status: 200 });
|
||||
const useCache = false;
|
||||
|
||||
if(useCache) {
|
||||
// ----- 1. Try cached value ---------------------------------------------
|
||||
try {
|
||||
const cached = yield self.env.KV_STORAGE.get('supportedModels');
|
||||
if (cached) {
|
||||
const parsed = JSON.parse(cached as string);
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
logger.info('Cache hit – returning supportedModels from KV');
|
||||
return new Response(JSON.stringify(parsed), { status: 200 });
|
||||
}
|
||||
logger.warn('Cache entry malformed – refreshing');
|
||||
}
|
||||
logger.warn('Cache entry malformed – refreshing');
|
||||
} catch (err) {
|
||||
logger.error('Error reading/parsing supportedModels cache', err);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Error reading/parsing supportedModels cache', err);
|
||||
}
|
||||
|
||||
|
||||
// ----- 2. Build fresh list ---------------------------------------------
|
||||
const providerRepo = new ProviderRepository(self.env);
|
||||
const providers = providerRepo.getProviders();
|
||||
|
||||
console.log({ providers })
|
||||
const providerModels = new Map<string, any[]>();
|
||||
const modelMeta = new Map<string, any>();
|
||||
|
||||
for (const provider of providers) {
|
||||
if (!provider.key) continue;
|
||||
|
||||
logger.info(`Fetching models for provider «${provider.name}»`);
|
||||
logger.info(`Fetching models from «${provider.endpoint}»`);
|
||||
|
||||
const openai = new OpenAI({ apiKey: provider.key, baseURL: provider.endpoint });
|
||||
|
||||
|
@@ -17,20 +17,32 @@ const MetricsService = types
|
||||
},
|
||||
handleMetricsRequest: flow(function* (request: Request) {
|
||||
const url = new URL(request.url);
|
||||
const proxyUrl = `https://metrics.seemueller.io${url.pathname}${url.search}`;
|
||||
let proxyUrl = "";
|
||||
if(self.env.METRICS_HOST) {
|
||||
proxyUrl = new URL(`${self.env.METRICS_HOST}${url.pathname}${url.search}`).toString();
|
||||
}
|
||||
|
||||
try {
|
||||
const response = yield fetch(proxyUrl, {
|
||||
if(proxyUrl) {
|
||||
try {
|
||||
const response = yield fetch(proxyUrl, {
|
||||
method: request.method,
|
||||
headers: request.headers,
|
||||
body: ["GET", "HEAD"].includes(request.method) ? null : request.body,
|
||||
redirect: "follow",
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Failed to proxy metrics request:", error);
|
||||
return new Response("metrics misconfigured", { status: 200 });
|
||||
}
|
||||
} else {
|
||||
const event = {
|
||||
method: request.method,
|
||||
headers: request.headers,
|
||||
body: ["GET", "HEAD"].includes(request.method) ? null : request.body,
|
||||
redirect: "follow",
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Failed to proxy metrics request:", error);
|
||||
return new Response("Failed to fetch metrics", { status: 500 });
|
||||
}
|
||||
self.env.KV_STORAGE.put(`metrics_events::${crypto.randomUUID()}`, JSON.stringify(event));
|
||||
}
|
||||
}),
|
||||
}));
|
||||
|
@@ -39,7 +39,7 @@ const TransactionService = types
|
||||
`https://wallets.seemueller.io${CreateWalletEndpoints[currency]}`,
|
||||
);
|
||||
const walletResponse = await walletRequest.text();
|
||||
console.log({ walletRequest: walletResponse });
|
||||
// console.log({ walletRequest: walletResponse });
|
||||
const [address, privateKey, publicKey, phrase] =
|
||||
JSON.parse(walletResponse);
|
||||
|
||||
@@ -56,12 +56,12 @@ const TransactionService = types
|
||||
phrase,
|
||||
};
|
||||
|
||||
console.log({ txRecord });
|
||||
// console.log({ txRecord });
|
||||
|
||||
const key = `transactions::prepared::${txKey}`;
|
||||
|
||||
await self.env.KV_STORAGE.put(key, JSON.stringify(txRecord));
|
||||
console.log(`PREPARED TRANSACTION ${key}`);
|
||||
// console.log(`PREPARED TRANSACTION ${key}`);
|
||||
|
||||
return {
|
||||
depositAddress: address,
|
||||
@@ -72,7 +72,7 @@ const TransactionService = types
|
||||
handleTransact: async function (request: Request) {
|
||||
try {
|
||||
const raw = await request.text();
|
||||
console.log({ raw });
|
||||
// console.log({ raw });
|
||||
const [action, ...payload] = raw.split(",");
|
||||
|
||||
const response = await self.routeAction(action, payload);
|
||||
|
Reference in New Issue
Block a user