-
Notifications
You must be signed in to change notification settings - Fork 745
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: Add SemanticScholarToolkits to integrate Semantic Scholar to camel #1493
base: master
Are you sure you want to change the base?
feat: Add SemanticScholarToolkits to integrate Semantic Scholar to camel #1493
Conversation
import json | ||
|
||
class SemanticScholarToolkit(BaseToolkit): | ||
"""A toolkit for interacting with the Semantic Scholar API to fetch paper and author data.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""A toolkit for interacting with the Semantic Scholar API to fetch paper and author data.""" | |
r"""A toolkit for interacting with the Semantic Scholar API to fetch paper and author data.""" |
"""A toolkit for interacting with the Semantic Scholar API to fetch paper and author data.""" | ||
|
||
def __init__(self): | ||
"""Initializes the SemanticScholarToolkit.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Initializes the SemanticScholarToolkit.""" | |
r"""Initializes the SemanticScholarToolkit.""" |
papers = response.json().get("recommendedPapers", []) | ||
papers.sort(key=lambda paper: paper["citationCount"], reverse=True) | ||
with open('recommended_papers_sorted.json', 'w') as output: | ||
json.dump(papers, output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we make writing to a local JSON file optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @renxinxing123 ! Please run and fix the pre-commit test, and make sure that the code and docstring are formatted correctly. Could you also add the unit test and examples under the test and examples folder please? Thanks a lot!
Many thanks for you comment @harryeqs! I will fix the error. |
Thanks! It seems there are some remaining formatting problems. You could run the pre-commit test locally using the commands.
For other contributing guidelines please refer to: https://github.com/camel-ai/camel/blob/master/CONTRIBUTING.md |
Thank you, @harryeqs! I followed your suggestion, reformatted the Semantic Scholar toolkits, and added the related test and example files. All files passed the pre-commit tests on my local machine, but it seems that several tests didn’t pass during the PR. However, the error messages in these tests are unrelated to the newly added files. |
Happy Chinese New Year! Thank you very much for the contribution @renxinxing123 . Sorry for getting back quite late as I was working on different tasks in the past few days. |
""" | ||
url = f"{self.base_url}/paper/search" | ||
query_params = {"query": paperTitle, "fields": fields} | ||
response = requests.get(url, params=query_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better if we implement error handling here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AveryYay ! Thanks for your suggestion! I noticed that the code already includes error handling for the case where the response status code is not 200, and it returns an error message accordingly.
Could you clarify if you're suggesting a different type of error handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the status code works if requests.get() successfully returns. Adding try-except could prevents crashes if the request fails due to connectivity problems. There could also be some case where the response isn't a valid JSON.
Happy Chinese New Year @harryeqs ! It doesn't matter, hope you enjoyed a good time with your family and the ones you love! The generation of the json file has been revised as an option, where is set as False as default, while user can activate it using the promt such as 'Please search the information of 'author xx', and save it in a json file'. |
Description
This PR introduces a new toolkit called SemanticScholarToolkits to integrate Semantic Scholar into CAMEL. It provides several functionalities, including searching for papers by paper ID, paper title, and keywords, and retrieving recommended papers based on a given paper ID as well as searching author by author ID. Howerver, although Semantic Scholar API is able to search dataset, this feature itself is currently non-responsive based on my testing.
Motivation and Context
Integrating Semantic Scholar into CAMEL enhances its ability to access and process academic papers and resources. This integration will make CAMEL more versatile for research-related tasks by leveraging the rich academic resources and powerful search capabilities of Semantic Scholar. This change addresses the feature request in issue #1032.
[ ] I have raised an issue to propose this change (#1032)
Types of changes
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds core functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)
[ ] Documentation (update in the documentation)
[ ] Example (update in the folder of example)
Implemented Tasks
[x] Implement search paper by paper ID
[x] Implement search paper by paper title
[x] Implement search papers by keywords
[x] Implement retrieve recommended papers by paper ID
[x] Implement search author by author ID
Checklist
[x] I have read the CONTRIBUTION guide. (required)
[ ] My change requires a change to the documentation.
[x] I have updated the tests accordingly. (required for a bug fix or a new feature)
[ ] I have updated the documentation accordingly.