mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 18:13:03 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
import requests
|
|
from docsgpt.agents.tools.base import Tool
|
|
|
|
|
|
class CryptoPriceTool(Tool):
|
|
"""
|
|
CryptoPrice
|
|
A tool for retrieving cryptocurrency prices using the CryptoCompare public API
|
|
"""
|
|
|
|
def __init__(self, config):
|
|
self.config = config
|
|
|
|
def execute_action(self, action_name, **kwargs):
|
|
actions = {"cryptoprice_get": self._get_price}
|
|
|
|
if action_name in actions:
|
|
return actions[action_name](**kwargs)
|
|
else:
|
|
raise ValueError(f"Unknown action: {action_name}")
|
|
|
|
def _get_price(self, symbol, currency):
|
|
"""
|
|
Fetches the current price of a given cryptocurrency symbol in the specified currency.
|
|
Example:
|
|
symbol = "BTC"
|
|
currency = "USD"
|
|
returns price in USD.
|
|
"""
|
|
url = f"https://min-api.cryptocompare.com/data/price?fsym={symbol.upper()}&tsyms={currency.upper()}"
|
|
response = requests.get(url, timeout=100)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if currency.upper() in data:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"price": data[currency.upper()],
|
|
"message": f"Price of {symbol.upper()} in {currency.upper()} retrieved successfully.",
|
|
}
|
|
else:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"message": f"Couldn't find price for {symbol.upper()} in {currency.upper()}.",
|
|
}
|
|
else:
|
|
return {
|
|
"status_code": response.status_code,
|
|
"message": "Failed to retrieve price.",
|
|
}
|
|
|
|
def get_actions_metadata(self):
|
|
return [
|
|
{
|
|
"name": "cryptoprice_get",
|
|
"description": (
|
|
"Get the current price of a cryptocurrency from the public "
|
|
"CryptoCompare API. Use ticker symbols, e.g. symbol='BTC', "
|
|
"currency='USD'."
|
|
),
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"symbol": {
|
|
"type": "string",
|
|
"description": "The cryptocurrency symbol (e.g. BTC)",
|
|
},
|
|
"currency": {
|
|
"type": "string",
|
|
"description": "The currency in which you want the price (e.g. USD)",
|
|
},
|
|
},
|
|
"required": ["symbol", "currency"],
|
|
"additionalProperties": False,
|
|
},
|
|
}
|
|
]
|
|
|
|
def get_config_requirements(self):
|
|
# No specific configuration needed for this tool as it just queries a public endpoint
|
|
return {}
|