Skip to content

Commit

Permalink
add default configs for all served runnables
Browse files Browse the repository at this point in the history
  • Loading branch information
jakerachleff committed Nov 10, 2023
1 parent 7e1a1a1 commit 971e454
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions langserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import contextlib
import json
import os
import re
import weakref
from inspect import isclass
Expand Down Expand Up @@ -554,6 +555,23 @@ def _route_name_with_config(name: str) -> str:
InvokeResponse = create_invoke_response_model(model_namespace, output_type_)
BatchResponse = create_batch_response_model(model_namespace, output_type_)

def _get_default_base_config() -> RunnableConfig:
"""Set up some baseline configuration for the underlying runnable."""
metadata = {}
is_hosted = os.environ.get("HOSTED_LANGSERVE_ENABLED", "false").lower() == "true"
if is_hosted:
hosted_metadata = {
"Commit SHA": os.environ.get("HOSTED_LANGSERVE_GIT_COMMIT", ""),
"Git Repo Subdirectory": os.environ.get("HOSTED_LANGSERVE_GIT_REPO_PATH", ""),
"Git Repo URL": os.environ.get("HOSTED_LANGSERVE_GIT_REPO", ""),

}
metadata.update(hosted_metadata)
return RunnableConfig(
run_name=path,
metadata=metadata,
)

async def _get_config_and_input(
request: Request, config_hash: str
) -> Tuple[RunnableConfig, Any]:
Expand Down Expand Up @@ -597,6 +615,7 @@ async def invoke(
# have dynamic schema -- so the validation below is a bit more involved.
config, input_ = await _get_config_and_input(request, config_hash)

config = merge_configs(_get_default_base_config(), config)
event_aggregator = AsyncEventAggregatorCallback()
_add_tracing_info_to_metadata(config, request)
config["callbacks"] = [event_aggregator]
Expand Down

0 comments on commit 971e454

Please sign in to comment.