Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

[HN-504] feat: add suggested prompts endpoint #27

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hive_agent_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from hive_agent_client.files import upload_files, list_files, delete_file, rename_file
from hive_agent_client.tools import install_tools
from hive_agent_client.prompts import sample_prompts

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -255,6 +256,18 @@ async def install_tools(self, tools: List[Dict[str, Any]]) -> Dict:
logger.error(f"Failed to install tools: {e}")
raise Exception(f"Failed to install tools: {e}")

async def sample_prompts(self) -> Dict:
"""
List all sample prompts configured for the agent.

:return: A dictionary with a list of the suggested prompts.
"""
try:
return await sample_prompts(self.http_client, self.base_url)
except Exception as e:
logger.error(f"Failed to list the suggested prompts: {e}")
raise Exception(f"Failed to list the suggested prompts: {e}")

async def close(self):
"""
Close the HTTP client session.
Expand Down
1 change: 1 addition & 0 deletions hive_agent_client/prompts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .sample_prompts import sample_prompts
39 changes: 39 additions & 0 deletions hive_agent_client/prompts/sample_prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import httpx
import logging
import os
import sys


def get_log_level():
HIVE_AGENT_LOG_LEVEL = os.getenv("HIVE_AGENT_LOG_LEVEL", "INFO").upper()
return getattr(logging, HIVE_AGENT_LOG_LEVEL, logging.INFO)


logging.basicConfig(stream=sys.stdout, level=get_log_level())
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

logger = logging.getLogger()
logger.setLevel(get_log_level())


async def sample_prompts(http_client: httpx.AsyncClient, base_url: str) -> dict:
"""
Lists all sample prompts for the agent

:param http_client: An HTTP client for sending requests.
:param base_url: The base URL of the Hive Agent API.
:return: A dictionary containing the list of all the suggested prompts for starting an interaction with the agent.
:raises Exception: If the HTTP request fails or the API returns an error response.
"""
endpoint = "/sample_prompts/"
url = f"{base_url}{endpoint}"

try:
logger.debug(f"Listing sample prompts at {url}")
response = await http_client.get(url)
response.raise_for_status()
logger.debug(f"Response for sample prompts at {url}: {response.json()}")
return response.json()
except httpx.HTTPStatusError as e:
logging.error(f"Failed to get sample prompts: {e}")
raise Exception(f"Failed to get sample prompts: {e.response.text}") from e
Loading