Streamlit
What is Streamlit?
import os
import streamlit as st
from openai import OpenAI
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# --- Configuration ---
NEXOS_BASE_URL = os.getenv("NEXOS_BASE_URL")
NEXOS_API_KEY = os.getenv("NEXOS_API_KEY")
if not NEXOS_BASE_URL or not NEXOS_API_KEY:
raise ValueError("Please set NEXOS_BASE_URL and NEXOS_API_KEY in your .env file")
# Configure OpenAI client once, pointing to Nexos
client = OpenAI(
api_key=NEXOS_API_KEY,
base_url=NEXOS_BASE_URL # e.g. "https://api.nexos.ai/v1"
)
st.title("Chat via Nexos.ai")
user_input = st.text_input("Ask something:")
if user_input:
try:
response = client.chat.completions.create(
model='Claude Haiku 4.5', # or any other OpenAI-compatible model ID available to you
messages=[{"role": "user", "content": user_input}]
)
st.write("Nexos Response:")
st.write(response.choices[0].message.content)
except Exception as e:
st.error(f"Error calling Nexos: {e}")Last updated

