zhaoqingang
2024-11-21 dbbc7d891c0f9837d3580842fa5326ba40a21476
app/service/basic.py
@@ -10,10 +10,7 @@
        if response.status_code not in [200, 201]:
            raise Exception(f"Failed to fetch data from API: {response.text}")
        response_data = response.json()
        status_code = response_data.get("status_code", 0)
        if status_code != 200:
            raise Exception(f"Failed to fetch data from API: {response.text}")
        return response_data.get("data", {})
        return response_data
    async def download_from_url(self, url, params=None):
        async with httpx.AsyncClient() as client:
@@ -56,7 +53,7 @@
                files=files,
                params=params
            )
            return await self._check_response(response)
            return self._check_response(response)
    async def excel_talk(self, question: str, chat_id: str):
        url = f"{self.base_url}/exceltalk/talk"
@@ -68,10 +65,26 @@
                if response.status_code == 200:
                    try:
                        async for answer in response.aiter_text():
                            print(f"response of ragflow chat: {answer}")
                            print(f"response of excel_talk chat: {answer}")
                            yield answer
                    except GeneratorExit as e:
                        print(e)
                        return
                else:
                    yield f"Error: {response.status_code}"
                    yield f"Error: {response.status_code}"
    async def questions_talk(self, chat_id: str):
        url = f"{self.base_url}/questions/talk"
        params = {'chat_id': chat_id}
        headers = {'Content-Type': 'text/plain'}
        async with httpx.AsyncClient() as client:
            response = await client.post(
                url,
                headers=headers,
                params=params
            )
            return self._check_response(response)
    async def questions_talk_word_download(self, file_id: str):
        url = f"{self.base_url}/questions/download/word"
        return await self.download_from_url(url, params={'excel_name': file_id})