-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
27 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,20 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This is a sample API file that demonstrates how to create an API using FastAPI, | ||
which is compatible with ChainLit. This file is a starting point for creating | ||
an API that can be deployed with the ChainLit chatbot. | ||
""" | ||
|
||
import logging | ||
|
||
from chainlit.server import app | ||
from fastapi import Request | ||
from fastapi import FastAPI, Request | ||
from fastapi.responses import HTMLResponse | ||
|
||
import chatbot | ||
|
||
if __name__ == "__main__": | ||
# If running directly, define the FastAPI app | ||
app = FastAPI() | ||
else: | ||
# Otherwise use ChainLit's app | ||
from chainlit.server import app | ||
|
||
logger = logging.getLogger(f"chatbot.{__name__}") | ||
|
||
_chat_engine = None | ||
|
||
|
||
def chat_engine(): | ||
# pylint: disable=global-statement | ||
global _chat_engine | ||
if not _chat_engine: | ||
# Load the initial settings | ||
settings = chatbot.initial_settings | ||
chatbot.validate_settings(settings) | ||
|
||
# Create the chat engine | ||
_chat_engine = chatbot.create_chat_engine(settings) | ||
|
||
return _chat_engine | ||
|
||
|
||
# See https://docs.chainlit.io/deploy/api#how-it-works | ||
@app.get("/hello") | ||
def hello(request: Request): | ||
logger.info(request.headers) | ||
return HTMLResponse("Hello World") | ||
@app.get("/query/{message}") | ||
def query(message: str): | ||
response = chat_engine().gen_response(message) | ||
return HTMLResponse(response) | ||
|
||
|
||
@app.get("/healthcheck") | ||
def healthcheck(): | ||
def healthcheck(request: Request): | ||
logger.info(request.headers) | ||
# TODO: Add a health check - https://pypi.org/project/fastapi-healthchecks/ | ||
return HTMLResponse("Healthy") | ||
|
||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
uvicorn.run("__main__:app", host="0.0.0.0", port=8001, log_level="info") |
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