Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
src/opensymbiose/gradio/app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import logging
|
|
|
2 |
import time
|
3 |
from dataclasses import asdict
|
4 |
|
@@ -18,6 +19,10 @@ logger = logging.getLogger(__name__)
|
|
18 |
client = Mistral(api_key=opensymbiose.config.MISTRAL_API_KEY)
|
19 |
model = "mistral-medium-latest"
|
20 |
|
|
|
|
|
|
|
|
|
21 |
def get_mistral_answer(message: str, history = None):
|
22 |
# Start global execution timer
|
23 |
global_start_time = time.time()
|
@@ -39,15 +44,24 @@ def get_mistral_answer(message: str, history = None):
|
|
39 |
for chunk in stream_response:
|
40 |
logger.info(f"Chunk: {chunk}")
|
41 |
if chunk.event == "message.output.delta":
|
42 |
-
if isinstance(chunk.data.content,
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
full_response += chunk.data.content
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
full_response += f"([{chunk.data.content.title}]({chunk.data.content.url})) "
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
messages.append(asdict(ChatMessage(role="assistant", content=full_response)))
|
51 |
yield messages
|
52 |
elif chunk.event == "tool.execution.started":
|
53 |
# Start timer for this tool
|
@@ -115,6 +129,7 @@ def get_mistral_answer(message: str, history = None):
|
|
115 |
# Add a new message for conversation response error
|
116 |
error_message = f"Error: {chunk.data.message} (Code: {chunk.data.code})"
|
117 |
logger.error(f"Conversation response error: {error_message}")
|
|
|
118 |
messages.append(asdict(ChatMessage(role="assistant", content="",
|
119 |
metadata={"title": f"❌ {error_message}"})))
|
120 |
yield messages
|
@@ -132,8 +147,8 @@ with gr.Blocks() as demo:
|
|
132 |
description="OpenSymbiose is an open-source biotechnology / biology research AI agent designed to support researcher",
|
133 |
examples=["search internet: CEO of google", "Use your calculator agent to do 1273*3/12^2"],
|
134 |
save_history=True,
|
135 |
-
flagging_mode="manual"
|
136 |
-
|
137 |
)
|
138 |
|
139 |
if __name__ == "__main__":
|
|
|
1 |
import logging
|
2 |
+
import sys
|
3 |
import time
|
4 |
from dataclasses import asdict
|
5 |
|
|
|
19 |
client = Mistral(api_key=opensymbiose.config.MISTRAL_API_KEY)
|
20 |
model = "mistral-medium-latest"
|
21 |
|
22 |
+
# Log Version Information
|
23 |
+
logger.info(f"Gradio version: {gr.__version__}")
|
24 |
+
logger.info(f"Python version: {sys.version}")
|
25 |
+
|
26 |
def get_mistral_answer(message: str, history = None):
|
27 |
# Start global execution timer
|
28 |
global_start_time = time.time()
|
|
|
44 |
for chunk in stream_response:
|
45 |
logger.info(f"Chunk: {chunk}")
|
46 |
if chunk.event == "message.output.delta":
|
47 |
+
if isinstance(chunk.data.content, dict) and "filepath" in chunk.data.content:
|
48 |
+
# Handle file messages with proper alt_text
|
49 |
+
file_path = chunk.data.content["filepath"]
|
50 |
+
alt_text = chunk.data.content.get("alt_text", "File attachment") # Default alt_text if not provided
|
51 |
+
messages.append(asdict(ChatMessage(role="assistant", content=file_path,
|
52 |
+
metadata={"type": "file", "alt_text": alt_text})))
|
53 |
+
elif isinstance(chunk.data.content, str):
|
54 |
full_response += chunk.data.content
|
55 |
+
if messages and messages[-1].get("role") == "assistant" and not messages[-1].get("metadata"):
|
56 |
+
messages[-1] = asdict(ChatMessage(role="assistant", content=full_response))
|
57 |
+
else:
|
58 |
+
messages.append(asdict(ChatMessage(role="assistant", content=full_response)))
|
59 |
+
elif isinstance(chunk.data.content, ToolReferenceChunk):
|
60 |
full_response += f"([{chunk.data.content.title}]({chunk.data.content.url})) "
|
61 |
+
if messages and messages[-1].get("role") == "assistant" and not messages[-1].get("metadata"):
|
62 |
+
messages[-1] = asdict(ChatMessage(role="assistant", content=full_response))
|
63 |
+
else:
|
64 |
+
messages.append(asdict(ChatMessage(role="assistant", content=full_response)))
|
|
|
65 |
yield messages
|
66 |
elif chunk.event == "tool.execution.started":
|
67 |
# Start timer for this tool
|
|
|
129 |
# Add a new message for conversation response error
|
130 |
error_message = f"Error: {chunk.data.message} (Code: {chunk.data.code})"
|
131 |
logger.error(f"Conversation response error: {error_message}")
|
132 |
+
logger.error(f"Chunk: {chunk}")
|
133 |
messages.append(asdict(ChatMessage(role="assistant", content="",
|
134 |
metadata={"title": f"❌ {error_message}"})))
|
135 |
yield messages
|
|
|
147 |
description="OpenSymbiose is an open-source biotechnology / biology research AI agent designed to support researcher",
|
148 |
examples=["search internet: CEO of google", "Use your calculator agent to do 1273*3/12^2"],
|
149 |
save_history=True,
|
150 |
+
flagging_mode="manual",
|
151 |
+
cache_examples=False # Disable caching for examples to prevent startup validation errors
|
152 |
)
|
153 |
|
154 |
if __name__ == "__main__":
|