|
| 1 | +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= |
| 14 | + |
| 15 | +from camel.agents import ChatAgent |
| 16 | +from camel.configs import AnthropicConfig |
| 17 | +from camel.models import ModelFactory |
| 18 | +from camel.types import ModelPlatformType, ModelType |
| 19 | + |
| 20 | +""" |
| 21 | +please set the below os environment: |
| 22 | +export ANTHROPIC_API_KEY="" |
| 23 | +""" |
| 24 | + |
| 25 | +model = ModelFactory.create( |
| 26 | + model_platform=ModelPlatformType.ANTHROPIC, |
| 27 | + model_type=ModelType.CLAUDE_3_5_SONNET, |
| 28 | + model_config_dict=AnthropicConfig(temperature=0.2).as_dict(), |
| 29 | +) |
| 30 | + |
| 31 | +# Define system message |
| 32 | +sys_msg = "You are a helpful assistant." |
| 33 | + |
| 34 | +# Set agent |
| 35 | +camel_agent = ChatAgent(system_message=sys_msg, model=model) |
| 36 | + |
| 37 | +user_msg = """Say hi to CAMEL AI, one open-source community dedicated to the |
| 38 | + study of autonomous and communicative agents.""" |
| 39 | + |
| 40 | +# Get response information |
| 41 | +response = camel_agent.step(user_msg) |
| 42 | +print(response.msgs[0].content) |
| 43 | +''' |
| 44 | +=============================================================================== |
| 45 | +Hi CAMEL AI! It's great to meet an open-source community focused on advancing research in autonomous and communicative agents. Your work on developing and studying AI systems that can effectively communicate and operate autonomously is fascinating and important for the field. I appreciate communities like yours that contribute to open research and development in AI. Wishing you continued success in your mission! |
| 46 | +=============================================================================== |
| 47 | +''' # noqa: E501 |
| 48 | + |
| 49 | +# Use the extended thinking model with Claude 3.7 Sonnet |
| 50 | +config = AnthropicConfig( |
| 51 | + thinking={"type": "enabled", "budget_tokens": 2048} |
| 52 | +).as_dict() |
| 53 | + |
| 54 | +model = ModelFactory.create( |
| 55 | + model_platform=ModelPlatformType.ANTHROPIC, |
| 56 | + model_type=ModelType.CLAUDE_3_7_SONNET, |
| 57 | + model_config_dict=config, |
| 58 | +) |
| 59 | + |
| 60 | +camel_agent = ChatAgent(model=model) |
| 61 | + |
| 62 | +user_msg = """Write a bash script that takes a matrix represented as a string with |
| 63 | +format '[1,2],[3,4],[5,6]' and prints the transpose in the same format. |
| 64 | +""" # noqa: E501 |
| 65 | + |
| 66 | +response = camel_agent.step(user_msg) |
| 67 | +print(response.msgs[0].content) |
| 68 | +''' |
| 69 | +=============================================================================== |
| 70 | +# Matrix Transpose Bash Script |
| 71 | +
|
| 72 | +Here's a bash script that transposes a matrix from the format `[1,2],[3,4],[5,6]` to `[1,3,5],[2,4,6]`: |
| 73 | +
|
| 74 | +```bash |
| 75 | +#!/bin/bash |
| 76 | +
|
| 77 | +# Check if input argument is provided |
| 78 | +if [ $# -lt 1 ]; then |
| 79 | + echo "Usage: $0 '[row1],[row2],...'" |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | +
|
| 83 | +# Input matrix as string |
| 84 | +input="$1" |
| 85 | +
|
| 86 | +# Remove outer brackets and split into rows |
| 87 | +input="${input//\]\,\[/]|[}" # Replace "],[" with "]|[" |
| 88 | +input="${input#\[}" # Remove leading "[" |
| 89 | +input="${input%\]}" # Remove trailing "]" |
| 90 | +IFS='|' read -ra rows <<< "$input" |
| 91 | +
|
| 92 | +# Determine dimensions of the matrix |
| 93 | +row_count="${#rows[@]}" |
| 94 | +IFS=',' read -ra first_row <<< "${rows[0]//[\[\]]}" # Remove brackets from first row |
| 95 | +col_count="${#first_row[@]}" |
| 96 | +
|
| 97 | +# Create transpose |
| 98 | +result="" |
| 99 | +for (( col=0; col<col_count; col++ )); do |
| 100 | + result+="[" |
| 101 | + for (( row=0; row<row_count; row++ )); do |
| 102 | + # Extract current row without brackets |
| 103 | + current="${rows[row]//[\[\]]}" |
| 104 | + # Split by commas |
| 105 | + IFS=',' read -ra elements <<< "$current" |
| 106 | + # Add element to transpose |
| 107 | + result+="${elements[col]}" |
| 108 | + # Add comma if not the last element |
| 109 | + if (( row < row_count-1 )); then |
| 110 | + result+="," |
| 111 | + fi |
| 112 | + done |
| 113 | + result+="]" |
| 114 | + # Add comma if not the last row |
| 115 | + if (( col < col_count-1 )); then |
| 116 | + result+="," |
| 117 | + fi |
| 118 | +done |
| 119 | +
|
| 120 | +echo "$result" |
| 121 | +``` |
| 122 | +
|
| 123 | +## How to Use: |
| 124 | +
|
| 125 | +1. Save the script to a file (e.g., `transpose.sh`) |
| 126 | +2. Make it executable: `chmod +x transpose.sh` |
| 127 | +3. Run it with your matrix: `./transpose.sh "[1,2],[3,4],[5,6]"` |
| 128 | +
|
| 129 | +## Example: |
| 130 | +- Input: `[1,2],[3,4],[5,6]` |
| 131 | +- Output: `[1,3,5],[2,4,6]` |
| 132 | +
|
| 133 | +The script works by: |
| 134 | +1. Parsing the input string to extract rows and elements |
| 135 | +2. Finding the dimensions of the original matrix |
| 136 | +3. Creating the transpose by iterating through columns first, then rows |
| 137 | +4. Formatting the result with proper brackets and commas |
| 138 | +''' # noqa: E501 |
0 commit comments