Skip to main content

A Python SDK for fetching and managing prompts by goman.live

Project description

Goman LIve

This SDK allows developers to easily fetch and manage prompt templates from a remote server. It supports both local environments and remote contexts, making it versatile for different projects. The package was developed as part of the Goman.live SaaS product, which functions as a prompt management platform.

Installation

To use this SDK in your Python project, install it via pip:

pip install goman-live-sdk

Example:

from goman_live_sdk import PromptSDK

# Initialize the SDK
application_id = "your_application_id"
api_key = "your_api_key"
base_url = "https://api.goman.live"
sdk = PromptSDK(application_id, api_key, base_url)

# Fetch a prompt from the remote server
prompt_id = "example_prompt_id"
context = {"username": "JohnDoe"}
try:
    prompt_response = sdk.get_prompt_from_remote(prompt_id, context, options)
    print(f"Prompt: {prompt_response.template}")
except Exception as e:
    print(f"Error fetching prompt: {e}")

# Send JSON result to the editor
result_json = {"result": "This is a test result"}
try:
    response = sdk.send_json_result_to_editor(result_json, prompt_id)
    print(f"Response: {response}")
except Exception as e:
    print(f"Error sending JSON result: {e}")

# Send image result to the editor
result_image = "base64_encoded_image_string"
try:
    response = sdk.send_image_result_to_editor(result_image, prompt_id)
    print(f"Response: {response}")
except Exception as e:
    print(f"Error sending image result: {e}")

# Initialize WebSocket connection
def example_callback(data):
    print(f"Received data: {data}")
    return {"status": "processed"}

sdk.init_callbacks(example_callback)
try:
    sdk.init_socket(api_key, application_id, prompt_id)
except Exception as e:
    print(f"Error initializing WebSocket: {e}")

# Close the WebSocket connection
sdk.close_socket()

PromptSDK Documentation

The PromptSDK class provides methods to interact with the Goman Live API for fetching and managing prompts, sending results, and handling WebSocket connections.

Class: PromptSDK

Constructor

def __init__(self, application_id: str, api_key: str, base_url: str = "https://api.goman.live"):
  • application_id (str): The unique identifier for the application.
  • api_key (str): The API key for authenticating requests.
  • base_url (str, optional): The base URL of the API server. Defaults to "https://api.goman.live".

Methods

get_prompt_from_remote

Fetches a prompt from the remote server and processes the template with context.

def get_prompt_from_remote(
    self,
    prompt_id: str,
    context: Dict[str, str] = {},
    options: Dict[str, str] = {},
) -> PromptResponse:
  • prompt_id (str): The ID of the prompt to fetch.
  • context (Dict[str, str], optional): A dictionary of context variables to replace in the template. Defaults to an empty dictionary.
  • options (Dict[str, str], optional): Additional options such as a custom URL for fetching the prompt. Defaults to an empty dictionary.

Returns a

PromptResponse

object containing the prompt ID, processed template, and metadata.

send_json_result_to_editor

Sends a JSON result to the editor for a specific prompt.

def send_json_result_to_editor(self, result_json: str, prompt_id: str):
  • result_json (str): The JSON object or string to send.
  • prompt_id (str): The ID of the prompt associated with the result.

Returns the server's response as a JSON object.

send_image_result_to_editor

Sends an image result to the editor for a specific prompt.

def send_image_result_to_editor(self, result_image: Union[str, bytes], prompt_id: str):
  • result_image (Union[str, bytes]): The image as a base64 string or bytes to send.
  • prompt_id (str): The ID of the prompt associated with the image.

Returns the server's response as a JSON object.

init_socket

Initializes a WebSocket connection for real-time communication.

def init_socket(
    self,
    base_url: str = "wss://api.goman.live/ws_sdk",
    api_key: Optional[str] = None,
    application_id: Optional[str] = None,
    prompt_id: str = "",
    close_socket_after_callback: bool = False,
):
  • base_url (str, optional): The base URL of the WebSocket server. Defaults to "wss://api.goman.live/ws_sdk".
  • api_key (Optional[str], optional): The API key for authentication. Defaults to the configured API key.
  • application_id (Optional[str], optional): The application ID for authentication. Defaults to the configured application ID.
  • prompt_id (str, optional): The ID of the prompt associated with the connection. Defaults to an empty string.
  • close_socket_after_callback (bool, optional): Whether to close the WebSocket after processing a callback. Defaults to False.

close_socket

Closes the WebSocket connection if it is open.

def close_socket(self):

init_callbacks

Adds a callback to be executed when a WebSocket message is received.

def init_callbacks(self, callback: Callable[..., Any]):
  • callback (Callable[..., Any]): The callback function to handle WebSocket messages.

Classes

Config

A configuration class for storing application ID, API key, and base URL.

PromptResponse

A class representing the response from fetching a prompt, containing the prompt ID, processed template, and metadata.

class Config:
    def __init__(self, application_id: str, api_key: str, base_url: str):
        self.application_id = application_id
        self.api_key = api_key
        self.base_url = base_url

class PromptResponse:
    def __init__(self, id: str, value: str, metadata: Dict[str, Any]):
        self.id = id
        self.value = value
        self.metadata = metadata

This documentation provides detailed information about the `PromptSDK` class, its methods, and the associated classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

goman_live_sdk-0.1.11.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

goman_live_sdk-0.1.11-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file goman_live_sdk-0.1.11.tar.gz.

File metadata

  • Download URL: goman_live_sdk-0.1.11.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for goman_live_sdk-0.1.11.tar.gz
Algorithm Hash digest
SHA256 94fad9f72fab143501fc97932a6034d4b4207ef8fb42fda1848141e3c35e6ce0
MD5 14fbbb25e91c06db58c881c6cb3faba7
BLAKE2b-256 c3fb1230b700c639ad285e768805cc77e9b45b3326dd679df54714f21c9eaaab

See more details on using hashes here.

File details

Details for the file goman_live_sdk-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for goman_live_sdk-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 061a39be739e205b54f43ff56ba556b4fab60c711ef53762f620b3e5762deffe
MD5 8b3cb1cfc1145963690d7419230c38d2
BLAKE2b-256 4e1959ed0e50bc17bd4dcb5b035cb0a3c781bb1d44d6ddfc1cd19c116feeb8bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page