From faf1feb6baa66a5a65144e1b835fc15b5295b58f Mon Sep 17 00:00:00 2001 From: discombobulateme Date: Mon, 31 Mar 2025 14:17:26 +0200 Subject: [PATCH 1/3] Add readme to how to run examples --- examples/HOW_TO_RUN_EXAMPLES.md | 149 ++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 examples/HOW_TO_RUN_EXAMPLES.md diff --git a/examples/HOW_TO_RUN_EXAMPLES.md b/examples/HOW_TO_RUN_EXAMPLES.md new file mode 100644 index 0000000..a89bbbd --- /dev/null +++ b/examples/HOW_TO_RUN_EXAMPLES.md @@ -0,0 +1,149 @@ +# How to Run Examples + +This guide will walk you through setting up and running the example agents in this repository. + +## Prerequisites + +1. Expose your local server: +During development, OpenServ needs to reach your agent running on your computer. Since your computer doesn't have a public internet address, we'll use a tunneling tool. + +What is tunneling? It creates a temporary secure pathway from the internet to your computer, allowing OpenServ to send requests to your agent while you develop it. + +Choose one option: +- ngrok (recommended for beginners) +- localtunnel (open source option) + +### Quick start with ngrok: +1. Download and install ngrok +2. Open your terminal and run: +```bash +ngrok http 7378 # Use your actual port number if different +``` +3. Look for a line like `Forwarding https://abc123.ngrok-free.app -> http://localhost:7378` +4. Copy the https URL (e.g., https://abc123.ngrok-free.app) - you'll need this later + +## Python Setup + +1. Create and activate a virtual environment: +```bash +# Create a virtual environment +python3 -m venv venv + +# Activate the virtual environment +# On macOS/Linux: +source venv/bin/activate +# On Windows: +.\venv\Scripts\activate +``` + +2. Install the required packages: +```bash +# Install the OpenServ SDK in editable mode +pip install --upgrade pip +pip install -e . && pip install -r requirements.txt +``` + +3. Verify the installation: +```bash +# Check if the packages are installed correctly +pip list | grep -E "openserv-sdk|python-dotenv|openai" +``` + +## 2. Create an account on OpenServ and set up your developer account +1. Create a developer account on OpenServ +2. Navigate to the Developer menu on the left sidebar +3. Click on Profile to set up your account as a developer on the platform + +## 3. Register your agent +To begin developing an agent for OpenServ, you must first register it: + +1. Navigate to the Developer sidebar menu +2. Click on Add Agent +3. Add details about your agent: + - Agent Name: Choose a descriptive name + - Agent Endpoint: Add the tunneling URL from step 1 as the agent's endpoint URL + - Capabilities Description: Describe what your agent can do + +## 4. Create a Secret (API) Key for your Agent +Note that every agent has its own API Key + +1. Navigate to Developer sidebar menu -> Your Agents +2. Open the Details of the agent for which you wish to generate a secret key +3. Click on Create Secret Key +4. Store this key securely as it will be required to authenticate your agent's requests with the OpenServ API + +## 5. Set Up Your Environment +Add your secret keys to your environment variables or to an .env file on your project root: + +```bash +export OPENSERV_API_KEY=your_api_key_here +export OPENAI_API_KEY=your_openai_api_key_here +``` + +## Running the Examples + +### Marketing Agent Example +This example demonstrates a specialized marketing agent with social media capabilities. + +1. Navigate to the examples directory and Run the marketing agent: +```bash +python3 examples/marketing_agent.py +``` + +3. Test the agent with the following prompt: +``` +Create a social media post for Twitter about the launch of our new AI-powered productivity tool. Then analyze the engagement metrics with 10 likes, 20 shares, 5 comments, and 100 impressions. +``` + +### Custom Agent Example +This example shows how to create a custom agent with specialized response behavior. + +1. Navigate to the examples directory: +```bash +cd examples +``` + +2. Run the custom agent: +```bash +python custom_agent.py +``` + +3. Test the agent with the following prompt: +``` +Hello, can you help me with a task? +``` + +### Twitter Agent Example +This example demonstrates an agent specifically designed to interact with Twitter. + +1. Navigate to the examples directory: +```bash +cd examples +``` + +2. Run the Twitter agent: +```bash +python twitter_agent.py +``` + +3. Test the agent with the following prompt: +``` +Get my Twitter account information and then send a marketing tweet about our new product launch. +``` + +## Troubleshooting + +If you encounter any issues: + +1. Ensure all environment variables are properly set +2. Check that your ngrok tunnel is active and the URL is correct +3. Verify that your agent is properly registered on OpenServ +4. Check the logs for any error messages +5. Make sure you have all required dependencies installed + +## Additional Notes + +- The examples use different capabilities and integrations to demonstrate various features of the OpenServ SDK +- Each example can be modified and extended based on your specific needs +- Remember to keep your API keys secure and never commit them to version control +- The system prompts and capabilities can be customized by modifying the respective files \ No newline at end of file From c183e612bae459074b45ecb85a732ac432f055b7 Mon Sep 17 00:00:00 2001 From: discombobulateme Date: Mon, 31 Mar 2025 14:17:36 +0200 Subject: [PATCH 2/3] Add missing requirement --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8ffa306..4deb7b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ uvicorn>=0.24.0 openai>=1.3.0 pydantic>=2.4.2 httpx>=0.25.0 -python-dotenv>=1.0.0 +python-dotenv>=1.0.0 +aiohttp>=3.8.0 From cedbd0059bbcd83089e6d811e70fd9480bf8115b Mon Sep 17 00:00:00 2001 From: discombobulateme Date: Mon, 31 Mar 2025 14:19:06 +0200 Subject: [PATCH 3/3] Fix runtime url --- src/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client.py b/src/client.py index 2f59833..f591f3e 100644 --- a/src/client.py +++ b/src/client.py @@ -138,8 +138,10 @@ class RuntimeClient(BaseClient): """Client for the OpenServ Runtime API.""" def __init__(self, config: APIConfig): super().__init__(config) + # Ensure runtime_url doesn't end with a slash + runtime_url = config.runtime_url.rstrip('/') self.client = httpx.AsyncClient( - base_url=f"{config.runtime_url}/runtime", + base_url=f"{runtime_url}/runtime", headers={ 'Content-Type': 'application/json', 'x-openserv-key': config.api_key