|
12 | 12 | # limitations under the License. |
13 | 13 | # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= |
14 | 14 |
|
| 15 | +import os |
| 16 | + |
15 | 17 | from camel.agents import ChatAgent |
16 | 18 | from camel.configs import AnthropicConfig |
17 | 19 | from camel.models import ModelFactory |
18 | | -from camel.toolkits import FunctionTool |
| 20 | +from camel.toolkits import FunctionTool, TerminalToolkit |
19 | 21 | from camel.types import ModelPlatformType, ModelType |
20 | 22 |
|
21 | 23 | """ |
22 | | -Claude Sonnet 4.5 Example |
| 24 | +Claude Model Example |
23 | 25 |
|
24 | 26 | Please set the environment variable: |
25 | 27 | export ANTHROPIC_API_KEY="your-api-key-here" |
26 | 28 | """ |
27 | 29 |
|
| 30 | +# Define system message |
| 31 | +sys_msg = "You are a helpful AI assistant" |
| 32 | + |
| 33 | +# Get current script directory |
| 34 | +base_dir = os.path.dirname(os.path.abspath(__file__)) |
| 35 | +# Define workspace directory for the toolkit |
| 36 | +workspace_dir = os.path.join( |
| 37 | + os.path.dirname(os.path.dirname(base_dir)), "workspace" |
| 38 | +) |
| 39 | + |
| 40 | +# Set model config |
| 41 | +tools = [ |
| 42 | + *TerminalToolkit(working_directory=workspace_dir).get_tools(), |
| 43 | +] |
| 44 | +# Create Claude Opus 4.5 model |
| 45 | +model_opus_4_5 = ModelFactory.create( |
| 46 | + model_platform=ModelPlatformType.ANTHROPIC, |
| 47 | + model_type=ModelType.CLAUDE_OPUS_4_5, |
| 48 | + model_config_dict=AnthropicConfig(temperature=0.2).as_dict(), |
| 49 | +) |
| 50 | + |
| 51 | +user_msg = """ |
| 52 | +Create an interactive HTML webpage that allows users to play with a |
| 53 | +Rubik's Cube, and saved it to local file. |
| 54 | +""" |
| 55 | + |
| 56 | +camel_agent_pro = ChatAgent( |
| 57 | + system_message=sys_msg, model=model_opus_4_5, tools=tools |
| 58 | +) |
| 59 | +response_pro = camel_agent_pro.step(user_msg) |
| 60 | +print(response_pro.msgs[0].content) |
| 61 | +''' |
| 62 | +=============================================================================== |
| 63 | +The interactive Rubik's Cube HTML file has been created successfully! Here's |
| 64 | +what I built: |
| 65 | +
|
| 66 | +## 📁 File: `rubiks_cube.html` (23KB) |
| 67 | +
|
| 68 | +### Features: |
| 69 | +
|
| 70 | +🎮 **Interactive 3D Cube** |
| 71 | +- Fully rendered 3D Rubik's Cube using CSS transforms |
| 72 | +- Drag to rotate the view (mouse or touch) |
| 73 | +- All 6 faces visible with proper colors |
| 74 | +
|
| 75 | +🔄 **Face Rotations** |
| 76 | +- **F/B** - Front/Back face |
| 77 | +- **U/D** - Up/Down face |
| 78 | +- **L/R** - Left/Right face |
| 79 | +- **'** versions for counter-clockwise rotations |
| 80 | +
|
| 81 | +⚡ **Actions** |
| 82 | +- **Scramble** - Randomly mix the cube with 20 moves |
| 83 | +- **Reset** - Return to solved state |
| 84 | +- **Undo** - Reverse the last move |
| 85 | +
|
| 86 | +📐 **Net View** |
| 87 | +- 2D unfolded view of all cube faces for easier tracking |
| 88 | +
|
| 89 | +⌨️ **Keyboard Support** |
| 90 | +- Press F, B, R, L, U, D keys to rotate faces |
| 91 | +- Hold Shift for counter-clockwise |
| 92 | +
|
| 93 | +📱 **Responsive Design** |
| 94 | +- Works on desktop and mobile devices |
| 95 | +- Touch support for rotating the view |
| 96 | +
|
| 97 | +### To use: |
| 98 | +Simply open `rubiks_cube.html` in any modern web browser! |
| 99 | +
|
| 100 | +Process finished with exit code 0 |
| 101 | +=============================================================================== |
| 102 | +''' |
| 103 | + |
28 | 104 | # Create Claude Sonnet 4.5 model |
29 | 105 | model = ModelFactory.create( |
30 | 106 | model_platform=ModelPlatformType.ANTHROPIC, |
31 | 107 | model_type=ModelType.CLAUDE_SONNET_4_5, |
32 | 108 | model_config_dict=AnthropicConfig(temperature=0.2).as_dict(), |
33 | 109 | ) |
34 | 110 |
|
35 | | -# Define system message |
36 | | -sys_msg = "You are a helpful AI assistant powered by Claude Sonnet 4.5." |
37 | | - |
38 | 111 | # Set agent |
39 | 112 | camel_agent = ChatAgent(system_message=sys_msg, model=model) |
40 | 113 |
|
|
0 commit comments