Can you write a more advanced Math Solver in this script with error handling? In poe.…
- User
Can you write a more advanced Math Solver in this script with error handling? In poe.
from __future__ import annotations from typing import AsyncIterable from modal import Image, Stub, asgi_app import fastapi_poe as fp import sympy class GPT35TurboBot(fp.PoeBot): async def get_response( self, request: fp.QueryRequest ) -> AsyncIterable[fp.PartialResponse]: async for msg in fp.stream_request( request, "GPT-3.5-Turbo", request.access_key ): yield msg async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse: return fp.SettingsResponse(server_bot_dependencies={"GPT-3.5-Turbo": 1}) class HttpRequestBot(fp.PoeBot): async def get_response_with_context( self, request: fp.QueryRequest, context: fp.RequestContext ) -> AsyncIterable[fp.PartialResponse]: request_url = context.http_request.url query_params = context.http_request.query_params yield fp.PartialResponse( text=f"The request url is: {request_url}, query params are: {query_params}" ) class AttachmentOutputDemoBot(fp.PoeBot): async def get_response( self, request: fp.QueryRequest ) -> AsyncIterable[fp.PartialResponse]: await self.post_message_attachment( message_id=request.message_id, file_data=request.query[-1].content, filename="dummy.txt" ) yield fp.PartialResponse(text=f"Attached a text file containing your last message.") class MathSolverBot(fp.PoeBot): async def get_response( self, request: fp.QueryRequest ) -> AsyncIterable[fp.PartialResponse]: try: expression = request.query[0].text result = sympy.sympify(expression).evalf() yield fp.PartialResponse(text=f"The solution to {expression} is {result}") except Exception as e: yield fp.PartialResponse(text=f"Error: {str(e)}") REQUIREMENTS = ["fastapi-poe==0.0.36", "sympy"] image = Image.debian_slim().pip_install(*REQUIREMENTS) stub = Stub("poebot-1") @stub.function(image=image) @asgi_app() def fastapi_app(): bot = mathsolver111() app = fp.make_app(bot, allow_without_key=True) return app - Assistant