File size: 1,421 Bytes
8178d95
 
 
 
 
 
 
4e0c974
 
8178d95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a51da98
8178d95
a51da98
 
8178d95
 
 
 
 
4e0c974
 
8178d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from fastapi import APIRouter, Request,Depends
from App.Users.Model import User
from App.Users.UserRoutes import get_token_owner
from App.Users.Schemas import UserSchema
from App.Transcription.Model import Transcriptions
from App.Transcription.Schemas import *
from App import bot
from .utils.Summarize import Summarizer

import aiohttp
import os

chat_router = APIRouter(tags=["chat"])


P_API_KEY = os.environ.get("API_KEY")
P_API_BASE = os.environ.get("P_API_BASE")
API_URL = f"{P_API_BASE}chat-bison-001:generateMessage?key={P_API_KEY}"


async def fetch_and_forward_request(request_body):
    async with aiohttp.ClientSession() as session:
        async with session.post(API_URL, data=request_body) as response:
            response_text = await response.text()
            return response_text, response.status


# @chat_router.post("/sql")
# async def generate_message(request_body: str):
#     response_body, status_code = await fetch_and_forward_request(request_body)
#     return response_body


@chat_router.get("/summarize/{task_id}")
async def generate_message(    task_id: str,
    # user: UserSchema = Depends(get_token_owner)
    ):
    entry: Transcriptions = await Transcriptions.objects.filter(task_id=task_id).first()
    result = BaseTranscription(**entry.__dict__)
    text =''
    for item in result.content:
        text+=item['text']
    summary=await Summarizer(text)
    return  [summary]