I am creating an app which should take a pdf, text (to be pasted in text area) and the type of llm as an input and after taking all the inputs the app should call the fastapi backend. Below is the code for integrating streamlit with fastapi:
def generate(text,llm_type):
url = “http://localhost:8000/generate/”
data = {“text”:text,“llm_type”:llm_type}
response = requests.post(url, data = data)
The issue I have is that in the backend I am able to get the text but not the llm_type. ( In the frontend I have a side bar in which radio buttons are there of different llm types and user needs to select the type of llm he needs to use). The backend is suppose to take the llm_type string, then with normal if else the llm code is selected, but llm_type is always coming as None. I have tested in the frontend, the selected llm_type string is being passed.
I think you’d need to ensure that the JSON structure and the data types you’re sending match exactly what your FastAPI endpoint expects according to its definition (e.g., the Pydantic model if you’ve updated to use one).
Also, you’ll need to check that all required fields are included and correctly formatted in your JSON payload.
Hi Charly,
In the fastapi function I changed the query parameters to the following and it worked for me. : @app.post(“/generate/”)
async def gen(text:str = Form(…), llm_type : Optional[str] = Form(None):
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.