File size: 1,660 Bytes
378f180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import os

# Add this at the top of your app.py
st.set_page_config(page_title="Multi-Agent Code Assistant", page_icon="πŸ€–")

# API Key Setup
if 'api_key' not in st.session_state:
    st.session_state.api_key = None

# Sidebar for API key
with st.sidebar:
    st.header("πŸ”‘ API Configuration")
    
    # Option 1: Use environment variable
    env_key = os.getenv("OPENAI_API_KEY")
    
    if env_key:
        st.session_state.api_key = env_key
        st.success("βœ… API key loaded from environment")
    else:
        # Option 2: User input
        user_key = st.text_input(
            "Enter OpenAI API Key:",
            type="password",
            help="Get your key from https://platform.openai.com/api-keys"
        )
        
        if user_key:
            st.session_state.api_key = user_key
            st.success("βœ… API key set!")
        
        st.markdown("""
        ### How to get an API key:
        1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)
        2. Click "Create new secret key"
        3. Copy and paste it here
        4. Your key is stored only in your browser session
        """)
    
    # Cost warning
    st.warning("""
    ⚠️ **Cost Warning:**
    - You're using YOUR OpenAI credits
    - GPT-3.5-turbo: ~$0.0015 per 1K tokens
    - Approx. 100 requests = $0.15
    """)

# Check if API key is available
if not st.session_state.api_key:
    st.error("πŸ” Please enter your OpenAI API key in the sidebar to continue.")
    st.stop()

# Now initialize your agents with the API key
import openai
openai.api_key = st.session_state.api_key

# Rest of your app continues...