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

pull/5197/head
Ankush Gola 1 year ago committed by GitHub
parent dcee8936c1
commit b7fcb35a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

@ -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,
)
)

Loading…
Cancel
Save