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

feat: implement jinja templating and rename kwarg to context #1011

Merged
merged 13 commits into from
Sep 25, 2024

Conversation

jxnl
Copy link
Collaborator

@jxnl jxnl commented Sep 20, 2024

Important

Integrates Jinja templating, adds context parameter, deprecates validation_context, and adds new tests.

  • Jinja Templating: Integrates Jinja templating in client.py and patch.py for prompt formatting. Adds context parameter to methods in client.py. Deprecates validation_context.
  • Functionality: Implements handle_context and handle_templating in patch.py. Updates from_response in function_calls.py to use context.
  • Testing: Adds tests in test_validation_context.py for context handling and test_formatting.py for Jinja templating.
  • Miscellaneous: Updates docstrings and comments across various files.

This description was created by Ellipsis for d889b15. It will automatically update as commits are pushed.

@jxnl jxnl requested a review from ivanleomk September 20, 2024 14:57
Copy link

cloudflare-workers-and-pages bot commented Sep 20, 2024

Deploying instructor with  Cloudflare Pages  Cloudflare Pages

Latest commit: d889b15
Status: ✅  Deploy successful!
Preview URL: https://ff02e471.instructor.pages.dev
Branch Preview URL: https://jinja-support.instructor.pages.dev

View logs

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to a03109c in 57 seconds

More details
  • Looked at 1168 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 10 drafted comments based on config settings.
1. instructor/function_calls.py:108
  • Draft comment:
    The parameter validation_context is still being used here without handling its deprecation. Consider using the handle_context function to manage the transition from validation_context to context.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The PR introduces a new context parameter and deprecates validation_context. However, there are still instances where validation_context is used without a deprecation warning or handling. This should be addressed to ensure consistency and proper deprecation handling.
2. instructor/process_response.py:106
  • Draft comment:
    The parameter validation_context is still being used here without handling its deprecation. Consider using the handle_context function to manage the transition from validation_context to context.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The PR introduces a new context parameter and deprecates validation_context. However, there are still instances where validation_context is used without a deprecation warning or handling. This should be addressed to ensure consistency and proper deprecation handling.
3. instructor/retry.py:187
  • Draft comment:
    The parameter validation_context is still being used here without handling its deprecation. Consider using the handle_context function to manage the transition from validation_context to context.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The PR introduces a new context parameter and deprecates validation_context. However, there are still instances where validation_context is used without a deprecation warning or handling. This should be addressed to ensure consistency and proper deprecation handling.
4. instructor/retry.py:266
  • Draft comment:
    The parameter validation_context is still being used here without handling its deprecation. Consider using the handle_context function to manage the transition from validation_context to context.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The PR introduces a new context parameter and deprecates validation_context. However, there are still instances where validation_context is used without a deprecation warning or handling. This should be addressed to ensure consistency and proper deprecation handling.
5. docs/blog/posts/jinja-proposal.md:1
  • Draft comment:
    The new jinja-proposal.md file should be added to the mkdocs.yml to ensure it is included in the documentation.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The new jinja-proposal.md file should be added to the mkdocs.yml to ensure it is included in the documentation.
6. instructor/client.py:65
  • Draft comment:
    The validation_context parameter is deprecated. Consider updating to use context instead. This applies to other overloads in this file as well.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The create method in instructor/client.py has multiple overloads with the validation_context parameter, which is deprecated. It should be updated to use context instead.
7. instructor/function_calls.py:108
  • Draft comment:
    The validation_context parameter is deprecated. Consider updating to use context instead.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The validation_context parameter is deprecated and should be updated to use context instead in the from_response method.
8. instructor/patch.py:55
  • Draft comment:
    Ensure that the handle_context function reflects the deprecation of validation_context.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The handle_context function in instructor/patch.py is handling both context and validation_context. Since validation_context is deprecated, ensure that the function is updated to reflect this change.
9. instructor/process_response.py:106
  • Draft comment:
    The validation_context parameter is deprecated. Consider updating to use context instead. This applies to other functions in this file as well.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The process_response function in instructor/process_response.py uses validation_context, which is deprecated. It should be updated to use context instead.
10. instructor/retry.py:187
  • Draft comment:
    The validation_context parameter is deprecated. Consider updating to use context instead. This applies to other functions in this file as well.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The retry_sync function in instructor/retry.py uses validation_context, which is deprecated. It should be updated to use context instead.

Workflow ID: wflow_vHNotWBouDNKSyNt


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 6c85df2 in 35 seconds

More details
  • Looked at 38 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. instructor/patch.py:163
  • Draft comment:
    validation_context is deprecated. Consider updating to use context instead, as per the PR description.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The PR description mentions deprecating validation_context in favor of context. However, the process_response_async and process_response functions still use validation_context. This should be updated to reflect the new context parameter.
2. instructor/process_response.py:22
  • Draft comment:
    The validation_context parameter is deprecated. Consider updating this to use context instead, and handle the deprecation accordingly.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The validation_context parameter is deprecated and replaced by context. However, the process_response_async and process_response functions still use validation_context without any deprecation warning or handling. This should be updated to reflect the changes made in the PR.

Workflow ID: wflow_KAxgf7KCOfDN24nj


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@jxnl
Copy link
Collaborator Author

jxnl commented Sep 20, 2024

@ivanleomk oh man can you help take a look at some of these errors?

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 69cec4d in 22 seconds

More details
  • Looked at 10 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. .github/workflows/pyright.yml:47
  • Draft comment:
    Consider specifying the version for jakebailey/pyright-action to ensure consistent behavior across runs.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The removal of the 'version' key in the pyright-action step might lead to using the latest version by default, which could introduce unexpected changes or incompatibilities. It's generally a good practice to specify the version to ensure consistent behavior.
2. .github/workflows/pyright.yml:47
  • Draft comment:
    Consider specifying a version for jakebailey/pyright-action to ensure consistent behavior.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The version specification for the pyright-action has been removed, which might affect the consistency of the action's behavior.

Workflow ID: wflow_aZBYjWcEJp4ME82j


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 2f967ff in 22 seconds

More details
  • Looked at 10 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. .github/workflows/pyright.yml:49
  • Draft comment:
    Ensure that the specified Pyright version (1.1.373) is compatible with the current setup and dependencies. This is crucial for maintaining consistency and avoiding potential issues.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The version of Pyright is being set in the workflow file, which is a good practice for consistency. However, it's important to ensure that this version is compatible with the rest of the setup.
2. .github/workflows/pyright.yml:49
  • Draft comment:
    If the pyright-action version is updated, ensure the documentation reflects this change.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The version update for the pyright-action should be documented.

Workflow ID: wflow_Kqfa5ZbtcP8G8YNN


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on d7e7baa in 27 seconds

More details
  • Looked at 34 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. instructor/client_cohere.py:64
  • Draft comment:
    The validation_context parameter is deprecated and should be removed from the function signature. Update the function to rely solely on the context parameter.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_V3uJzjSWdQ20yZw8


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on a274ef2 in 27 seconds

More details
  • Looked at 18 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. instructor/patch.py:123
  • Draft comment:
    Avoid using # type:ignore unless necessary. It can hide potential type errors. This comment is also applicable on lines 124 and 126.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The use of # type:ignore is unnecessary and should be avoided unless absolutely necessary. It can hide potential type errors.

Workflow ID: wflow_FtGMHaYENG821DZ5


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 65d178f in 21 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. instructor/patch.py:245
  • Draft comment:
    Avoid using # type: ignore unless absolutely necessary. It can hide potential type issues. Consider addressing the root cause of the type warning instead.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The use of # type: ignore should be minimized as it can hide potential type issues. It's better to address the root cause of the type warning.
2. instructor/patch.py:246
  • Draft comment:
    The # type: ignore comment on the return statement might indicate a potential issue. Ensure this is necessary and document why it's ignored.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The return statement in new_create_sync has a # type: ignore comment, which might indicate a potential issue that should be addressed or documented properly.

Workflow ID: wflow_QlIygFyLipo4i9G7


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on b55e0db in 40 seconds

More details
  • Looked at 138 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. instructor/client_cohere.py:13
  • Draft comment:
    handle_cohere_templating is imported but not used in the visible changes. Ensure that its usage is correctly implemented or remove the import if unnecessary.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import statement for handle_cohere_templating was added, but the function is not used in the visible diff. This might indicate an incomplete change or a missing usage.
2. instructor/patch.py:80
  • Draft comment:
    Consider creating a copy of new_kwargs before modifying it to avoid side effects:
    new_kwargs = new_kwargs.copy()
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The handle_cohere_templating function is modifying new_kwargs directly, which could lead to unexpected side effects if new_kwargs is used elsewhere. It's better to create a copy of new_kwargs before modifying it.
3. instructor/patch.py:98
  • Draft comment:
    Consider creating a copy of messages before modifying it to avoid side effects:
    messages = [message.copy() for message in messages]
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The handle_templating function is modifying the messages list in place, which could lead to unexpected side effects if messages is used elsewhere. It's better to create a copy of messages before modifying it.
4. tests/llm/test_cohere/test_json_schema.py:100
  • Draft comment:
    Assertions should include error messages for clarity. This applies to all assertions in this file.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The assertion statements in the test cases lack error messages, which are important for debugging when tests fail.

Workflow ID: wflow_hbFDuSTOwnXiKBuE


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on d889b15 in 33 seconds

More details
  • Looked at 36 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. tests/test_formatting.py:3
  • Draft comment:
    Consider importing pytest at the top of the file to maintain consistency and avoid potential issues if pytest is used in the future.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The test file test_formatting.py is missing an import statement for pytest, which is used in the test file test_validation_context.py. This could lead to issues if pytest is used in test_formatting.py in the future.
2. tests/test_formatting.py:1
  • Draft comment:
    Add import pytest at the top of the file to ensure the tests can be run using pytest.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment suggests adding import pytest, but the test functions do not seem to use any pytest-specific features. The removal of import pytest might be intentional if the tests can run without it. The comment does not provide strong evidence that adding import pytest is necessary.
    I might be missing the context of how these tests are executed. If they are part of a larger suite that uses pytest, the import might be necessary for consistency or future use.
    The tests do not currently use pytest-specific features, so the import is not strictly necessary. If future changes require pytest, the import can be added then.
    The comment should be deleted because there is no strong evidence that import pytest is necessary for the current test functions.

Workflow ID: wflow_zrUoQR3LtF8lcVmg


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.


if "messages" in new_kwargs:
new_kwargs["messages"] = handle_templating(new_kwargs["messages"], context)
elif "message" in new_kwargs and "chat_history" in new_kwargs:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jxnl , Cohere client seems to have a separate async method in its definition, that's why we only modify the sync here.

Thoughts on this approach to help support cohere messages?

@@ -30,6 +30,25 @@ def test_parse_user_sync(client, mode):
assert resp.age == 27


@pytest.mark.parametrize("mode", modes)
def test_parse_user_sync_jinja(client, mode):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Added some jinja tests to validate that the parsing is working too

Copy link
Collaborator

@ivanleomk ivanleomk left a comment

Choose a reason for hiding this comment

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

Looks good to me with the passing cohere and openai tests

@ivanleomk ivanleomk merged commit f1fb185 into main Sep 25, 2024
14 of 15 checks passed
@ivanleomk ivanleomk deleted the jinja-support branch September 25, 2024 02:36
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.

2 participants