Spaces:
Runtime error
Runtime error
Threatthriver
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,19 @@ import time
|
|
4 |
from cerebras.cloud.sdk import Cerebras
|
5 |
import markdown
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def chat_with_cerebras(user_input, system_prompt, model, temperature, top_p, max_completion_tokens):
|
11 |
"""
|
@@ -38,6 +49,7 @@ def chat_with_cerebras(user_input, system_prompt, model, temperature, top_p, max
|
|
38 |
if "Chain of Thought:" in chunk.choices[0].delta.content:
|
39 |
chain_of_thought += chunk.choices[0].delta.content.split("Chain of Thought:", 1)[-1]
|
40 |
|
|
|
41 |
# End compute time measurement
|
42 |
compute_time = time.time() - start_time
|
43 |
|
@@ -45,11 +57,11 @@ def chat_with_cerebras(user_input, system_prompt, model, temperature, top_p, max
|
|
45 |
formatted_response = response
|
46 |
if chain_of_thought:
|
47 |
formatted_response += f"\n\n**Chain of Thought:**\n{chain_of_thought}"
|
48 |
-
|
49 |
return formatted_response, chain_of_thought, f"Compute Time: {compute_time:.2f} seconds"
|
50 |
|
|
|
51 |
except Exception as e:
|
52 |
-
|
53 |
|
54 |
# Gradio interface
|
55 |
def gradio_ui():
|
@@ -67,14 +79,13 @@ def gradio_ui():
|
|
67 |
send_button = gr.Button("Send", variant="primary")
|
68 |
clear_button = gr.Button("Clear Chat")
|
69 |
|
70 |
-
|
71 |
default_system_prompt = """You are IntellijMind, an advanced AI designed to assist users with detailed insights, problem-solving, and chain-of-thought reasoning. Provide your answers in markdown format. If you do not know the answer, mention that you do not know and don't make things up. Also, remember to be concise and get straight to the point without unnecessary fluff."""
|
72 |
default_model = "llama-3.3-70b"
|
73 |
default_temperature = 0.2
|
74 |
default_top_p = 1
|
75 |
default_max_tokens = 1024
|
76 |
|
77 |
-
|
78 |
def handle_chat(chat_history, user_input):
|
79 |
chat_history.append((user_input, None))
|
80 |
yield chat_history, "", "Thinking..."
|
@@ -100,6 +111,7 @@ def gradio_ui():
|
|
100 |
|
101 |
return demo
|
102 |
|
|
|
103 |
# Run the Gradio app
|
104 |
demo = gradio_ui()
|
105 |
demo.launch()
|
|
|
4 |
from cerebras.cloud.sdk import Cerebras
|
5 |
import markdown
|
6 |
|
7 |
+
# Function to establish Cerebras client connection
|
8 |
+
def get_cerebras_client():
|
9 |
+
try:
|
10 |
+
client = Cerebras(api_key=os.environ.get("CEREBRAS_API_KEY"))
|
11 |
+
return client, None
|
12 |
+
except Exception as e:
|
13 |
+
return None, f"Error connecting to Cerebras: {e}. Please check your API key and ensure network connectivity."
|
14 |
+
|
15 |
+
# Cerebras client setup
|
16 |
+
client, connection_error = get_cerebras_client()
|
17 |
+
if connection_error:
|
18 |
+
print(connection_error)
|
19 |
+
exit() # Exit if the connection failed
|
20 |
|
21 |
def chat_with_cerebras(user_input, system_prompt, model, temperature, top_p, max_completion_tokens):
|
22 |
"""
|
|
|
49 |
if "Chain of Thought:" in chunk.choices[0].delta.content:
|
50 |
chain_of_thought += chunk.choices[0].delta.content.split("Chain of Thought:", 1)[-1]
|
51 |
|
52 |
+
|
53 |
# End compute time measurement
|
54 |
compute_time = time.time() - start_time
|
55 |
|
|
|
57 |
formatted_response = response
|
58 |
if chain_of_thought:
|
59 |
formatted_response += f"\n\n**Chain of Thought:**\n{chain_of_thought}"
|
|
|
60 |
return formatted_response, chain_of_thought, f"Compute Time: {compute_time:.2f} seconds"
|
61 |
|
62 |
+
|
63 |
except Exception as e:
|
64 |
+
return f"Error: {str(e)}", "", "An error occurred while processing your request. Please check the Cerebras service and your input."
|
65 |
|
66 |
# Gradio interface
|
67 |
def gradio_ui():
|
|
|
79 |
send_button = gr.Button("Send", variant="primary")
|
80 |
clear_button = gr.Button("Clear Chat")
|
81 |
|
82 |
+
# Set default values for system prompt, model, etc.
|
83 |
default_system_prompt = """You are IntellijMind, an advanced AI designed to assist users with detailed insights, problem-solving, and chain-of-thought reasoning. Provide your answers in markdown format. If you do not know the answer, mention that you do not know and don't make things up. Also, remember to be concise and get straight to the point without unnecessary fluff."""
|
84 |
default_model = "llama-3.3-70b"
|
85 |
default_temperature = 0.2
|
86 |
default_top_p = 1
|
87 |
default_max_tokens = 1024
|
88 |
|
|
|
89 |
def handle_chat(chat_history, user_input):
|
90 |
chat_history.append((user_input, None))
|
91 |
yield chat_history, "", "Thinking..."
|
|
|
111 |
|
112 |
return demo
|
113 |
|
114 |
+
|
115 |
# Run the Gradio app
|
116 |
demo = gradio_ui()
|
117 |
demo.launch()
|