Fixes "Method not implemented" error caused by faulty optional chaining of env.OPENAI_API_ENDPOINT

- Disable unsupported model groups and improve OpenAI endpoint checks.
- Upgrade wrangler
This commit is contained in:
geoffsee
2025-05-29 20:16:15 -04:00
committed by Geoff Seemueller
parent cc0da17b5f
commit 246b673111
4 changed files with 28 additions and 20 deletions

View File

@@ -74,7 +74,7 @@ const ChatService = types
};
const getSupportedModels = async () => {
if(self.env.OPENAI_API_ENDPOINT.includes("localhost")) {
if(self.env.OPENAI_API_ENDPOINT && self.env.OPENAI_API_ENDPOINT.includes("localhost")) {
const openaiClient = new OpenAI({baseURL: self.env.OPENAI_API_ENDPOINT})
const models = await openaiClient.models.list();
return Response.json(models.data.map(model => model.id));
@@ -141,7 +141,7 @@ const ChatService = types
setEnv(env: Env) {
self.env = env;
if(env.OPENAI_API_ENDPOINT.includes("localhost")) {
if(env.OPENAI_API_ENDPOINT && env.OPENAI_API_ENDPOINT.includes("localhost")) {
self.openai = new OpenAI({
apiKey: self.env.OPENAI_API_KEY,
baseURL: self.env.OPENAI_API_ENDPOINT,
@@ -173,9 +173,17 @@ const ChatService = types
}) {
const {streamConfig, streamParams, controller, encoder, streamId} = params;
const modelFamily = !self.env.OPENAI_API_ENDPOINT.includes("localhost") ? getModelFamily(streamConfig.model) : "openai";
const useModelFamily = () => {
return !self.env.OPENAI_API_ENDPOINT || !self.env.OPENAI_API_ENDPOINT.includes("localhost") ? getModelFamily(streamConfig.model) : "openai";
}
const handler = !self.env.OPENAI_API_ENDPOINT.includes("localhost") ? modelHandlers[modelFamily as ModelFamily] : modelHandlers.openai;
const modelFamily = useModelFamily();
const useModelHandler = () => {
return !self.env.OPENAI_API_ENDPOINT || !self.env.OPENAI_API_ENDPOINT.includes("localhost") ? modelHandlers[modelFamily as ModelFamily] : modelHandlers.openai;
}
const handler = useModelHandler();
if (handler) {
try {