Skip to content

Commit

Permalink
fix: update custom tool example to use string instead of code
Browse files Browse the repository at this point in the history
  • Loading branch information
jezekra1 committed Nov 13, 2024
1 parent cb622ee commit b158e04
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/custom_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
https://github.com/i-am-bee/bee-code-interpreter/blob/main/executor/requirements.txt
"""

import inspect
import os
import warnings
from datetime import datetime
Expand All @@ -28,18 +27,20 @@ def heading(text: str) -> str:

# Define hosted function, all requirements must be available in the hosted executor environment.
# Docstring must be defined and satisfy the following format:
ip_info_code = '''
import requests
def ip_info(ip: str) -> dict:
"""
Get information about an IP address, such as location, company, and carrier name.
:param ip: IP address in the 255.255.255.255 format
:return: Information about the IP address
"""
import requests

response = requests.get(f"https://ipinfo.io/{ip}/geo")
response.raise_for_status()
return response.json()
'''


# Get existing tools using Bee API extension
Expand Down Expand Up @@ -67,7 +68,7 @@ class SourceCodeTool(openai.BaseModel):
"/tools",
cast_to=SourceCodeTool,
# You can also pass the source code directly as a string without python definition
body={"source_code": inspect.getsource(ip_info)},
body={"source_code": ip_info_code},
)
print("Tool:")
pprint(custom_tool.model_dump())
Expand Down

0 comments on commit b158e04

Please sign in to comment.