-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: name used for tracing should take into account APIRouter path (#…
…476) If there is a router at path /foo, and a runnable is added to that router at path /bar, the name of the runnable should be /foo/bar for logging purposes.
- Loading branch information
Showing
2 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
"""Example LangChain Server that uses a Fast API Router. | ||
When applications grow, it becomes useful to use FastAPI's Router to organize | ||
the routes. | ||
See more documentation at: | ||
https://fastapi.tiangolo.com/tutorial/bigger-applications/ | ||
""" | ||
from fastapi import APIRouter, FastAPI | ||
from langchain.chat_models import ChatAnthropic, ChatOpenAI | ||
|
||
from langserve import add_routes | ||
|
||
app = FastAPI() | ||
|
||
router = APIRouter(prefix="/models") | ||
|
||
# Invocations to this router will appear in trace logs as /models/openai | ||
add_routes( | ||
router, | ||
ChatOpenAI(), | ||
path="/openai", | ||
) | ||
# Invocations to this router will appear in trace logs as /models/anthropic | ||
add_routes( | ||
router, | ||
ChatAnthropic(), | ||
path="/anthropic", | ||
) | ||
|
||
app.include_router(router) | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
uvicorn.run(app, host="localhost", port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters