Skip to content
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

Add support for model aliases in script function #1164

Merged
merged 1 commit into from
Feb 21, 2025
Merged

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Feb 21, 2025

Define model aliases directly within the script function, enhancing flexibility in model management. This update allows users to specify aliases in the script, alongside existing methods like environment variables and configuration files.


Summary of Changes

  • Added support for defining model aliases in the script function:

    • Introduced a modelAliases property in the script function to define model aliases directly in scripts.
    • Updated related documentation to reflect this new configuration option.
  • 🛠️ Improved error handling for web search:

    • Enhanced error messages when no web search provider is configured, including a helpful link to the documentation.
  • 📖 Documentation updates:

    • Expanded examples and explanations for model alias configurations.
    • Clarified guidance on creating optimized web search queries in the system function.
  • 🧩 New helper function:

    • Added applyScriptModelAliases to handle model alias definitions within scripts.
  • 🗂️ Sample script added:

    • Introduced a sample script (model-alias.genai.mjs) showcasing the new modelAliases functionality.

These changes enhance flexibility in model alias configuration and improve usability and clarity in both the codebase and documentation. 🚀

AI-generated content by prd may be incorrect

Model aliases can now be defined directly in the script function.
@@ -24,7 +24,7 @@ script({
```

Model aliases can be defined as environment varialbles (through the `.env` file),
in a configuration file or through the [cli](/genaiscript/reference/cli/run).
in a configuration file, through the [cli](/genaiscript/reference/cli/run) or in the `script` function.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "environment varialbles" should be "environment variables".

AI-generated content by pr-docs-review-commit model_alias_typo may be incorrect

Answer the question in <QUERY>.`,
Search the web and answer the question in <QUERY>.
- Expand <QUERY> into an optimized search query for better results.
- Answer exclusively with live information from the web.`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should include a link to the web search documentation for better user guidance.

AI-generated content by pr-docs-review-commit web_search_error_message may be incorrect

Object.entries(script.modelAliases).forEach(([name, alias]) => {
runtimeHost.setModelAlias("script", name, alias)
})
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function applyScriptModelAliases is not used anywhere in the codebase and can be removed to clean up the code.

AI-generated content by pr-review-commit unnecessary_function may be incorrect

/**
* A list of model aliases to use.
*/
modelAliases?: Record<string, string>
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field modelAliases in the interface ModelAliasesOptions is defined but not used anywhere in the codebase and can be removed to clean up the code.

AI-generated content by pr-review-commit unused_interface_field may be incorrect

@@ -351,7 +355,7 @@ export async function runScriptInternal(
const stats = new GenerationStats("")
try {
if (options.label) trace.heading(2, options.label)
applyModelOptions(script, "script")
applyScriptModelAliases(script)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function call applyScriptModelAliases(script) is unnecessary as it's already called in the previous line. This can be simplified by removing one of the calls to avoid redundancy.

AI-generated content by pr-review-commit unnecessary_function_call may be incorrect

@pelikhan pelikhan merged commit 28868bc into main Feb 21, 2025
16 checks passed
@pelikhan pelikhan deleted the script_model_alias branch February 21, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant