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

fix: Add the error handling for Langchain transformer #2137

Merged
merged 10 commits into from
Nov 21, 2023

Conversation

sherylZhaoCode
Copy link
Contributor

@sherylZhaoCode sherylZhaoCode commented Nov 16, 2023

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

_This PR was to do error handling for the openai request, so that failure of a single row won’t result in failure of the whole spark job. _

How is this patch tested?

  • I have written tests (not required for typo or doc fix) and confirmed the proposed feature/bug-fix/change works.

Does this PR change any dependencies?

  • No. You can skip this section.
  • Yes. Make sure the dependencies are resolved correctly, and list changes here.

Does this PR add a new feature? If so, have you added samples on website?

  • No. You can skip this section.
  • Yes. Make sure you have added samples following below steps.
  1. Find the corresponding markdown file for your new feature in website/docs/documentation folder.
    Make sure you choose the correct class estimators/transformers and namespace.
  2. Follow the pattern in markdown file and add another section for your new API, including pyspark, scala (and .NET potentially) samples.
  3. Make sure the DocTable points to correct API link.
  4. Navigate to website folder, and run yarn run start to make sure the website renders correctly.
  5. Don't forget to add <!--pytest-codeblocks:cont--> before each python code blocks to enable auto-tests for python samples.
  6. Make sure the WebsiteSamplesTests job pass in the pipeline.

Copy link

Hey @sherylZhaoCode 👋!
Thank you so much for contributing to our repository 🙌.
Someone from SynapseML Team will be reviewing this pull request soon.

We use semantic commit messages to streamline the release process.
Before your pull request can be merged, you should make sure your first commit and PR title start with a semantic prefix.
This helps us to create release messages and credit you for your hard work!

Examples of commit messages with semantic prefixes:

  • fix: Fix LightGBM crashes with empty partitions
  • feat: Make HTTP on Spark back-offs configurable
  • docs: Update Spark Serving usage
  • build: Add codecov support
  • perf: improve LightGBM memory usage
  • refactor: make python code generation rely on classes
  • style: Remove nulls from CNTKModel
  • test: Add test coverage for CNTKModel

To test your commit locally, please follow our guild on building from source.
Check out the developer guide for additional guidance on testing your change.

@sherylZhaoCode sherylZhaoCode changed the title added the error handling for Langchain transformer [fix] Add the error handling for Langchain transformer Nov 16, 2023
@sherylZhaoCode sherylZhaoCode changed the title [fix] Add the error handling for Langchain transformer fix: Add the error handling for Langchain transformer Nov 16, 2023
@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@codecov-commenter
Copy link

codecov-commenter commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9195dee) 86.26% compared to head (a267cd0) 86.12%.
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2137      +/-   ##
==========================================
- Coverage   86.26%   86.12%   -0.15%     
==========================================
  Files         312      312              
  Lines       16477    16483       +6     
  Branches     1460     1462       +2     
==========================================
- Hits        14214    14196      -18     
- Misses       2263     2287      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines 232 to 234
result = error_messages[type(e)].format(e)

return result
Copy link
Collaborator

Choose a reason for hiding this comment

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

to retain parity with the other cognitive services can we make a separate error column and puts errors there if they exist? this requires a new setter, setErrorCol

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also later we'll want to automatically retry rate limit errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. So in this case, what do you think I should put in the response column? Something like "error"? And for the valid cases, what should be in the error column? Just empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the latest commit, I added an extra column with default name 'errorCol'.
The errorColumn will be empty in the case where everything is valid.
The response column will also be empty in the case of error.
Let me know if any of the above is undesirable behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect!

Copy link
Collaborator

@mhamilton723 mhamilton723 left a comment

Choose a reason for hiding this comment

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

One comment about where to put these errors so people can easily see them in their analysis and choose to filter them with spark sql

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines 100 to 101
input_col_values = [row.technology for row in transformed_df.collect()]
output_col_values = [row.copied_technology for row in transformed_df.collect()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this and other tests will run twice as fast if you collect once and then pull out the info from that collected df. Collect will retrigger whole comp unless you have the output cached

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified this according to the suggestion

# construct langchain transformer using the chain defined above. And test if the generated
# column has the expected result.
dataframes_to_test = spark.createDataFrame(
[(0, "people on disability don't deserve the money")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to put a disclaimer in the comments that this is only for triggering an error and is not our views

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a disclaimer

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

return dataset.withColumn(outCol, udfFunction(inCol))

return (
dataset.withColumn("result", udfFunction(inCol))
Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry i just noticed this, name the column result_{uid} so that this doesent break if someone already has a column called result

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sherylZhaoCode
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mhamilton723 mhamilton723 merged commit 23222c0 into master Nov 21, 2023
67 checks passed
@mhamilton723 mhamilton723 deleted the sherylZhao/add_error_handling branch November 21, 2023 12:26
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.

None yet

3 participants