35 lines
784 B
Python
35 lines
784 B
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
API路由模块,为前端提供REST API接口
|
||
"""
|
||
|
||
import os
|
||
from fastapi import APIRouter, Depends, HTTPException, status, Body
|
||
from typing import Dict, Any, List, Optional
|
||
from pydantic import BaseModel
|
||
import json
|
||
import logging
|
||
|
||
from cryptoai.api.deepseek_api import DeepSeekAPI
|
||
from cryptoai.utils.config_loader import ConfigLoader
|
||
from fastapi.responses import StreamingResponse
|
||
# 创建路由
|
||
router = APIRouter()
|
||
|
||
class ChatRequest(BaseModel):
|
||
user_prompt: str
|
||
|
||
|
||
@router.post("/chat")
|
||
async def chat(request: ChatRequest):
|
||
"""
|
||
聊天接口
|
||
"""
|
||
|
||
deepseek_api = DeepSeekAPI()
|
||
response = deepseek_api.streaming_call(request.user_prompt)
|
||
|
||
return StreamingResponse(response, media_type="text/plain")
|