jostlebot commited on
Commit
2170f30
·
1 Parent(s): b70fe8f

Add minimal test app for debugging

Browse files
Files changed (2) hide show
  1. README.md +3 -3
  2. src/minimal_test.py +54 -0
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: blue
5
  colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.31.1
8
- app_file: src/streamlit_app.py
9
  pinned: false
10
  license: mit
11
  ---
@@ -37,8 +37,8 @@ ANTHROPIC_API_KEY=your_api_key_here
37
 
38
  ### Testing API Key
39
  To verify your API key is working:
40
- 1. Run the test app: `streamlit run src/test_api.py`
41
- 2. If successful, you'll see "✅ API key works!"
42
  3. If there's an error, check your API key configuration
43
 
44
  ## Running the App
 
5
  colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.31.1
8
+ app_file: src/minimal_test.py
9
  pinned: false
10
  license: mit
11
  ---
 
37
 
38
  ### Testing API Key
39
  To verify your API key is working:
40
+ 1. Run the test app: `streamlit run src/minimal_test.py`
41
+ 2. If successful, you'll be able to chat with Claude
42
  3. If there's an error, check your API key configuration
43
 
44
  ## Running the App
src/minimal_test.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from anthropic import Anthropic
4
+
5
+ st.set_page_config(page_title="Claude Test", layout="wide")
6
+
7
+ st.title("Claude API Test")
8
+
9
+ # Get API key directly from environment
10
+ api_key = os.getenv('ANTHROPIC_API_KEY')
11
+
12
+ if not api_key:
13
+ st.error("No API key found. Please set ANTHROPIC_API_KEY in your environment variables.")
14
+ st.stop()
15
+
16
+ try:
17
+ # Initialize Claude client
18
+ client = Anthropic(api_key=api_key)
19
+
20
+ # Simple chat interface
21
+ if "messages" not in st.session_state:
22
+ st.session_state.messages = []
23
+
24
+ # Display chat history
25
+ for message in st.session_state.messages:
26
+ with st.chat_message(message["role"]):
27
+ st.write(message["content"])
28
+
29
+ # Chat input
30
+ if prompt := st.chat_input("Say something"):
31
+ # Display user message
32
+ with st.chat_message("user"):
33
+ st.write(prompt)
34
+
35
+ # Add user message to history
36
+ st.session_state.messages.append({"role": "user", "content": prompt})
37
+
38
+ # Get Claude's response
39
+ with st.chat_message("assistant"):
40
+ with st.spinner("Thinking..."):
41
+ response = client.messages.create(
42
+ model="claude-3-opus-20240229",
43
+ max_tokens=1000,
44
+ messages=[{"role": "user", "content": prompt}]
45
+ )
46
+ response_text = response.content[0].text
47
+ st.write(response_text)
48
+
49
+ # Add assistant response to history
50
+ st.session_state.messages.append({"role": "assistant", "content": response_text})
51
+
52
+ except Exception as e:
53
+ st.error(f"Error: {str(e)}")
54
+ st.write("Please check your API key configuration")