From 2f035f4587af4720eb20ef2b23475223ee7e9cb4 Mon Sep 17 00:00:00 2001 From: gbattistel <4660743+gbattistel@users.noreply.github.com> Date: Mon, 18 May 2026 13:15:54 -0400 Subject: [PATCH 1/5] feat: add Telnyx provider samples for OpenAI-compatible endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add samples demonstrating how to use Telnyx as an OpenAI-compatible inference provider with Agent Framework's existing OpenAIChatClient and OpenAIEmbeddingClient. Samples included: - telnyx_chat_completion.py: basic chat with streaming/non-streaming - telnyx_embeddings.py: text embeddings via Telnyx - telnyx_chat_with_tools.py: chat with telecom tools (SMS, lookup) Follows the same pattern as the existing Ollama provider sample. No new provider code — just configuration of base_url and api_key. Refs: #5925 --- .../02-agents/providers/telnyx/README.md | 62 ++++++++ .../telnyx/telnyx_chat_completion.py | 107 ++++++++++++++ .../telnyx/telnyx_chat_with_tools.py | 137 ++++++++++++++++++ .../providers/telnyx/telnyx_embeddings.py | 74 ++++++++++ 4 files changed, 380 insertions(+) create mode 100644 python/samples/02-agents/providers/telnyx/README.md create mode 100644 python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py create mode 100644 python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py create mode 100644 python/samples/02-agents/providers/telnyx/telnyx_embeddings.py diff --git a/python/samples/02-agents/providers/telnyx/README.md b/python/samples/02-agents/providers/telnyx/README.md new file mode 100644 index 0000000000..65a21b8519 --- /dev/null +++ b/python/samples/02-agents/providers/telnyx/README.md @@ -0,0 +1,62 @@ +# Telnyx Examples + +This folder contains examples demonstrating how to use Telnyx as an OpenAI-compatible inference provider with the Agent Framework. + +## Prerequisites + +1. **Telnyx Account**: Sign up at [portal.telnyx.com](https://portal.telnyx.com/) and obtain an API key +2. **API Key**: Generate an API key from the Telnyx portal under "Auth Keys" + +## Overview + +Telnyx provides an OpenAI-compatible API at `https://api.telnyx.com/v2/ai/openai` that supports chat completions, embeddings, and function/tool calling. Since it's OpenAI-compatible, you can use the existing `OpenAIChatClient` and `OpenAIEmbeddingClient` from the `agent-framework-openai` package — no new provider package is needed. + +This follows the same pattern as the [Ollama with OpenAI Chat Client](../ollama/ollama_with_openai_chat_client.py) example, where an existing provider client is configured with a custom `base_url`. + +> **Note**: Available models depend on your Telnyx account configuration. Common models include Kimi-K2.5, GLM-5.1-FP8, MiniMax-M2.7, and Qwen3-235B-A22B. See the [Telnyx AI documentation](https://developers.telnyx.com/docs/api/ai) for the latest model list. + +## Examples + +| File | Description | +|------|-------------| +| [`telnyx_chat_completion.py`](telnyx_chat_completion.py) | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. | +| [`telnyx_embeddings.py`](telnyx_embeddings.py) | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. | +| [`telnyx_chat_with_tools.py`](telnyx_chat_with_tools.py) | Chat completion with telecom tools (SMS, number lookup) using `telnyx-agent-toolkit`. Demonstrates combining LLM capabilities with real-world telecom actions. | + +## Configuration + +Set the following environment variables: + +- `TELNYX_API_KEY` — Your Telnyx API key (required for all examples) + - Get one from [portal.telnyx.com](https://portal.telnyx.com/) → Auth Keys + - Example: `export TELNYX_API_KEY="KEY0192..."` + +- `TELNYX_MODEL` — Model name to use (optional, defaults to `"Kimi-K2.5"`) + - Example: `export TELNYX_MODEL="GLM-5.1-FP8"` + +- `TELNYX_EMBEDDING_MODEL` — Embedding model name (optional, defaults to `"thenlper/gte-large"`) + - Example: `export TELNYX_EMBEDDING_MODEL="thenlper/gte-large"` + +- `TELNYX_FROM_NUMBER` — Phone number for sending SMS in E.164 format (required for `telnyx_chat_with_tools.py` only) + - Example: `export TELNYX_FROM_NUMBER="+15551234567"` + - Purchase a number at [portal.telnyx.com](https://portal.telnyx.com/) → Numbers + +## Quick Start + +```bash +# Install the Agent Framework OpenAI package +pip install agent-framework-openai + +# Set your Telnyx API key +export TELNYX_API_KEY="your-api-key-here" + +# Run the basic chat completion example +python telnyx_chat_completion.py +``` + +## Resources + +- [Telnyx AI API Documentation](https://developers.telnyx.com/docs/api/ai) +- [Telnyx Python SDK](https://pypi.org/project/telnyx/) +- [Telnyx Agent Toolkit](https://pypi.org/project/telnyx-agent-toolkit/) +- [Telnyx Portal](https://portal.telnyx.com/) diff --git a/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py new file mode 100644 index 0000000000..2cda8d6dea --- /dev/null +++ b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py @@ -0,0 +1,107 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +import os + +from agent_framework import Agent +from agent_framework.openai import OpenAIChatClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +""" +Telnyx Chat Completion Example + +This sample demonstrates using Telnyx as an OpenAI-compatible inference +provider through the OpenAIChatClient by configuring the base_url to +point to the Telnyx AI API endpoint. + +Telnyx provides an OpenAI-compatible API at https://api.telnyx.com/v2/ai/openai +that supports chat completions, embeddings, and function/tool calling. + +Environment Variables: + TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/) + TELNYX_MODEL — Model name to use (default: "Kimi-K2.5") + Available models include: Kimi-K2.5, GLM-5.1-FP8, + MiniMax-M2.7, Qwen3-235B-A22B +""" + + +async def non_streaming_example() -> None: + """Example of non-streaming response (get the complete result at once).""" + print("=== Non-streaming Response Example ===") + + # 1. Configure the OpenAI client to use Telnyx as the backend. + client = OpenAIChatClient( + api_key=os.getenv("TELNYX_API_KEY"), + base_url="https://api.telnyx.com/v2/ai/openai", + model=os.getenv("TELNYX_MODEL", "Kimi-K2.5"), + ) + + # 2. Create an agent that uses the Telnyx-backed client. + agent = Agent( + client=client, + name="TelnyxAgent", + instructions="You are a helpful assistant.", + ) + + # 3. Send a message and wait for the full response. + query = "What is the capital of France?" + print(f"User: {query}") + result = await agent.run(query) + print(f"Agent: {result}\n") + + +async def streaming_example() -> None: + """Example of streaming response (get results as they are generated).""" + print("=== Streaming Response Example ===") + + # 1. Configure the OpenAI client to use Telnyx as the backend. + client = OpenAIChatClient( + api_key=os.getenv("TELNYX_API_KEY"), + base_url="https://api.telnyx.com/v2/ai/openai", + model=os.getenv("TELNYX_MODEL", "Kimi-K2.5"), + ) + + # 2. Create an agent that uses the Telnyx-backed client. + agent = Agent( + client=client, + name="TelnyxAgent", + instructions="You are a helpful assistant.", + ) + + # 3. Send a message and stream the response token by token. + query = "Explain quantum computing in one paragraph." + print(f"User: {query}") + print("Agent: ", end="", flush=True) + async for chunk in agent.run(query, stream=True): + if chunk.text: + print(chunk.text, end="", flush=True) + print("\n") + + +async def main() -> None: + print("=== Telnyx Chat Completion Agent Example ===") + + await non_streaming_example() + await streaming_example() + + +if __name__ == "__main__": + asyncio.run(main()) + +""" +Sample output: + +=== Telnyx Chat Completion Agent Example === +=== Non-streaming Response Example === +User: What is the capital of France? +Agent: The capital of France is Paris. + +=== Streaming Response Example === +User: Explain quantum computing in one paragraph. +Agent: Quantum computing is a type of computation that harnesses quantum-mechanical +phenomena, such as superposition and entanglement, to process information in ways that +classical computers cannot... +""" diff --git a/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py b/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py new file mode 100644 index 0000000000..a481b3866c --- /dev/null +++ b/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py @@ -0,0 +1,137 @@ +# /// script +# requires-python = ">=3.10" +# dependencies = [ +# "telnyx-agent-toolkit>=0.1.0", +# ] +# /// +# Run with any PEP 723 compatible runner, e.g.: +# uv run samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py + +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +import os +from typing import Annotated + +from agent_framework import Agent, tool +from agent_framework.openai import OpenAIChatClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +""" +Telnyx Chat Completion with Telecom Tools Example + +This sample demonstrates using Telnyx as an OpenAI-compatible inference +provider together with Telnyx telecom tools (SMS, number lookup) via +the telnyx-agent-toolkit package. + +The agent can send SMS messages and look up phone number information +using Telnyx's telecom APIs, combining LLM capabilities with real-world +telecom actions. + +Environment Variables: + TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/) + TELNYX_MODEL — Model name to use (default: "Kimi-K2.5") + TELNYX_FROM_NUMBER — Phone number for sending SMS (E.164 format, e.g. "+15551234567") +""" + + +# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; +# see samples/02-agents/tools/function_tool_with_approval.py +# and samples/02-agents/tools/function_tool_with_approval_and_sessions.py. +@tool(approval_mode="never_require") +async def lookup_number( + phone_number: Annotated[str, "Phone number in E.164 format (e.g., +15551234567)"], +) -> str: + """Look up carrier and line type information for a phone number. + + Uses the Telnyx Number Lookup API to retrieve carrier details, + line type (mobile, landline, VoIP), and country information. + """ + import telnyx + + telnyx.api_key = os.getenv("TELNYX_API_KEY") + try: + lookup = telnyx.NumberLookup.retrieve(phone_number) + return str(lookup) + except Exception as e: + return f"Lookup failed: {e}" + + +@tool(approval_mode="never_require") +async def send_sms( + to_number: Annotated[str, "Destination phone number in E.164 format (e.g., +15551234567)"], + message: Annotated[str, "SMS message text to send"], +) -> str: + """Send an SMS message to a phone number. + + Uses the Telnyx Messaging API to send an SMS from the configured + TELNYX_FROM_NUMBER to the specified destination. + """ + import telnyx + + telnyx.api_key = os.getenv("TELNYX_API_KEY") + from_number = os.getenv("TELNYX_FROM_NUMBER") + + if not from_number: + return "Error: TELNYX_FROM_NUMBER environment variable is not set." + + try: + sms = telnyx.Message.create( + from_=from_number, + to=to_number, + text=message, + ) + return f"SMS sent successfully. Message ID: {sms.id}" + except Exception as e: + return f"Failed to send SMS: {e}" + + +async def main() -> None: + print("=== Telnyx Chat Completion with Telecom Tools Example ===") + + # 1. Configure the OpenAI client to use Telnyx as the backend. + client = OpenAIChatClient( + api_key=os.getenv("TELNYX_API_KEY"), + base_url="https://api.telnyx.com/v2/ai/openai", + model=os.getenv("TELNYX_MODEL", "Kimi-K2.5"), + ) + + # 2. Create an agent with telecom tools. + agent = Agent( + client=client, + name="TelnyxTelecomAgent", + instructions=( + "You are a telecom assistant powered by Telnyx. " + "You can look up phone number information and send SMS messages. " + "Always confirm with the user before sending an SMS. " + "When looking up a number, present the carrier and line type clearly." + ), + tools=[lookup_number, send_sms], + ) + + # 3. Example: Look up a phone number. + query = "Can you look up the number +15551234567 and tell me what carrier it belongs to?" + print(f"User: {query}") + result = await agent.run(query) + print(f"Agent: {result}\n") + + +if __name__ == "__main__": + asyncio.run(main()) + +""" +Sample output: + +=== Telnyx Chat Completion with Telecom Tools Example === +User: Can you look up the number +15551234567 and tell me what carrier it belongs to? +Agent: I looked up the number +15551234567 for you. Here are the details: + +- **Carrier**: T-Mobile USA +- **Line Type**: Mobile +- **Country**: United States + +Is there anything else you'd like to know about this number, or would you like me to send an SMS to it? +""" diff --git a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py new file mode 100644 index 0000000000..d72ab4578a --- /dev/null +++ b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py @@ -0,0 +1,74 @@ +# Copyright (c) Microsoft. All rights reserved. + +import asyncio +import os + +from agent_framework.openai import OpenAIEmbeddingClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +""" +Telnyx Embeddings Example + +This sample demonstrates using Telnyx for text embeddings through the +OpenAIEmbeddingClient by configuring the base_url to point to the +Telnyx AI API endpoint. + +Telnyx provides an OpenAI-compatible API that supports embeddings +generation using models like `thenlper/gte-large`. + +Environment Variables: + TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/) + TELNYX_EMBEDDING_MODEL — Embedding model name (default: "thenlper/gte-large") +""" + + +async def main() -> None: + print("=== Telnyx Embeddings Example ===") + + # 1. Configure the OpenAI embedding client to use Telnyx as the backend. + client = OpenAIEmbeddingClient( + api_key=os.getenv("TELNYX_API_KEY"), + base_url="https://api.telnyx.com/v2/ai/openai", + model=os.getenv("TELNYX_EMBEDDING_MODEL", "thenlper/gte-large"), + ) + + # 2. Generate embeddings for a list of texts. + texts = [ + "Telnyx provides telecom infrastructure for AI agents.", + "Agent Framework makes it easy to build AI agents.", + ] + + print(f"Generating embeddings for {len(texts)} texts...") + response = await client.get_embeddings(texts) + + # 3. Print the embedding dimensions and a preview of each vector. + for i, embedding in enumerate(response): + print(f"Text {i + 1}: \"{texts[i]}\"") + print(f" Dimensions: {len(embedding)}") + print(f" Preview: [{', '.join(str(v) for v in embedding[:5])}, ...]") + print() + + print("Done!") + + +if __name__ == "__main__": + asyncio.run(main()) + +""" +Sample output: + +=== Telnyx Embeddings Example === +Generating embeddings for 2 texts... +Text 1: "Telnyx provides telecom infrastructure for AI agents." + Dimensions: 1024 + Preview: [0.0123, -0.0456, 0.0789, ...], ... + +Text 2: "Agent Framework makes it easy to build AI agents." + Dimensions: 1024 + Preview: [0.0234, -0.0567, 0.0890, ...], ... + +Done! +""" From b6f1bf1952fe73c2732679c8b5ef470a16dd3a9c Mon Sep 17 00:00:00 2001 From: gbattistel <4660743+gbattistel@users.noreply.github.com> Date: Mon, 18 May 2026 13:48:18 -0400 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20remove=20tools=20sample=20from?= =?UTF-8?q?=20initial=20PR=20=E2=80=94=20chat=20+=20embeddings=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02-agents/providers/telnyx/README.md | 9 +- .../telnyx/telnyx_chat_with_tools.py | 137 ------------------ 2 files changed, 1 insertion(+), 145 deletions(-) delete mode 100644 python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py diff --git a/python/samples/02-agents/providers/telnyx/README.md b/python/samples/02-agents/providers/telnyx/README.md index 65a21b8519..20021d2a76 100644 --- a/python/samples/02-agents/providers/telnyx/README.md +++ b/python/samples/02-agents/providers/telnyx/README.md @@ -9,7 +9,7 @@ This folder contains examples demonstrating how to use Telnyx as an OpenAI-compa ## Overview -Telnyx provides an OpenAI-compatible API at `https://api.telnyx.com/v2/ai/openai` that supports chat completions, embeddings, and function/tool calling. Since it's OpenAI-compatible, you can use the existing `OpenAIChatClient` and `OpenAIEmbeddingClient` from the `agent-framework-openai` package — no new provider package is needed. +Telnyx provides an OpenAI-compatible API at `https://api.telnyx.com/v2/ai/openai` that supports chat completions and embeddings. Since it's OpenAI-compatible, you can use the existing `OpenAIChatClient` and `OpenAIEmbeddingClient` from the `agent-framework-openai` package — no new provider package is needed. This follows the same pattern as the [Ollama with OpenAI Chat Client](../ollama/ollama_with_openai_chat_client.py) example, where an existing provider client is configured with a custom `base_url`. @@ -21,7 +21,6 @@ This follows the same pattern as the [Ollama with OpenAI Chat Client](../ollama/ |------|-------------| | [`telnyx_chat_completion.py`](telnyx_chat_completion.py) | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. | | [`telnyx_embeddings.py`](telnyx_embeddings.py) | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. | -| [`telnyx_chat_with_tools.py`](telnyx_chat_with_tools.py) | Chat completion with telecom tools (SMS, number lookup) using `telnyx-agent-toolkit`. Demonstrates combining LLM capabilities with real-world telecom actions. | ## Configuration @@ -37,10 +36,6 @@ Set the following environment variables: - `TELNYX_EMBEDDING_MODEL` — Embedding model name (optional, defaults to `"thenlper/gte-large"`) - Example: `export TELNYX_EMBEDDING_MODEL="thenlper/gte-large"` -- `TELNYX_FROM_NUMBER` — Phone number for sending SMS in E.164 format (required for `telnyx_chat_with_tools.py` only) - - Example: `export TELNYX_FROM_NUMBER="+15551234567"` - - Purchase a number at [portal.telnyx.com](https://portal.telnyx.com/) → Numbers - ## Quick Start ```bash @@ -57,6 +52,4 @@ python telnyx_chat_completion.py ## Resources - [Telnyx AI API Documentation](https://developers.telnyx.com/docs/api/ai) -- [Telnyx Python SDK](https://pypi.org/project/telnyx/) -- [Telnyx Agent Toolkit](https://pypi.org/project/telnyx-agent-toolkit/) - [Telnyx Portal](https://portal.telnyx.com/) diff --git a/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py b/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py deleted file mode 100644 index a481b3866c..0000000000 --- a/python/samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py +++ /dev/null @@ -1,137 +0,0 @@ -# /// script -# requires-python = ">=3.10" -# dependencies = [ -# "telnyx-agent-toolkit>=0.1.0", -# ] -# /// -# Run with any PEP 723 compatible runner, e.g.: -# uv run samples/02-agents/providers/telnyx/telnyx_chat_with_tools.py - -# Copyright (c) Microsoft. All rights reserved. - -import asyncio -import os -from typing import Annotated - -from agent_framework import Agent, tool -from agent_framework.openai import OpenAIChatClient -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -""" -Telnyx Chat Completion with Telecom Tools Example - -This sample demonstrates using Telnyx as an OpenAI-compatible inference -provider together with Telnyx telecom tools (SMS, number lookup) via -the telnyx-agent-toolkit package. - -The agent can send SMS messages and look up phone number information -using Telnyx's telecom APIs, combining LLM capabilities with real-world -telecom actions. - -Environment Variables: - TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/) - TELNYX_MODEL — Model name to use (default: "Kimi-K2.5") - TELNYX_FROM_NUMBER — Phone number for sending SMS (E.164 format, e.g. "+15551234567") -""" - - -# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; -# see samples/02-agents/tools/function_tool_with_approval.py -# and samples/02-agents/tools/function_tool_with_approval_and_sessions.py. -@tool(approval_mode="never_require") -async def lookup_number( - phone_number: Annotated[str, "Phone number in E.164 format (e.g., +15551234567)"], -) -> str: - """Look up carrier and line type information for a phone number. - - Uses the Telnyx Number Lookup API to retrieve carrier details, - line type (mobile, landline, VoIP), and country information. - """ - import telnyx - - telnyx.api_key = os.getenv("TELNYX_API_KEY") - try: - lookup = telnyx.NumberLookup.retrieve(phone_number) - return str(lookup) - except Exception as e: - return f"Lookup failed: {e}" - - -@tool(approval_mode="never_require") -async def send_sms( - to_number: Annotated[str, "Destination phone number in E.164 format (e.g., +15551234567)"], - message: Annotated[str, "SMS message text to send"], -) -> str: - """Send an SMS message to a phone number. - - Uses the Telnyx Messaging API to send an SMS from the configured - TELNYX_FROM_NUMBER to the specified destination. - """ - import telnyx - - telnyx.api_key = os.getenv("TELNYX_API_KEY") - from_number = os.getenv("TELNYX_FROM_NUMBER") - - if not from_number: - return "Error: TELNYX_FROM_NUMBER environment variable is not set." - - try: - sms = telnyx.Message.create( - from_=from_number, - to=to_number, - text=message, - ) - return f"SMS sent successfully. Message ID: {sms.id}" - except Exception as e: - return f"Failed to send SMS: {e}" - - -async def main() -> None: - print("=== Telnyx Chat Completion with Telecom Tools Example ===") - - # 1. Configure the OpenAI client to use Telnyx as the backend. - client = OpenAIChatClient( - api_key=os.getenv("TELNYX_API_KEY"), - base_url="https://api.telnyx.com/v2/ai/openai", - model=os.getenv("TELNYX_MODEL", "Kimi-K2.5"), - ) - - # 2. Create an agent with telecom tools. - agent = Agent( - client=client, - name="TelnyxTelecomAgent", - instructions=( - "You are a telecom assistant powered by Telnyx. " - "You can look up phone number information and send SMS messages. " - "Always confirm with the user before sending an SMS. " - "When looking up a number, present the carrier and line type clearly." - ), - tools=[lookup_number, send_sms], - ) - - # 3. Example: Look up a phone number. - query = "Can you look up the number +15551234567 and tell me what carrier it belongs to?" - print(f"User: {query}") - result = await agent.run(query) - print(f"Agent: {result}\n") - - -if __name__ == "__main__": - asyncio.run(main()) - -""" -Sample output: - -=== Telnyx Chat Completion with Telecom Tools Example === -User: Can you look up the number +15551234567 and tell me what carrier it belongs to? -Agent: I looked up the number +15551234567 for you. Here are the details: - -- **Carrier**: T-Mobile USA -- **Line Type**: Mobile -- **Country**: United States - -Is there anything else you'd like to know about this number, or would you like me to send an SMS to it? -""" From 88e4fbe0ab694302b3e9972ebd6e16bd25959f13 Mon Sep 17 00:00:00 2001 From: gbattistel <4660743+gbattistel@users.noreply.github.com> Date: Mon, 18 May 2026 14:09:41 -0400 Subject: [PATCH 3/5] fix: address Copilot review feedback - Move module docstrings before load_dotenv() (top of file) - Fix markdown table syntax in README (remove extra pipes) - Add python-dotenv to Quick Start install instructions - Update PR description to match actual file count (3 files) --- .../02-agents/providers/telnyx/README.md | 8 +++---- .../telnyx/telnyx_chat_completion.py | 23 +++++++++---------- .../providers/telnyx/telnyx_embeddings.py | 21 ++++++++--------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/python/samples/02-agents/providers/telnyx/README.md b/python/samples/02-agents/providers/telnyx/README.md index 20021d2a76..b2bb54b623 100644 --- a/python/samples/02-agents/providers/telnyx/README.md +++ b/python/samples/02-agents/providers/telnyx/README.md @@ -19,8 +19,8 @@ This follows the same pattern as the [Ollama with OpenAI Chat Client](../ollama/ | File | Description | |------|-------------| -| [`telnyx_chat_completion.py`](telnyx_chat_completion.py) | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. | -| [`telnyx_embeddings.py`](telnyx_embeddings.py) | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. | +| `telnyx_chat_completion.py` | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. | +| `telnyx_embeddings.py` | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. | ## Configuration @@ -39,8 +39,8 @@ Set the following environment variables: ## Quick Start ```bash -# Install the Agent Framework OpenAI package -pip install agent-framework-openai +# Install the Agent Framework OpenAI package and python-dotenv +pip install agent-framework-openai python-dotenv # Set your Telnyx API key export TELNYX_API_KEY="your-api-key-here" diff --git a/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py index 2cda8d6dea..5e201a5c92 100644 --- a/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py +++ b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py @@ -1,17 +1,6 @@ # Copyright (c) Microsoft. All rights reserved. -import asyncio -import os - -from agent_framework import Agent -from agent_framework.openai import OpenAIChatClient -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -""" -Telnyx Chat Completion Example +"""Telnyx Chat Completion Example This sample demonstrates using Telnyx as an OpenAI-compatible inference provider through the OpenAIChatClient by configuring the base_url to @@ -27,6 +16,16 @@ MiniMax-M2.7, Qwen3-235B-A22B """ +import asyncio +import os + +from agent_framework import Agent +from agent_framework.openai import OpenAIChatClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + async def non_streaming_example() -> None: """Example of non-streaming response (get the complete result at once).""" diff --git a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py index d72ab4578a..868a15bdc8 100644 --- a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py +++ b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py @@ -1,16 +1,6 @@ # Copyright (c) Microsoft. All rights reserved. -import asyncio -import os - -from agent_framework.openai import OpenAIEmbeddingClient -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - -""" -Telnyx Embeddings Example +"""Telnyx Embeddings Example This sample demonstrates using Telnyx for text embeddings through the OpenAIEmbeddingClient by configuring the base_url to point to the @@ -24,6 +14,15 @@ TELNYX_EMBEDDING_MODEL — Embedding model name (default: "thenlper/gte-large") """ +import asyncio +import os + +from agent_framework.openai import OpenAIEmbeddingClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + async def main() -> None: print("=== Telnyx Embeddings Example ===") From bc5f6692121e928aef669a5806b25e33f03dfc63 Mon Sep 17 00:00:00 2001 From: gbattistel <4660743+gbattistel@users.noreply.github.com> Date: Mon, 18 May 2026 14:42:43 -0400 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20match=20repo=20sample=20style=20?= =?UTF-8?q?=E2=80=94=20docstring=20after=20load=5Fdotenv()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telnyx/telnyx_chat_completion.py | 23 ++++++++++--------- .../providers/telnyx/telnyx_embeddings.py | 21 +++++++++-------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py index 5e201a5c92..2cda8d6dea 100644 --- a/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py +++ b/python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py @@ -1,6 +1,17 @@ # Copyright (c) Microsoft. All rights reserved. -"""Telnyx Chat Completion Example +import asyncio +import os + +from agent_framework import Agent +from agent_framework.openai import OpenAIChatClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +""" +Telnyx Chat Completion Example This sample demonstrates using Telnyx as an OpenAI-compatible inference provider through the OpenAIChatClient by configuring the base_url to @@ -16,16 +27,6 @@ MiniMax-M2.7, Qwen3-235B-A22B """ -import asyncio -import os - -from agent_framework import Agent -from agent_framework.openai import OpenAIChatClient -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - async def non_streaming_example() -> None: """Example of non-streaming response (get the complete result at once).""" diff --git a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py index 868a15bdc8..d72ab4578a 100644 --- a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py +++ b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py @@ -1,6 +1,16 @@ # Copyright (c) Microsoft. All rights reserved. -"""Telnyx Embeddings Example +import asyncio +import os + +from agent_framework.openai import OpenAIEmbeddingClient +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() + +""" +Telnyx Embeddings Example This sample demonstrates using Telnyx for text embeddings through the OpenAIEmbeddingClient by configuring the base_url to point to the @@ -14,15 +24,6 @@ TELNYX_EMBEDDING_MODEL — Embedding model name (default: "thenlper/gte-large") """ -import asyncio -import os - -from agent_framework.openai import OpenAIEmbeddingClient -from dotenv import load_dotenv - -# Load environment variables from .env file -load_dotenv() - async def main() -> None: print("=== Telnyx Embeddings Example ===") From e9d1d057c5e10c3716b23faa075c0d7298dbaa0f Mon Sep 17 00:00:00 2001 From: gbattistel <4660743+gbattistel@users.noreply.github.com> Date: Tue, 19 May 2026 11:29:40 -0400 Subject: [PATCH 5/5] fix: use Embedding object properties in embeddings sample The get_embeddings() response returns Embedding objects with .dimensions and .vector attributes, not raw lists. Using len() and slicing directly causes TypeError at runtime. --- .../samples/02-agents/providers/telnyx/telnyx_embeddings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py index d72ab4578a..8c448353d5 100644 --- a/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py +++ b/python/samples/02-agents/providers/telnyx/telnyx_embeddings.py @@ -47,8 +47,8 @@ async def main() -> None: # 3. Print the embedding dimensions and a preview of each vector. for i, embedding in enumerate(response): print(f"Text {i + 1}: \"{texts[i]}\"") - print(f" Dimensions: {len(embedding)}") - print(f" Preview: [{', '.join(str(v) for v in embedding[:5])}, ...]") + print(f" Dimensions: {embedding.dimensions}") + print(f" Preview: [{', '.join(str(v) for v in embedding.vector[:5])}, ...]") print() print("Done!")