Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support OpenAI compatible APIs #317

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/genai/agent-langgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 4 additions & 0 deletions plugins/genai/agent-langgraph/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down
20 changes: 17 additions & 3 deletions plugins/genai/agent-langgraph/src/LangGraphReactAgentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions plugins/genai/agent-langgraph/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ export function readLangGraphAgentOpenAIConfig(
return {
apiKey: config.getString('apiKey'),
modelName: config.getOptionalString('modelName'),
baseUrl: config.getOptionalString('baseUrl'),
};
}
1 change: 1 addition & 0 deletions plugins/genai/agent-langgraph/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ export interface LangGraphAgentBedrockConfig {
export interface LangGraphAgentOpenAIConfig {
apiKey: string;
modelName?: string;
baseUrl?: string;
}
Loading