我正在尝试 Azure AI 搜索。后端使用 python 并作为 Linux Web 应用程序运行。在
app/backend/approaches/charreadretrieveread.py
的部分地区
async def run_until_final_call(
self,
history: list[dict[str, str]],
overrides: dict[str, Any],
auth_claims: dict[str, Any],
should_stream: bool = False,
) -> tuple[dict[str, Any], Coroutine[Any, Any, Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]]]:
#print("/chat user question: " , history[-1])
logging.basicConfig(level=logging.INFO)
logging.info('Hello, logging!')
虽然此时没有引发错误,但在 Azure protal 中,“Hello,logging!”没有显示在后端 -> 流日志。
在后端 -> Web服务日志中,我已经设置了
level: verbose
application logging: file system
quota: 35 mb
retention periods(days): 1
我尝试了示例代码来打印 Azure Web 应用程序的日志流中的日志。
代码:
from flask import Flask
import logging
from typing import Any, Coroutine, Union
app = Flask(__name__)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class ChatCompletion:
pass
class AsyncStream:
pass
class ChatCompletionChunk:
pass
search_service_endpoint = "https://<search_name>.search.windows.net"
index_name = "<index_name>"
api_key = "<search_apiKey>"
async def run_until_final_call(
history: list[dict[str, str]],
overrides: dict[str, Any],
auth_claims: dict[str, Any],
should_stream: bool = False,
) -> tuple[dict[str, Any], Coroutine[Any, Any, Union[ChatCompletion, AsyncStream, ChatCompletionChunk]]]:
pass
@app.route('/')
def hello_world():
logger.info('Hello, logging!')
return 'Hello, Kamali!'
if __name__ == '__main__':
app.run(debug=True, port=8080)
本地输出:
代码运行成功,如下图。
Azure 门户:
部署后,我在 Azure Web 应用程序的应用服务日志中启用了文件系统,如下所示。
然后我能够在 Azure Web 应用程序日志流中查看日志。