mirror of https://github.com/kortix-ai/suna.git
wip
This commit is contained in:
parent
7486571486
commit
30854527cd
|
@ -1,39 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Modern Landing Page</title>
|
||||
<link rel="stylesheet" href="reset.css">
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="header container">
|
||||
<div class="header-logo">YourBrand</div>
|
||||
<nav>
|
||||
<ul class="nav-links">
|
||||
<li><a href="#">Home</a></li>
|
||||
<li><a href="#">Features</a></li>
|
||||
<li><a href="#">About</a></li>
|
||||
<li><a href="#">Contact</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="hero">
|
||||
<div class="container hero-content">
|
||||
<h1 class="hero-title">Transform Your Digital Experience</h1>
|
||||
<p class="hero-subtitle">Innovative solutions for modern challenges. Simplify, streamline, and succeed.</p>
|
||||
<a href="#" class="cta-button">Get Started</a>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container footer-content">
|
||||
<p>© 2023 YourBrand. All rights reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -1 +0,0 @@
|
|||
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{line-height:1.6;font-family:'-apple-system','BlinkMacSystemFont','Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Open Sans','Helvetica Neue',sans-serif}img{max-width:100%;height:auto}a{text-decoration:none;color:inherit}
|
|
@ -1 +0,0 @@
|
|||
:root{--primary-color:#3498db;--secondary-color:#2ecc71;--text-color:#333;--background-color:#f4f4f4}body{font-family:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Open Sans','Helvetica Neue',sans-serif;color:var(--text-color);background-color:var(--background-color)}.container{max-width:1200px;margin:0 auto;padding:0 15px}.header{display:flex;justify-content:space-between;align-items:center;padding:20px 0;background-color:white;box-shadow:0 2px 4px rgba(0,0,0,0.1)}.header-logo{font-size:24px;font-weight:bold;color:var(--primary-color)}.nav-links{display:flex;list-style:none;gap:20px}.nav-links a{color:var(--text-color);transition:color 0.3s ease}.nav-links a:hover{color:var(--primary-color)}.hero{display:flex;align-items:center;min-height:70vh;background:linear-gradient(135deg,var(--primary-color),var(--secondary-color));color:white;text-align:center}.hero-content{max-width:800px;margin:0 auto;padding:40px 20px}.hero-title{font-size:48px;margin-bottom:20px;font-weight:bold}.hero-subtitle{font-size:24px;margin-bottom:30px;opacity:0.9}.cta-button{display:inline-block;background-color:white;color:var(--primary-color);padding:12px 30px;border-radius:5px;font-weight:bold;transition:transform 0.3s ease}.cta-button:hover{transform:scale(1.05)}.footer{background-color:#333;color:white;text-align:center;padding:20px;margin-top:40px}.footer-content{max-width:800px;margin:0 auto}@media screen and (max-width:768px){.header{flex-direction:column;text-align:center}.nav-links{margin-top:15px}.hero{text-align:center}.hero-title{font-size:36px}.hero-subtitle{font-size:20px}}
|
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
from typing import Dict, Any, AsyncGenerator, Callable
|
||||
import json
|
||||
from agentpress.tool_executor import ToolExecutor
|
||||
from agentpress.tool_parser import ToolParser
|
||||
|
||||
|
@ -50,7 +50,7 @@ class LLMResponseProcessor:
|
|||
self,
|
||||
response_stream: AsyncGenerator,
|
||||
execute_tools: bool = True,
|
||||
immediate_execution: bool = True # Renamed from execute_tools_immediately
|
||||
immediate_execution: bool = True
|
||||
) -> AsyncGenerator:
|
||||
"""
|
||||
Process streaming LLM response and handle tool execution.
|
||||
|
|
|
@ -350,73 +350,95 @@ if __name__ == "__main__":
|
|||
from agentpress.examples.example_agent.tools.files_tool import FilesTool
|
||||
|
||||
async def main():
|
||||
manager = ThreadManager()
|
||||
manager.add_tool(FilesTool, ['create_file'])
|
||||
thread_id = await manager.create_thread()
|
||||
# Initialize managers
|
||||
thread_manager = ThreadManager()
|
||||
|
||||
# Register available tools
|
||||
thread_manager.add_tool(FilesTool)
|
||||
|
||||
# Create a new thread
|
||||
thread_id = await thread_manager.create_thread()
|
||||
|
||||
# Add a test message
|
||||
await manager.add_message(thread_id, {
|
||||
await thread_manager.add_message(thread_id, {
|
||||
"role": "user",
|
||||
"content": "Please create 10x files – Each should be a chapter of a book about an Introduction to Robotics.."
|
||||
})
|
||||
|
||||
# Define system message
|
||||
system_message = {
|
||||
"role": "system",
|
||||
"content": "You are a helpful assistant that can create, read, update, and delete files."
|
||||
}
|
||||
model_name = "anthropic/claude-3-5-haiku-latest"
|
||||
# model_name = "gpt-4o-mini"
|
||||
|
||||
# Test with tools (non-streaming)
|
||||
print("\n🤖 Testing non-streaming response with tools:")
|
||||
response = await manager.run_thread(
|
||||
|
||||
# Test with streaming response and tool execution
|
||||
print("\n🤖 Testing streaming response with tools:")
|
||||
response = await thread_manager.run_thread(
|
||||
thread_id=thread_id,
|
||||
system_message=system_message,
|
||||
model_name=model_name,
|
||||
model_name="anthropic/claude-3-5-haiku-latest",
|
||||
temperature=0.7,
|
||||
stream=False,
|
||||
max_tokens=4096,
|
||||
stream=True,
|
||||
use_tools=True,
|
||||
execute_tool_calls=True
|
||||
execute_tools=True,
|
||||
immediate_tool_execution=True,
|
||||
parallel_tool_execution=False
|
||||
)
|
||||
|
||||
# Print the non-streaming response
|
||||
if "error" in response:
|
||||
print(f"Error: {response['message']}")
|
||||
|
||||
# Handle streaming response
|
||||
if isinstance(response, AsyncGenerator):
|
||||
print("\nAssistant is responding:")
|
||||
content_buffer = ""
|
||||
try:
|
||||
async for chunk in response:
|
||||
if hasattr(chunk.choices[0], 'delta'):
|
||||
delta = chunk.choices[0].delta
|
||||
|
||||
# Handle content streaming
|
||||
if hasattr(delta, 'content') and delta.content is not None:
|
||||
content_buffer += delta.content
|
||||
if delta.content.endswith((' ', '\n')):
|
||||
print(content_buffer, end='', flush=True)
|
||||
content_buffer = ""
|
||||
|
||||
# Handle tool calls
|
||||
if hasattr(delta, 'tool_calls') and delta.tool_calls:
|
||||
for tool_call in delta.tool_calls:
|
||||
# Print tool name when it first appears
|
||||
if tool_call.function and tool_call.function.name:
|
||||
print(f"\n🛠️ Tool Call: {tool_call.function.name}", flush=True)
|
||||
|
||||
# Print arguments as they stream in
|
||||
if tool_call.function and tool_call.function.arguments:
|
||||
print(f" {tool_call.function.arguments}", end='', flush=True)
|
||||
|
||||
# Print any remaining content
|
||||
if content_buffer:
|
||||
print(content_buffer, flush=True)
|
||||
print("\n✨ Response completed\n")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Error processing stream: {e}")
|
||||
else:
|
||||
print(response["llm_response"].choices[0].message.content)
|
||||
print("\n✨ Response completed.\n")
|
||||
# Handle non-streaming response
|
||||
print("\nAssistant response:")
|
||||
if hasattr(response.choices[0], 'message'):
|
||||
message = response.choices[0].message
|
||||
if message.content:
|
||||
print(message.content)
|
||||
if hasattr(message, 'tool_calls') and message.tool_calls:
|
||||
for tool_call in message.tool_calls:
|
||||
print(f"\n🛠️ Tool Call: {tool_call.function.name}")
|
||||
print(f" Arguments: {tool_call.function.arguments}")
|
||||
print("\n✨ Response completed\n")
|
||||
|
||||
# Test streaming
|
||||
print("\n🤖 Testing streaming response:")
|
||||
stream_response = await manager.run_thread(
|
||||
thread_id=thread_id,
|
||||
system_message=system_message,
|
||||
model_name=model_name,
|
||||
temperature=0.7,
|
||||
stream=True,
|
||||
use_tools=True,
|
||||
execute_tool_calls=True,
|
||||
execute_tools_on_stream=True
|
||||
)
|
||||
|
||||
buffer = ""
|
||||
async for chunk in stream_response:
|
||||
if isinstance(chunk, dict) and 'choices' in chunk:
|
||||
content = chunk['choices'][0]['delta'].get('content', '')
|
||||
else:
|
||||
# For non-dict responses (like ModelResponse objects)
|
||||
content = chunk.choices[0].delta.content
|
||||
|
||||
if content:
|
||||
buffer += content
|
||||
# Print complete words/sentences when we hit whitespace
|
||||
if content[-1].isspace():
|
||||
print(buffer, end='', flush=True)
|
||||
buffer = ""
|
||||
|
||||
# Print any remaining content
|
||||
if buffer:
|
||||
print(buffer, flush=True)
|
||||
print("\n✨ Stream completed.\n")
|
||||
# Display final thread state
|
||||
messages = await thread_manager.list_messages(thread_id)
|
||||
print("\n📝 Final Thread State:")
|
||||
for msg in messages:
|
||||
role = msg.get('role', 'unknown')
|
||||
content = msg.get('content', '')
|
||||
print(f"\n{role.upper()}: {content[:100]}...")
|
||||
|
||||
asyncio.run(main())
|
||||
|
|
12
state.json
12
state.json
|
@ -1,13 +1,3 @@
|
|||
{
|
||||
"files": {
|
||||
"index.html": {
|
||||
"content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <title>Modern Landing Page</title>\n <link rel=\"stylesheet\" href=\"reset.css\">\n <link rel=\"stylesheet\" href=\"styles.css\">\n</head>\n<body>\n <header class=\"header container\">\n <div class=\"header-logo\">YourBrand</div>\n <nav>\n <ul class=\"nav-links\">\n <li><a href=\"#\">Home</a></li>\n <li><a href=\"#\">Features</a></li>\n <li><a href=\"#\">About</a></li>\n <li><a href=\"#\">Contact</a></li>\n </ul>\n </nav>\n </header>\n\n <main>\n <section class=\"hero\">\n <div class=\"container hero-content\">\n <h1 class=\"hero-title\">Transform Your Digital Experience</h1>\n <p class=\"hero-subtitle\">Innovative solutions for modern challenges. Simplify, streamline, and succeed.</p>\n <a href=\"#\" class=\"cta-button\">Get Started</a>\n </div>\n </section>\n </main>\n\n <footer class=\"footer\">\n <div class=\"container footer-content\">\n <p>© 2023 YourBrand. All rights reserved.</p>\n </div>\n </footer>\n</body>\n</html>"
|
||||
},
|
||||
"reset.css": {
|
||||
"content": "*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{line-height:1.6;font-family:'-apple-system','BlinkMacSystemFont','Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Open Sans','Helvetica Neue',sans-serif}img{max-width:100%;height:auto}a{text-decoration:none;color:inherit}"
|
||||
},
|
||||
"styles.css": {
|
||||
"content": ":root{--primary-color:#3498db;--secondary-color:#2ecc71;--text-color:#333;--background-color:#f4f4f4}body{font-family:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Open Sans','Helvetica Neue',sans-serif;color:var(--text-color);background-color:var(--background-color)}.container{max-width:1200px;margin:0 auto;padding:0 15px}.header{display:flex;justify-content:space-between;align-items:center;padding:20px 0;background-color:white;box-shadow:0 2px 4px rgba(0,0,0,0.1)}.header-logo{font-size:24px;font-weight:bold;color:var(--primary-color)}.nav-links{display:flex;list-style:none;gap:20px}.nav-links a{color:var(--text-color);transition:color 0.3s ease}.nav-links a:hover{color:var(--primary-color)}.hero{display:flex;align-items:center;min-height:70vh;background:linear-gradient(135deg,var(--primary-color),var(--secondary-color));color:white;text-align:center}.hero-content{max-width:800px;margin:0 auto;padding:40px 20px}.hero-title{font-size:48px;margin-bottom:20px;font-weight:bold}.hero-subtitle{font-size:24px;margin-bottom:30px;opacity:0.9}.cta-button{display:inline-block;background-color:white;color:var(--primary-color);padding:12px 30px;border-radius:5px;font-weight:bold;transition:transform 0.3s ease}.cta-button:hover{transform:scale(1.05)}.footer{background-color:#333;color:white;text-align:center;padding:20px;margin-top:40px}.footer-content{max-width:800px;margin:0 auto}@media screen and (max-width:768px){.header{flex-direction:column;text-align:center}.nav-links{margin-top:15px}.hero{text-align:center}.hero-title{font-size:36px}.hero-subtitle{font-size:20px}}"
|
||||
}
|
||||
}
|
||||
"files": {}
|
||||
}
|
Loading…
Reference in New Issue