Skip to content

The agent engineering platform.

add option to pass openai key to langchain plus command (#5213)

Ankush Golab7fcb35a39f3
diff --git a/langchain/cli/docker-compose.yaml b/langchain/cli/docker-compose.yaml
index 06527198c4..b86f3dfa26 100644
--- a/langchain/cli/docker-compose.yaml
+++ b/langchain/cli/docker-compose.yaml
@@ -19,6 +19,7 @@ services:
- PORT=1984
- LANGCHAIN_ENV=local_docker
- LOG_LEVEL=warning
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
ports:
- 1984:1984
depends_on:
diff --git a/langchain/cli/main.py b/langchain/cli/main.py
index 9a3b02622f..3f59ec169d 100644
--- a/langchain/cli/main.py
+++ b/langchain/cli/main.py
@@ -173,6 +173,7 @@ class PlusCommand:
expose: bool = False,
auth_token: Optional[str] = None,
dev: bool = False,
+ openai_api_key: Optional[str] = None,
) -> None:
"""Run the LangChainPlus server locally.
@@ -180,9 +181,16 @@ class PlusCommand:
expose: If True, expose the server to the internet using ngrok.
auth_token: The ngrok authtoken to use (visible in the ngrok dashboard).
If not provided, ngrok server session length will be restricted.
+ dev: If True, use the development (rc) image of LangChainPlus.
+ openai_api_key: The OpenAI API key to use for LangChainPlus
+ If not provided, the OpenAI API Key will be read from the
+ OPENAI_API_KEY environment variable. If neither are provided,
+ some features of LangChainPlus will not be available.
"""
if dev:
os.environ["_LANGCHAINPLUS_IMAGE_PREFIX"] = "rc-"
+ if openai_api_key is not None:
+ os.environ["OPENAI_API_KEY"] = openai_api_key
if expose:
self._start_and_expose(auth_token=auth_token)
else:
@@ -250,9 +258,20 @@ def main() -> None:
action="store_true",
help="Use the development version of the LangChainPlus image.",
)
+ server_start_parser.add_argument(
+ "--openai-api-key",
+ default=os.getenv("OPENAI_API_KEY"),
+ help="The OpenAI API key to use for LangChainPlus."
+ " If not provided, the OpenAI API Key will be read from the"
+ " OPENAI_API_KEY environment variable. If neither are provided,"
+ " some features of LangChainPlus will not be available.",
+ )
server_start_parser.set_defaults(
func=lambda args: server_command.start(
- expose=args.expose, auth_token=args.ngrok_authtoken, dev=args.dev
+ expose=args.expose,
+ auth_token=args.ngrok_authtoken,
+ dev=args.dev,
+ openai_api_key=args.openai_api_key,
)
)