feat: 代码格式化统一
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = off
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
@@ -14,8 +14,8 @@ from pydantic import BaseModel, Field
|
|||||||
from starlette.staticfiles import StaticFiles
|
from starlette.staticfiles import StaticFiles
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
docs_url=None, # 禁用默认 Swagger
|
docs_url=None, # 禁用默认 Swagger
|
||||||
redoc_url=None, # 禁用默认 ReDoc
|
redoc_url=None, # 禁用默认 ReDoc
|
||||||
)
|
)
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
|
||||||
@@ -23,88 +23,88 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|||||||
# 自定义 Swagger 页面(使用本地资源)
|
# 自定义 Swagger 页面(使用本地资源)
|
||||||
@app.get("/docs", include_in_schema=False)
|
@app.get("/docs", include_in_schema=False)
|
||||||
async def custom_swagger_ui():
|
async def custom_swagger_ui():
|
||||||
"""
|
"""
|
||||||
提供自定义的 Swagger UI 文档页面
|
提供自定义的 Swagger UI 文档页面
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Swagger UI HTML 页面,使用本地静态资源加载
|
Swagger UI HTML 页面,使用本地静态资源加载
|
||||||
"""
|
"""
|
||||||
return get_swagger_ui_html(
|
return get_swagger_ui_html(
|
||||||
openapi_url=app.openapi_url,
|
openapi_url=app.openapi_url,
|
||||||
title=app.title + " - Swagger UI",
|
title=app.title + " - Swagger UI",
|
||||||
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
|
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
|
||||||
swagger_js_url="/static/swagger-ui-bundle.min.js",
|
swagger_js_url="/static/swagger-ui-bundle.min.js",
|
||||||
swagger_css_url="/static/swagger-ui.min.css",
|
swagger_css_url="/static/swagger-ui.min.css",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
|
@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
|
||||||
async def swagger_ui_redirect():
|
async def swagger_ui_redirect():
|
||||||
"""
|
"""
|
||||||
处理 Swagger UI 的 OAuth2 重定向回调
|
处理 Swagger UI 的 OAuth2 重定向回调
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
OAuth2 重定向 HTML 响应
|
OAuth2 重定向 HTML 响应
|
||||||
"""
|
"""
|
||||||
return get_swagger_ui_oauth2_redirect_html()
|
return get_swagger_ui_oauth2_redirect_html()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/redoc", include_in_schema=False)
|
@app.get("/redoc", include_in_schema=False)
|
||||||
async def redoc_html():
|
async def redoc_html():
|
||||||
"""
|
"""
|
||||||
提供自定义的 ReDoc 文档页面
|
提供自定义的 ReDoc 文档页面
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ReDoc HTML 页面,使用本地静态资源加载
|
ReDoc HTML 页面,使用本地静态资源加载
|
||||||
"""
|
"""
|
||||||
return get_redoc_html(
|
return get_redoc_html(
|
||||||
openapi_url=app.openapi_url,
|
openapi_url=app.openapi_url,
|
||||||
title=app.title + " - ReDoc",
|
title=app.title + " - ReDoc",
|
||||||
redoc_js_url="/static/redoc.standalone.js",
|
redoc_js_url="/static/redoc.standalone.js",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def redirect_root_to_docs():
|
async def redirect_root_to_docs():
|
||||||
"""
|
"""
|
||||||
将根路径请求重定向到 Swagger 文档页面
|
将根路径请求重定向到 Swagger 文档页面
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
重定向响应到 /docs 路径
|
重定向响应到 /docs 路径
|
||||||
"""
|
"""
|
||||||
return RedirectResponse("/docs")
|
return RedirectResponse("/docs")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/chat")
|
@app.get("/chat")
|
||||||
async def chat():
|
async def chat():
|
||||||
model = init_chat_model(
|
model = init_chat_model(
|
||||||
model="qwen2.5-vl-7b-instruct", # 你的模型名
|
model="qwen2.5-vl-7b-instruct", # 你的模型名
|
||||||
model_provider="openai", # 必须填 openai(兼容协议)
|
model_provider="openai", # 必须填 openai(兼容协议)
|
||||||
base_url="http://127.0.0.1:1234/v1", # 你的自定义 API URL
|
base_url="http://127.0.0.1:1234/v1", # 你的自定义 API URL
|
||||||
api_key="1234", # 本地模型随便填
|
api_key="1234", # 本地模型随便填
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
)
|
)
|
||||||
output = model.invoke("你好").content
|
output = model.invoke("你好").content
|
||||||
|
|
||||||
print(f"output:{output}")
|
print(f"output:{output}")
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
# Edit this to add the chain you want to add
|
# Edit this to add the chain you want to add
|
||||||
# add_routes(app, NotImplemented)
|
# add_routes(app, NotImplemented)
|
||||||
|
|
||||||
model = init_chat_model(
|
model = init_chat_model(
|
||||||
model="doubao-1-5-pro-32k-250115", # 你的模型名
|
model="doubao-1-5-pro-32k-250115", # 你的模型名
|
||||||
model_provider="openai", # 必须填 openai(兼容协议)
|
model_provider="openai", # 必须填 openai(兼容协议)
|
||||||
base_url="https://ark.cn-beijing.volces.com/api/v3/", # 你的自定义 API URL
|
base_url="https://ark.cn-beijing.volces.com/api/v3/", # 你的自定义 API URL
|
||||||
api_key="b1e7c7e0-33af-480e-b0a8-2812ba97f7b1", # 本地模型随便填
|
api_key="b1e7c7e0-33af-480e-b0a8-2812ba97f7b1", # 本地模型随便填
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
streaming=False
|
streaming=False
|
||||||
)
|
)
|
||||||
|
|
||||||
add_routes(app=app,runnable=model,path="/qwen")
|
add_routes(app=app, runnable=model, path="/qwen")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(app, host="localhost", port=8000)
|
uvicorn.run(app, host="localhost", port=8000)
|
||||||
|
|||||||
Reference in New Issue
Block a user