Skip to main content

Python client for mindforge.ai

Project description

mindforge-py

mindforge.ai

This package contains Python clients and utilities for interacting with the Mindforge API. Specifically, there's a MindforgeServerClient for interactions with our REST API (e.g. creating an NPC, deleting a capability), and a MindforgeBrowserClient for joining live sessions in your client-side code.

Installation

To install the Mindforge client, use pip:

pip install mindforge

Server-side Usage

Create a MindforgeServerClient:

from mindforge import MindforgeServerClient

client = MindforgeServerClient(
  base_url="https://api.mindforge.ai", # Optional
  api_key="your-api-key"
)

To use this client, you'll need a Mindforge API key. You can create keys in the dashboard.

Performing NPC interactions

To trigger an NPC interaction:

from mindforge.messages import NPCText, NPCClientFunctionFire

npc_id = "your-npc-id" # get from dashboard
history = [
  {"role": "player", "content": "Hello, NPC!"},
  {"role": "npc", "content": "Greetings! How can I assist you today?"},
]

try:
  result = await client.perform.trigger(npc_id, history)
  for message in result:
    if isinstance(message, NPCText):
      print("NPC Text:", message.content)
    elif isinstance(message, NPCClientFunctionFire):
      print("NPC Function:", message.name, message.args)
except ValueError as error:
  print("Error performing NPC interaction:", error)

Browser-side Usage

Create a MindforgeBrowserClient:

from mindforge import MindforgeBrowserClient, MindforgeNPCMessageType

client = MindforgeBrowserClient()

Joining a session

To join a live session:

token = "your-session-token" # `get_mindforge_session_token from token.py`

try:
  await client.join_session(token)
  print("Joined session successfully")
except ValueError as error:
  print("Error joining session:", error)

Receiving messages

You can listen for various events emitted by the client:

@client.on(MindforgeNPCMessageType.Text)
def handle_text(message):
  print("Received NPC text:", message.content)

@client.on(MindforgeNPCMessageType.InputAudioTranscript)
def handle_input_transcript(message):
  print("Received input audio transcript:", message.content)

@client.on(MindforgeNPCMessageType.OutputAudioTranscript)
def handle_output_transcript(message):
  print("Received output audio transcript:", message.content)

@client.on(MindforgeNPCMessageType.ClientFunctionFire)
def handle_client_function(message):
  print("NPC triggered client function:", message.name, message.args)

Disconnecting

To disconnect from the session:

client.disconnect()

Event Types

The client uses the following event types:

Server Event Types

Event Type Description
NPCText Received when the NPC sends a text message.
NPCInputAudioTranscript Received when the input audio transcript is available.
NPCOutputAudioTranscript Received when the output audio transcript is available.
NPCClientFunctionFire Received when the NPC triggers a client-side function.

Client Event Types

Event Type Description
PlayerText Used to send a text message from the player to the server.
PlayerTriggerNPCMessage Used to trigger an NPC message from the player.

Support

If you need any help or have any questions, please open a GitHub issue or contact us at team@mindforge.ai.

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

mindforge-1.0.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

mindforge-1.0.4-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mindforge-1.0.4.tar.gz.

File metadata

  • Download URL: mindforge-1.0.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for mindforge-1.0.4.tar.gz
Algorithm Hash digest
SHA256 2ce42e0fb15d939100901c675dd289af71511759a5392bcdf08cd6e64245972c
MD5 24246629ef99a05452020987a06700e4
BLAKE2b-256 33062b3133ca354be43df0ec0bd68d162fa13df0b0b79793b4a73dde8bc8eb0b

See more details on using hashes here.

File details

Details for the file mindforge-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: mindforge-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for mindforge-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e30f5277dfef99b443efaaae96873a24a874aeecadb79bf6fba6590a54e03f
MD5 874744246613db4c7f29e82c8dd60f74
BLAKE2b-256 354cdfd2a8c973aede248e04c412281f3541720907a909d21f2d2a00471d1927

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