commit
91c7acc569
@ -1,46 +0,0 @@ |
||||
# controller/app_description_v1.py |
||||
from fastapi import APIRouter, HTTPException |
||||
from dbgpt.component import SystemApp, ComponentType |
||||
from dbgpt.core import ModelRequest |
||||
from dbgpt.model.cluster.client import DefaultLLMClient # ✅ 使用已定义的客户端类 |
||||
|
||||
router = APIRouter() |
||||
system_app = SystemApp() |
||||
|
||||
# 获取项目主配置的模型客户端(直接复用 DefaultLLMClient) |
||||
model_client = DefaultLLMClient() |
||||
|
||||
_PROMPT_TEMPLATE = """作为应用助手,请根据名称生成描述: |
||||
名称:{app_name} |
||||
要求: |
||||
1. 突出核心功能 |
||||
2. 口语化中文 |
||||
3. 80字以内 |
||||
|
||||
生成结果:""" |
||||
|
||||
|
||||
@router.post("/ai_generate_description") |
||||
async def generate_description(app_name: str): |
||||
try: |
||||
# 参数校验 |
||||
if not app_name or len(app_name) > 50: |
||||
raise ValueError("应用名称需为1-50字符") |
||||
|
||||
# 构造提示词 |
||||
prompt = _PROMPT_TEMPLATE.format(app_name=app_name.strip()) |
||||
|
||||
# 调用模型(自动继承项目配置) |
||||
response = await model_client.generate( |
||||
ModelRequest(prompt=prompt, max_new_tokens=200) |
||||
) |
||||
|
||||
# 清理结果 |
||||
description = response.text.strip().strip('"').strip("'") |
||||
return {"description": description} |
||||
|
||||
except Exception as e: |
||||
raise HTTPException( |
||||
status_code=500, |
||||
detail=f"生成失败: {str(e)}" |
||||
) |
@ -0,0 +1,7 @@ |
||||
from pydantic import BaseModel |
||||
|
||||
|
||||
# 定义请求体模型 |
||||
class GenerateRequest(BaseModel): |
||||
app_name: str |
||||
describe: str |
Loading…
Reference in new issue