feat: add autonomous mode command-line argument
feat: improve error handling in autonomous mode feat: enhance assistant output for better user experience feat: track usage and cost in autonomous mode refactor: update api call function to accept database connection refactor: update list models function to accept database connection refactor: update assistant class to track api requests refactor: update http client to log requests maintenance: update pyproject.toml version to 1.25.0 docs: update changelog with version 1.24.0 changes
This commit is contained in:
+10
-3
@@ -7,7 +7,7 @@ from rp.core.http_client import http_client
|
||||
logger = logging.getLogger("rp")
|
||||
|
||||
|
||||
def call_api(messages, model, api_url, api_key, use_tools, tools_definition, verbose=False):
|
||||
def call_api(messages, model, api_url, api_key, use_tools, tools_definition, verbose=False, db_conn=None):
|
||||
try:
|
||||
messages = auto_slim_messages(messages, verbose=verbose)
|
||||
logger.debug(f"=== API CALL START ===")
|
||||
@@ -34,8 +34,15 @@ def call_api(messages, model, api_url, api_key, use_tools, tools_definition, ver
|
||||
logger.debug(f"Tool calling enabled with {len(tools_definition)} tools")
|
||||
request_json = data
|
||||
logger.debug(f"Request payload size: {len(request_json)} bytes")
|
||||
# Log the API request to database if db_conn is provided
|
||||
if db_conn:
|
||||
|
||||
from rp.tools.database import log_api_request
|
||||
log_result = log_api_request(model, api_url, request_json, db_conn)
|
||||
if log_result.get("status") != "success":
|
||||
logger.warning(f"Failed to log API request: {log_result.get('error')}")
|
||||
logger.debug("Sending HTTP request...")
|
||||
response = http_client.post(api_url, headers=headers, json_data=request_json)
|
||||
response = http_client.post(api_url, headers=headers, json_data=request_json, db_conn=db_conn)
|
||||
if response.get("error"):
|
||||
if "status" in response:
|
||||
logger.error(f"API HTTP Error: {response['status']} - {response.get('text', '')}")
|
||||
@@ -82,7 +89,7 @@ def list_models(model_list_url, api_key):
|
||||
headers = {}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
response = http_client.get(model_list_url, headers=headers)
|
||||
response = http_client.get(model_list_url, headers=headers, db_conn=None)
|
||||
if response.get("error"):
|
||||
return {"error": response.get("text", "HTTP error")}
|
||||
data = json.loads(response["text"])
|
||||
|
||||
Reference in New Issue
Block a user