[EAGLE-6237]: update code snippets for MCP/OpenAI and make env vars take precedence#607
Merged
[EAGLE-6237]: update code snippets for MCP/OpenAI and make env vars take precedence#607
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances configuration defaults, URL generation, and client script templates to support MCP-hosted and OpenAI-compatible models.
- Adds default UI/base fallbacks in
Contextand new transport constants. - Introduces
mcp_api_urlandopenai_api_urlhelpers. - Updates
generate_client_scriptto branch on transport signatures using context, and updates UI URL construction in model/CLI modules.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| clarifai/utils/constants.py | Added MCP_TRANSPORT_NAME and OPENAI_TRANSPORT_NAME constants |
| clarifai/utils/config.py | Imported DEFAULT_UI/DEFAULT_BASE and extended fallback logic |
| clarifai/urls/helper.py | Added mcp_api_url and openai_api_url methods |
| clarifai/runners/utils/code_script.py | Added has_signature_method, context‐based script generation |
| clarifai/client/model.py | Updated URL template to use current.ui from context |
| clarifai/cli/model.py | Changed log to include full UI URL |
Comments suppressed due to low confidence (4)
clarifai/runners/utils/code_script.py:13
- The
Listtype is used here but not imported; addfrom typing import Listat the top of the file to avoid a NameError.
name: str, method_signatures: List[resources_pb2.MethodSignature]
clarifai/runners/utils/code_script.py:7
auth_objisn't defined or exported fromclarifai.urls.helper; ensure you import the correct auth helper (e.g.default_auth) or defineauth_obj.
from clarifai.urls.helper import ClarifaiUrlHelper, auth_obj
clarifai/client/model.py:133
current.uialready includes the protocol (e.g. "https://"); usingf"https://{current.ui}/..."will double the prefix. Remove the hardcodedhttps://or normalizecurrent.uito exclude it.
url = f"https://{current.ui}/{current.user_id}/{current.app_id}/models/{current.model_id}"
clarifai/urls/helper.py:100
- [nitpick] Fix typos: change "incldue" to "include" and "you an set" to "you can set" for clarity.
It also doesn't incldue the model which you an set as the model arg in an openAI client call
Minimum allowed line rate is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces enhancements to the configuration handling, URL generation, and client script generation in the Clarifai codebase. The changes improve flexibility by introducing new default values, methods for constructing URLs for specific endpoints, and updated logic for generating client scripts based on context and method signatures.
Configuration Enhancements:
DEFAULT_UIandDEFAULT_BASE) in theContextclass when environment variables are not set. This ensures a more robust configuration handling process.__getattr__inContextto prioritize environment variables over configuration values and provide detailed error messages for missing attributes.URL Generation Improvements:
mcp_api_urlandopenai_api_urlmethods inClarifaiUrlHelperto generate URLs for MCP-hosted models and OpenAI-compatible models, respectively. These methods streamline URL creation for specific use cases.Client Script Generation Updates:
generate_client_scriptto support context-based URL generation usingConfigandClarifaiUrlHelper. This allows dynamic selection of API endpoints based on the context.Constants and Utilities:
MCP_TRANSPORT_NAMEandOPENAI_TRANSPORT_NAMEtoclarifai/utils/constants.pyfor identifying specific transport methods.has_signature_methodto check for the existence of specific method signatures in a list.These changes collectively enhance the configurability, extensibility, and usability of the Clarifai codebase.