import streamlit as st import parsing from custom_prompt import TexRestructureTemplate,MetadataTemplate import ast # from gpt import get_chat_completion import openai openAiKey = st.text_input(label="Input the openai key", type="password") openai.api_key = openAiKey # if openAiKey: # try: # openai.api_key = openAiKey # # Test request to check if the key is valid # openai.ChatCompletion.create( # model="gpt-3.5-turbo", # messages=[ # {"role": "system", "content": "You are a helpful assistant."}, # {"role": "user", "content": "Test prompt to check OpenAI key validity."} # ] # ) # st.success("OpenAI key is valid!") # except Exception as e: # st.write(f"Invalid OpenAI key: {e}") # st.stop() def get_chat_completion(prompt, model="gpt-3.5-turbo"): try: response = openai.ChatCompletion.create( model=model, messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt} ] ) return response['choices'][0]['message']['content'] except Exception as e: return str(e) def main(): st.sidebar.markdown(""" """, unsafe_allow_html=True) st.sidebar.image(image="physigen.png", width=100) st.sidebar.title('Demo Links') st.sidebar.markdown("[Link-1](https://www.shaalaa.com/question-bank-solutions/a-particle-mass-100-g-kept-surface-uniform-sphere-mass-10-kg-radius-10-cm-newton-s-universal-law-of-gravitation_66992#ref=chapter&id=53499)") st.sidebar.markdown("[Link-2](https://www.shaalaa.com/question-bank-solutions/a-block-mass-2-kg-pushed-against-rough-vertical-wall-force-40-n-coefficient-static-friction-being-05-static-and-kinetic-friction_66797#ref=chapter&id=53300)") st.sidebar.markdown("[Link-3](https://www.shaalaa.com/question-bank-solutions/the-average-separation-between-proton-electron-hydrogen-atom-ground-state-53-10-11-m-a-calculate-coulomb-force-between-them-this-separation-work-done-by-a-constant-force-and-a-variable-force_66339#ref=chapter&id=52831)") st.sidebar.markdown("""