-
Notifications
You must be signed in to change notification settings - Fork 794
Improve Azure example configuration handling #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |||||||||
|
|
||||||||||
| from agentlightning.adapter.messages import OpenAIMessages, TraceToMessages | ||||||||||
| from agentlightning.algorithm import Algorithm | ||||||||||
| from agentlightning.algorithm.utils import batch_iter_over_dataset | ||||||||||
| from agentlightning.algorithm.apo.apo import batch_iter_over_dataset | ||||||||||
| from agentlightning.reward import find_final_reward | ||||||||||
| from agentlightning.types import LLM, RolloutMode, TaskInput | ||||||||||
|
|
||||||||||
|
|
@@ -29,6 +29,11 @@ | |||||||||
| FINETUNE_JOB_POLL_INTERVAL = 60 | ||||||||||
|
|
||||||||||
|
|
||||||||||
| from dotenv import load_dotenv | ||||||||||
|
|
||||||||||
| # Load environment variables from .env file (override existing) | ||||||||||
| load_dotenv(override=True) | ||||||||||
|
|
||||||||||
| class AzureOpenAIFinetune(Algorithm): | ||||||||||
| """Coordinate iterative fine-tuning runs for an Azure OpenAI deployment. | ||||||||||
|
|
||||||||||
|
|
@@ -176,6 +181,10 @@ async def run( # type: ignore | |||||||||
| training_data = await self.prepare_data_for_training(messages_group, reward_group, "train") | ||||||||||
| self._log_info(f"[Stage 4] Prepared {len(training_data)} training examples after filtering.") | ||||||||||
|
|
||||||||||
| self.openai_client = OpenAI( | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should encourage users to use the correct endpoint ending with /openai/v1. In other words, the documentation should be updated instead of the code. |
||||||||||
| api_key=self.azure_openai_api_key, | ||||||||||
| base_url=self.azure_openai_endpoint + "/openai/v1/", | ||||||||||
| ) | ||||||||||
|
Comment on lines
+184
to
+187
|
||||||||||
| self.openai_client = OpenAI( | |
| api_key=self.azure_openai_api_key, | |
| base_url=self.azure_openai_endpoint + "/openai/v1/", | |
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,13 @@ | |||||||||
|
|
||||||||||
| from agentlightning import LLM, AgentOpsTracer, InMemoryLightningStore, LitAgentRunner, rollout | ||||||||||
|
|
||||||||||
| from dotenv import load_dotenv | ||||||||||
|
|
||||||||||
| # Load environment variables from .env file (override existing) | ||||||||||
| load_dotenv(override=True) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dotenv run is a better idea than load_dotenv. |
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
||||||||||
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message states "Set AZURE_OPENAI_API_VERSION to match your Azure OpenAI resource" but doesn't provide guidance on what a valid value looks like. Consider enhancing the error message to include an example of a valid API version format (e.g., "2024-08-01-preview") to help users configure this correctly.
| raise ValueError("Set AZURE_OPENAI_API_VERSION to match your Azure OpenAI resource.") | |
| raise ValueError( | |
| "Set AZURE_OPENAI_API_VERSION (for example, '2024-08-01-preview') to match your Azure OpenAI resource's API version." | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why AzureOpenAI is a must here?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,9 @@ | |
| from capital_agent import capital_agent | ||
| from rich.console import Console | ||
|
|
||
| from agentlightning import TraceToMessages, Trainer, setup_logging | ||
| from agentlightning.adapter.messages import TraceToMessages | ||
| from agentlightning.trainer.trainer import Trainer | ||
| from agentlightning.logging import configure_logger | ||
|
|
||
| console = Console() | ||
|
|
||
|
|
@@ -20,7 +22,7 @@ def parse_args() -> argparse.Namespace: | |
|
|
||
|
|
||
| def main(): | ||
| setup_logging() | ||
| configure_logger() | ||
|
||
| args = parse_args() | ||
| finetune_algo = AzureOpenAIFinetune( | ||
| base_deployment_name="gpt-4.1-mini", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import path change is incorrect. The function
batch_iter_over_datasetis defined inagentlightning.algorithm.utils(not inagentlightning.algorithm.apo.apo). Whileapo.pyimports it from utils, importing directly from apo.py creates an indirect dependency. Please import from the original location:from agentlightning.algorithm.utils import batch_iter_over_dataset.