Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxukun2000 committed Nov 17, 2024
1 parent 6a94219 commit 75c29de
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
19 changes: 13 additions & 6 deletions camel/toolkits/search_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def search_wiki(self, entity: str) -> str:
try:
result = wikipedia.summary(entity, sentences=5, auto_suggest=False)
except wikipedia.exceptions.DisambiguationError as e:
result = wikipedia.summary(e.options[0], sentences=5, auto_suggest=False)
result = wikipedia.summary(
e.options[0], sentences=5, auto_suggest=False
)
except wikipedia.exceptions.PageError:
result = (
"There is no page in Wikipedia corresponding to entity "
Expand Down Expand Up @@ -217,10 +219,13 @@ def search_google(

# Iterate over 10 results found
for i, search_item in enumerate(search_items, start=1):
if "og:description" in search_item["pagemap"]["metatags"][0]:
long_description = search_item["pagemap"]["metatags"][0][
"og:description"
]
if (
"og:description"
in search_item["pagemap"]["metatags"][0]
):
long_description = search_item["pagemap"]["metatags"][
0
]["og:description"]
else:
long_description = "N/A"
# Get the page title
Expand Down Expand Up @@ -349,7 +354,9 @@ def _parse_wolfram_result(self, result) -> Dict[str, Any]:

return output

def _get_wolframalpha_step_by_step_solution(self, app_id: str, query: str) -> dict:
def _get_wolframalpha_step_by_step_solution(
self, app_id: str, query: str
) -> dict:
r"""Retrieve a step-by-step solution from the Wolfram Alpha API for a
given query.
Expand Down
2 changes: 1 addition & 1 deletion examples/runtime/docker_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.runtime import DockerRuntime
from camel.toolkits import MathToolkit, CodeExecutionToolkit
from camel.toolkits import CodeExecutionToolkit, MathToolkit

if __name__ == "__main__":
runtime = (
Expand Down
7 changes: 3 additions & 4 deletions test/runtime/test_code_execution_with_llm_guard_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest
from colorama import Fore

from camel.agents import ChatAgent
from camel.configs import ChatGPTConfig
Expand All @@ -21,7 +19,7 @@
from camel.runtime import LLMGuardRuntime
from camel.toolkits.code_execution import CodeExecutionToolkit
from camel.types import ModelPlatformType, ModelType
from camel.utils import print_text_animated


def test_code_execution_with_llm_guard_runtime():
runtime = LLMGuardRuntime(verbose=True).add(
Expand Down Expand Up @@ -67,7 +65,8 @@ def test_code_execution_with_llm_guard_runtime():

prompt = (
"Weng earns $12 an hour for babysitting. "
"Yesterday, she just did 51 minutes of babysitting. How much did she earn?"
"Yesterday, she just did 51 minutes of babysitting."
"How much did she earn?"
)
user_msg = BaseMessage.make_user_message(role_name="User", content=prompt)

Expand Down
10 changes: 5 additions & 5 deletions test/runtime/test_docker_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest

from camel.runtime import DockerRuntime
from camel.toolkits import MathToolkit, CodeExecutionToolkit
from camel.toolkits import CodeExecutionToolkit, MathToolkit


@pytest.mark.skip(reason="Need Docker environment to run this test.")
Expand All @@ -28,7 +29,9 @@ def test_docker_runtime():
)
)

with runtime as r: # using with statement to automatically close the runtime
with (
runtime as r
): # using with statement to automatically close the runtime
print("Waiting for runtime to be ready...")
r.wait()
print("Runtime is ready.")
Expand All @@ -48,6 +51,3 @@ def test_docker_runtime():
assert mul.func(a=2, b=3) == 6

assert r.docs == "http://localhost:8000/docs"



3 changes: 1 addition & 2 deletions test/runtime/test_remote_http_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import pytest
from camel.runtime import RemoteHttpRuntime
from camel.toolkits import MathToolkit


def test_remote_http_runtime():
runtime = (
RemoteHttpRuntime("localhost")
Expand All @@ -31,4 +31,3 @@ def test_remote_http_runtime():
assert mul.func(2, 3) == 6

assert runtime.docs == "http://localhost:8000/docs"

0 comments on commit 75c29de

Please sign in to comment.