Skip to content

fix: rerank error#2145

Merged
wxg0103 merged 1 commit intomainfrom
pr@main@fix_rerank
Feb 7, 2025
Merged

fix: rerank error#2145
wxg0103 merged 1 commit intomainfrom
pr@main@fix_rerank

Conversation

@shaohuzhang1
Copy link
Contributor

fix: rerank error --bug=1052035 --user=王孝刚 【模型管理】SiliconFlow的重排模型,重排后的内容不正确 https://www.tapd.cn/57709429/s/1651239

--bug=1052035 --user=王孝刚 【模型管理】SiliconFlow的重排模型,重排后的内容不正确 https://www.tapd.cn/57709429/s/1651239
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 7, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 7, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

"return_documents": True,
}

response = requests.post(f"{self.api_base}/rerank", json=payload, headers=headers)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code appears to be missing a closing bracket for the payload dictionary. Additionally, while there are no specific irregularities or clear issues with the current implementation, an optimization suggestion could be to add error handling around the API call using try-except blocks to manage exceptions related to network issues or invalid responses from the API.

Here is the corrected version of the payload:

{
    "model": self.model,
    "query": query,
    "documents": texts,
    "top_n": self.top_n,
    "return_docs": True,
}

And here is how you might incorporate error handling into the function:

import requests

def compress_documents(self, documents: Sequence[Document], query: str, callback=None):
    # ... other parts remain unchanged ...

    url = f"{self.api_base}/rerank"
    headers = {
        # Set appropriate headers here if required
    }

    try:
        response = requests.post(url, json=payload, headers=headers)
        response.raise_for_status()  # Raise an HTTPError for bad responses (4xx, 5xx status codes)
        result = response.json()
        # Process result based on needs ...
    except requests.exceptions.HTTPError as http_err:
        print(f"HTTP error occurred: {http_err}")
        return None
    except requests.exceptions.ConnectionError as conn_err:
        print(f"Connection error occurred: {conn_err}")
        return None
    except Exception as err:
        print(f"An unexpected error occurred: {err}")
        return None

    return result  # Return the processed data or handle according to business logic

This additional error handling will make the function more robust and easier to debug.

@wxg0103 wxg0103 merged commit fbe899e into main Feb 7, 2025
4 of 5 checks passed
@wxg0103 wxg0103 deleted the pr@main@fix_rerank branch February 7, 2025 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants