Next.js Discord

Discord Forum

Unknown application error occurred Runtime.Unknown with Python Function Vercel

Unanswered
European pilchard posted this in #help-forum
Open in Discord
European pilchardOP
Hello, I know this is a Next.JS server but I figured its associated with Vercel so if anyone has some python knowledge I'd be grateful for some help. I keep getting:

Unknown application error occurred
Runtime.Unknown

I am using FastAPI to run an API route. When I test locally, my script runs and returns properly with UVICorn. But when I test it on Vercel, it builds but gives me that Runtime.Unknown error. Has anyone ever run into this? Is there something specific I have to do to make my code work with Vercel? Ill paste in my code below. Also, when I navigate to the route when hosted on Vercel, I get a 500 error, most likely just in relation to the Runtime.Unknown Error. Thanks in advance!

from fastapi import FastAPI
from starlette.responses import JSONResponse
from codeinterpreterapi import CodeInterpreterSession
from langchain.chat_models.openai import ChatOpenAI
import base64
import io

app = FastAPI()

@app.get("/py/interpreter")
async def get_btc_chart_2023():

    # create a session
    session = CodeInterpreterSession(model="gpt-3.5-turbo-0613", openai_api_key="sk-1234", verbose=True)
    await session.astart()

    # generate a response based on user input
    response = await session.generate_response(
        "Plot the bitcoin chart of 2023 YTD"
    )

    # output the response (text + image)
    print("AI: ", response.content)

    # save the image to a file and return it as a downloadable file
    if response.files:
        # convert binary image data to base64
        base64_image = base64.b64encode(response.files[0].content).decode("utf-8")
        
        # terminate the session
        await session.astop()

        # return as JSON
        return JSONResponse({"image": base64_image, "text": response.content})

    else:
        return {"message": "No image generated"}

0 Replies