SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
remove the implementation of adapting model based on the planInfo
Forhad Hosaind301eac448bf
diff --git a/packages/runtime/src/core/utils/llm.utils.ts b/packages/runtime/src/core/utils/llm.utils.tsdeleted file mode 100644index 6a63f456..00000000--- a/packages/runtime/src/core/utils/llm.utils.ts+++ /dev/null@@ -1,40 +0,0 @@-import { MODELS_FOR_LEGACY_USERS } from "@core/constants";--/**- * Adapts a model name based on user plan information and model availability.- *- * For users without access to built-in models (free users or users without the hasBuiltinModels flag),- * this function prefixes certain models with 'legacy/' to ensure they can still be used.- *- * @param {string} model - The original model name to be adapted- * @param {Record<string, any>} planInfo - User's plan information object- * @param {boolean} [planInfo.isDefaultPlan] - Whether the user is on the default/free plan- * @param {Object} [planInfo.flags] - Feature flags for the user's plan- * @param {boolean} [planInfo.flags.hasBuiltinModels] - Whether the user has access to built-in models- * @returns {string} The adapted model name, potentially prefixed with 'legacy/' if conditions are met.- * In case of any error during processing, returns the original model unchanged.- *- * @example- * -- For a free user trying to use a legacy model- * adaptModel('gpt-3.5-turbo', { isDefaultPlan: true }) // Returns 'legacy/gpt-3.5-turbo'- *- * @example- * -- For a premium user- * adaptModel('gpt-4', { isDefaultPlan: false, flags: { hasBuiltinModels: true } }) // Returns 'gpt-4'- */-export function adaptModel(model: string, planInfo: Record<string, any>) {- try {- const isFreeUser = planInfo?.isDefaultPlan;- const hasBuiltInModels = isFreeUser || planInfo?.flags?.hasBuiltinModels;-- // If the model is listed in the legacy models array and the user doesn't have access to built-in models, prefix the model with 'legacy/' to allow the model to be used- if (!hasBuiltInModels && MODELS_FOR_LEGACY_USERS.includes(model)) {- return `legacy/${model}`;- }-- return model;- } catch {- // Fallback: if any error occurs during processing, return the original model to ensure function never throws- return model;- }-}diff --git a/packages/runtime/src/modules/embodiment/modules/alexa/services/alexa.service.ts b/packages/runtime/src/modules/embodiment/modules/alexa/services/alexa.service.tsindex c9ec3961..21551ddd 100644--- a/packages/runtime/src/modules/embodiment/modules/alexa/services/alexa.service.ts+++ b/packages/runtime/src/modules/embodiment/modules/alexa/services/alexa.service.ts@@ -1,4 +1,3 @@-import { adaptModel } from "@core/utils/llm.utils";import { getOpenAPIJSONForAI } from "@embodiment/helpers/openapi-adapter.helper";import { Agent, Conversation } from "@smythos/sre";import axios from "axios";@@ -223,8 +222,7 @@ export function processAlexaSearchQuery();// Adapt the model based on the user's plan, especially to support certain OpenAI models for legacy users with limited tokens without their own API key.- const adaptedModel = adaptModel(model, agent?.planInfo || {});- const conversation = new Conversation(adaptedModel, spec, {+ const conversation = new Conversation(model, spec, {agentId: agent.id,});conversation.on("error", (error) => {diff --git a/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts b/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.tsindex 7f9fb82a..db7a715e 100644--- a/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts+++ b/packages/runtime/src/modules/embodiment/modules/chatbot/services/Chatbot.class.ts@@ -4,7 +4,6 @@ import { Request } from "express";import config from "@core/config";import { EMBODIMENT_TYPES } from "@core/constants";import { delay } from "@core/utils/date-time.utils";-import { adaptModel } from "@core/utils/llm.utils";import { getOpenAPIJSONForAI } from "@embodiment/helpers/openapi-adapter.helper";import { ChatConversationsEnv } from "@embodiment/utils/chat.utils";@@ -222,8 +221,7 @@ export default class Chatbot {);// Adapt the model based on the user's plan, especially to support certain OpenAI models for legacy users with limited tokens without their own API key.- const adaptedModel = adaptModel(this.model, this.agent?.planInfo || {});- const conversation = new Conversation(adaptedModel, spec, {+ const conversation = new Conversation(this.model, spec, {maxContextSize: this.contextWindow,maxOutputTokens: this.maxOutputTokens,agentId: this.agentId,diff --git a/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts b/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.tsindex a57f3dac..40bcaec7 100644--- a/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts+++ b/packages/runtime/src/modules/embodiment/modules/openai/services/chat.service.ts@@ -1,5 +1,4 @@import ApiError from "@core/utils/apiError";-import { adaptModel } from "@core/utils/llm.utils";import { getAgentIdAndVersion } from "@embodiment/helpers/agent.helper";import {AccessCandidate,@@ -62,8 +61,7 @@ class OpenAIChatService {.join("\n");// Adapt the model based on the user's plan, especially to support certain OpenAI models for legacy users with limited tokens without their own API key.- const adaptedModel = adaptModel(modelId, agent?.planInfo || {});- const conv = new Conversation(adaptedModel, agentId, { agentVersion });+ const conv = new Conversation(modelId, agentId, { agentVersion });await conv.ready;if (systemPrompt.trim()?.length) {conv.systemPrompt += `\n\n######\n\n${systemPrompt}`;diff --git a/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts b/packages/runtime/src/modules/embodiment/services/Chatbot.class.tsindex 58bb5d15..d537cbd8 100644--- a/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts+++ b/packages/runtime/src/modules/embodiment/services/Chatbot.class.ts@@ -10,7 +10,6 @@ import { FsChatbotContextStore } from "./FsChatbotContextStore.class";import { ConversationStreamYield } from "./FsChatbotContextStore.class/FsChatbotContextExporter.class";import { ChatConversationsEnv } from "../utils/chat.utils";import { delay } from "../utils/date-time.utils";-import { adaptModel } from "../utils/llm.utils";type Headers = {"x-conversation-id": string;@@ -204,8 +203,7 @@ export default class Chatbot {);// Adapt the model based on the user's plan, especially to support certain OpenAI models for legacy users with limited tokens without their own API key.- const adaptedModel = adaptModel(this.model, this.agent?.planInfo || {});- const conversation = new Conversation(adaptedModel, spec, {+ const conversation = new Conversation(this.model, spec, {maxContextSize: this.contextWindow,maxOutputTokens: this.maxOutputTokens,agentId: this.agentId,diff --git a/packages/runtime/src/modules/embodiment/utils/llm.utils.ts b/packages/runtime/src/modules/embodiment/utils/llm.utils.tsdeleted file mode 100644index 6a63f456..00000000--- a/packages/runtime/src/modules/embodiment/utils/llm.utils.ts+++ /dev/null@@ -1,40 +0,0 @@-import { MODELS_FOR_LEGACY_USERS } from "@core/constants";--/**- * Adapts a model name based on user plan information and model availability.- *- * For users without access to built-in models (free users or users without the hasBuiltinModels flag),- * this function prefixes certain models with 'legacy/' to ensure they can still be used.- *- * @param {string} model - The original model name to be adapted- * @param {Record<string, any>} planInfo - User's plan information object- * @param {boolean} [planInfo.isDefaultPlan] - Whether the user is on the default/free plan- * @param {Object} [planInfo.flags] - Feature flags for the user's plan- * @param {boolean} [planInfo.flags.hasBuiltinModels] - Whether the user has access to built-in models- * @returns {string} The adapted model name, potentially prefixed with 'legacy/' if conditions are met.- * In case of any error during processing, returns the original model unchanged.- *- * @example- * -- For a free user trying to use a legacy model- * adaptModel('gpt-3.5-turbo', { isDefaultPlan: true }) // Returns 'legacy/gpt-3.5-turbo'- *- * @example- * -- For a premium user- * adaptModel('gpt-4', { isDefaultPlan: false, flags: { hasBuiltinModels: true } }) // Returns 'gpt-4'- */-export function adaptModel(model: string, planInfo: Record<string, any>) {- try {- const isFreeUser = planInfo?.isDefaultPlan;- const hasBuiltInModels = isFreeUser || planInfo?.flags?.hasBuiltinModels;-- // If the model is listed in the legacy models array and the user doesn't have access to built-in models, prefix the model with 'legacy/' to allow the model to be used- if (!hasBuiltInModels && MODELS_FOR_LEGACY_USERS.includes(model)) {- return `legacy/${model}`;- }-- return model;- } catch {- // Fallback: if any error occurs during processing, return the original model to ensure function never throws- return model;- }-}