mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 12:18:24 +00:00
add option to pass openai key to langchain plus command (#5213)
This commit is contained in:
parent
dcee8936c1
commit
b7fcb35a39
@ -19,6 +19,7 @@ services:
|
|||||||
- PORT=1984
|
- PORT=1984
|
||||||
- LANGCHAIN_ENV=local_docker
|
- LANGCHAIN_ENV=local_docker
|
||||||
- LOG_LEVEL=warning
|
- LOG_LEVEL=warning
|
||||||
|
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||||
ports:
|
ports:
|
||||||
- 1984:1984
|
- 1984:1984
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@ -173,6 +173,7 @@ class PlusCommand:
|
|||||||
expose: bool = False,
|
expose: bool = False,
|
||||||
auth_token: Optional[str] = None,
|
auth_token: Optional[str] = None,
|
||||||
dev: bool = False,
|
dev: bool = False,
|
||||||
|
openai_api_key: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run the LangChainPlus server locally.
|
"""Run the LangChainPlus server locally.
|
||||||
|
|
||||||
@ -180,9 +181,16 @@ class PlusCommand:
|
|||||||
expose: If True, expose the server to the internet using ngrok.
|
expose: If True, expose the server to the internet using ngrok.
|
||||||
auth_token: The ngrok authtoken to use (visible in the ngrok dashboard).
|
auth_token: The ngrok authtoken to use (visible in the ngrok dashboard).
|
||||||
If not provided, ngrok server session length will be restricted.
|
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:
|
if dev:
|
||||||
os.environ["_LANGCHAINPLUS_IMAGE_PREFIX"] = "rc-"
|
os.environ["_LANGCHAINPLUS_IMAGE_PREFIX"] = "rc-"
|
||||||
|
if openai_api_key is not None:
|
||||||
|
os.environ["OPENAI_API_KEY"] = openai_api_key
|
||||||
if expose:
|
if expose:
|
||||||
self._start_and_expose(auth_token=auth_token)
|
self._start_and_expose(auth_token=auth_token)
|
||||||
else:
|
else:
|
||||||
@ -250,9 +258,20 @@ def main() -> None:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Use the development version of the LangChainPlus image.",
|
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(
|
server_start_parser.set_defaults(
|
||||||
func=lambda args: server_command.start(
|
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…
Reference in New Issue
Block a user