-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add tools with instructions and examples to completion and agent configs #106
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 2 commits
d47de6d
c01300c
0996e4e
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 |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from ldai.models import (AIAgentConfig, AIAgentConfigDefault, | ||
| AIAgentConfigRequest, AIAgentGraphConfig, AIAgents, | ||
| AICompletionConfig, AICompletionConfigDefault, | ||
| AIJudgeConfig, AIJudgeConfigDefault, Edge, | ||
| AIJudgeConfig, AIJudgeConfigDefault, AITool, Edge, | ||
| JudgeConfiguration, LDMessage, ModelConfig, | ||
| ProviderConfig) | ||
| from ldai.providers.ai_provider_factory import AIProviderFactory | ||
|
|
@@ -52,15 +52,31 @@ def _completion_config( | |
| default: AICompletionConfigDefault, | ||
| variables: Optional[Dict[str, Any]] = None, | ||
| ) -> AICompletionConfig: | ||
| model, provider, messages, instructions, tracker, enabled, judge_configuration, _ = self.__evaluate( | ||
| model, provider, messages, instructions, tracker, enabled, judge_configuration, variation = self.__evaluate( | ||
| key, context, default.to_dict(), variables | ||
| ) | ||
|
|
||
| # Parse tools from variation data | ||
| tools = None | ||
| if 'tools' in variation and isinstance(variation['tools'], list): | ||
| tools = [ | ||
| AITool( | ||
| key=tool['key'], | ||
| version=tool.get('version', 0), | ||
| instructions=tool.get('instructions'), | ||
| examples=tool.get('examples'), | ||
| custom_parameters=tool.get('customParameters'), | ||
| ) | ||
| for tool in variation['tools'] | ||
| if isinstance(tool, dict) and 'key' in tool | ||
| ] or None | ||
|
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. Duplicated tool-parsing logic across two methodsLow Severity The tool-parsing block in Additional Locations (1)
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. Valid observation. The duplication is intentional to keep the shared |
||
|
|
||
| config = AICompletionConfig( | ||
| key=key, | ||
| enabled=bool(enabled), | ||
| model=model, | ||
| messages=messages, | ||
| tools=tools if tools is not None else (default.tools if default.tools else None), | ||
| provider=provider, | ||
| tracker=tracker, | ||
| judge_configuration=judge_configuration, | ||
|
|
@@ -706,19 +722,35 @@ def __evaluate_agent( | |
| :param variables: Variables for interpolation. | ||
| :return: Configured AIAgentConfig instance. | ||
| """ | ||
| model, provider, messages, instructions, tracker, enabled, judge_configuration, _ = self.__evaluate( | ||
| model, provider, messages, instructions, tracker, enabled, judge_configuration, variation = self.__evaluate( | ||
| key, context, default.to_dict(), variables | ||
| ) | ||
|
|
||
| # For agents, prioritize instructions over messages | ||
| final_instructions = instructions if instructions is not None else default.instructions | ||
|
|
||
| # Parse tools from variation data | ||
| tools = None | ||
| if 'tools' in variation and isinstance(variation['tools'], list): | ||
| tools = [ | ||
| AITool( | ||
| key=tool['key'], | ||
| version=tool.get('version', 0), | ||
| instructions=tool.get('instructions'), | ||
| examples=tool.get('examples'), | ||
| custom_parameters=tool.get('customParameters'), | ||
| ) | ||
| for tool in variation['tools'] | ||
| if isinstance(tool, dict) and 'key' in tool | ||
| ] or None | ||
|
|
||
| return AIAgentConfig( | ||
| key=key, | ||
| enabled=bool(enabled) if enabled is not None else (default.enabled or False), | ||
| model=model or default.model, | ||
| provider=provider or default.provider, | ||
| instructions=final_instructions, | ||
| tools=tools if tools is not None else (default.tools if default.tools else None), | ||
| tracker=tracker, | ||
| judge_configuration=judge_configuration or default.judge_configuration, | ||
| ) | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.