diff --git a/plugins/genai/agent-langgraph/README.md b/plugins/genai/agent-langgraph/README.md index 0a685b5..4a1cdff 100644 --- a/plugins/genai/agent-langgraph/README.md +++ b/plugins/genai/agent-langgraph/README.md @@ -53,4 +53,5 @@ genai: openai: apiKey: ${OPENAI_API_KEY} # (Required) OpenAI model name modelName: 'gpt-3.5-turbo-instruct' # (Optional) OpenAI model name + baseUrl: ${OPENAI_API_BASE_URL} # (Optional) URL for OpenAI API endpoint ``` diff --git a/plugins/genai/agent-langgraph/config.d.ts b/plugins/genai/agent-langgraph/config.d.ts index 2765904..c3ede1a 100644 --- a/plugins/genai/agent-langgraph/config.d.ts +++ b/plugins/genai/agent-langgraph/config.d.ts @@ -59,6 +59,10 @@ export interface Config { * (Optional) Name of the OpenAI model to use */ modelName?: string; + /** + * (Optional) Base URL of the OpenAI API + */ + baseUrl?: string; }; }; }; diff --git a/plugins/genai/agent-langgraph/src/LangGraphReactAgentType.ts b/plugins/genai/agent-langgraph/src/LangGraphReactAgentType.ts index 30364a5..3ed0470 100644 --- a/plugins/genai/agent-langgraph/src/LangGraphReactAgentType.ts +++ b/plugins/genai/agent-langgraph/src/LangGraphReactAgentType.ts @@ -84,8 +84,10 @@ export class LangGraphReactAgentType implements AgentType { agentModel = LangGraphReactAgentType.createBedrockModel(agentLangGraphConfig); } else if (agentLangGraphConfig.openai) { - agentModel = - LangGraphReactAgentType.createOpenAIModel(agentLangGraphConfig); + agentModel = LangGraphReactAgentType.createOpenAIModel( + agentLangGraphConfig, + logger, + ); } else { throw new Error('No agent model configured'); } @@ -133,10 +135,22 @@ export class LangGraphReactAgentType implements AgentType { }); } - private static createOpenAIModel(config: LangGraphAgentConfig) { + private static createOpenAIModel( + config: LangGraphAgentConfig, + logger: LoggerService, + ) { const { modelName, apiKey } = config.openai!; + const baseUrl = config.openai?.baseUrl ?? 'https://api.openai.com/v1'; + + logger.info( + `Instantiating ChatOpenAI model '${modelName}' using baseUrl '${baseUrl}'`, + ); + return new ChatOpenAI({ + configuration: { + baseURL: baseUrl, + }, apiKey: apiKey, streaming: true, modelName: modelName, diff --git a/plugins/genai/agent-langgraph/src/config/config.ts b/plugins/genai/agent-langgraph/src/config/config.ts index 4ac40b8..6a404f7 100644 --- a/plugins/genai/agent-langgraph/src/config/config.ts +++ b/plugins/genai/agent-langgraph/src/config/config.ts @@ -87,5 +87,6 @@ export function readLangGraphAgentOpenAIConfig( return { apiKey: config.getString('apiKey'), modelName: config.getOptionalString('modelName'), + baseUrl: config.getOptionalString('baseUrl'), }; } diff --git a/plugins/genai/agent-langgraph/src/config/types.ts b/plugins/genai/agent-langgraph/src/config/types.ts index de9a712..f4fd612 100644 --- a/plugins/genai/agent-langgraph/src/config/types.ts +++ b/plugins/genai/agent-langgraph/src/config/types.ts @@ -39,4 +39,5 @@ export interface LangGraphAgentBedrockConfig { export interface LangGraphAgentOpenAIConfig { apiKey: string; modelName?: string; + baseUrl?: string; }