mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 00:16:29 +02:00
fix: bypass gateway for local model connection tests
This commit is contained in:
parent
de24293cce
commit
e9b392b0b9
3 changed files with 32 additions and 2 deletions
|
|
@ -6,7 +6,8 @@
|
|||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsc",
|
||||
"dev": "tsc -w"
|
||||
"dev": "tsc -w",
|
||||
"test": "tsc --pretty false && node --test dist/models/models.test.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ai-sdk/anthropic": "^2.0.63",
|
||||
|
|
|
|||
20
apps/x/packages/core/src/models/models.test.ts
Normal file
20
apps/x/packages/core/src/models/models.test.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { shouldUseGatewayForModelTest } from "./models.js";
|
||||
|
||||
test("signed-in ollama model tests bypass the gateway", () => {
|
||||
assert.equal(shouldUseGatewayForModelTest("ollama", true), false);
|
||||
});
|
||||
|
||||
test("signed-in openai-compatible model tests bypass the gateway", () => {
|
||||
assert.equal(shouldUseGatewayForModelTest("openai-compatible", true), false);
|
||||
});
|
||||
|
||||
test("signed-in hosted model tests still use the gateway", () => {
|
||||
assert.equal(shouldUseGatewayForModelTest("openai", true), true);
|
||||
});
|
||||
|
||||
test("signed-out hosted model tests do not use the gateway", () => {
|
||||
assert.equal(shouldUseGatewayForModelTest("openai", false), false);
|
||||
});
|
||||
|
|
@ -70,6 +70,14 @@ export function createProvider(config: z.infer<typeof Provider>): ProviderV2 {
|
|||
}
|
||||
}
|
||||
|
||||
export function shouldUseGatewayForModelTest(
|
||||
flavor: z.infer<typeof Provider>["flavor"],
|
||||
signedIn: boolean,
|
||||
): boolean {
|
||||
const isLocal = flavor === "ollama" || flavor === "openai-compatible";
|
||||
return signedIn && !isLocal;
|
||||
}
|
||||
|
||||
export async function testModelConnection(
|
||||
providerConfig: z.infer<typeof Provider>,
|
||||
model: string,
|
||||
|
|
@ -80,7 +88,8 @@ export async function testModelConnection(
|
|||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), effectiveTimeout);
|
||||
try {
|
||||
const provider = await isSignedIn()
|
||||
const signedIn = await isSignedIn();
|
||||
const provider = shouldUseGatewayForModelTest(providerConfig.flavor, signedIn)
|
||||
? await getGatewayProvider()
|
||||
: createProvider(providerConfig);
|
||||
const languageModel = provider.languageModel(model);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue