Hello World Example

This guide demonstrates creating your first conversation using the Amigo SDK in Python or TypeScript.

Prerequisites

Before You Begin

  1. Installed the SDK in your project

  2. Configured your credentials with valid API keys

  3. Service ID from your Amigo dashboard

Quick Overview

Code Examples

Here's a complete example that creates a conversation, sends a message, and handles the streaming response:

from amigo_sdk import AmigoClient
from amigo_sdk.models import (
    ConversationCreateConversationRequest,
    CreateConversationParametersQuery,
    InteractWithConversationParametersQuery,
)

def hello_world():
    # Initialize the client
    with AmigoClient(
        api_key="your-api-key",
        api_key_id="your-api-key-id",
        user_id="your-user-id",
        organization_id="your-org-id"
    ) as client:

        # Step 1: Create a conversation
        print("Creating conversation...")
        create_events = client.conversation.create_conversation(
            ConversationCreateConversationRequest(
                service_id="your-service-id",
                service_version_set_name="release"
            ),
            CreateConversationParametersQuery(response_format="text")
        )

        # Process creation events
        conversation_id = None
        for event in create_events:
            event_data = event.model_dump(mode="json")
            print(f"Create event: {event_data.get('type')}")

            if event_data.get("type") == "conversation-created":
                conversation_id = event_data.get("conversation_id")
                print(f"Conversation created: {conversation_id}")

            if event_data.get("type") == "interaction-complete":
                break

        if not conversation_id:
            raise RuntimeError("Failed to create conversation")

        # Step 2: Send a message
        print("\nSending message...")
        interaction_events = client.conversation.interact_with_conversation(
            conversation_id,
            InteractWithConversationParametersQuery(
                request_format="text",
                response_format="text"
            ),
            text_message="Hello! Can you help me get started with Amigo?"
        )

        # Process interaction events
        full_response = ""
        for event in interaction_events:
            event_data = event.model_dump(mode="json")

            if event_data.get("type") == "new-message":
                message_chunk = event_data.get("message", "")
                full_response += message_chunk
                print(message_chunk, end="", flush=True)

            elif event_data.get("type") == "interaction-complete":
                print(f"\nResponse complete!")
                break

        print(f"\nFull response: {full_response}")

        # Step 3: Finish the conversation
        print("\nFinishing conversation...")
        try:
            client.conversation.finish_conversation(conversation_id)
            print("Conversation finished successfully!")
        except Exception as e:
            print(f"Warning: {e}")

if __name__ == "__main__":
    hello_world()

Next Steps

Now that you've created your first conversation, explore:

Last updated

Was this helpful?