-
Notifications
You must be signed in to change notification settings - Fork 2.9k
perf: Optimize code style #6277
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
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,9 +64,7 @@ def _get_chat_id(self): | |
| }).open() | ||
|
|
||
| def call_tool(self, params): | ||
| name = params["name"] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| args = params.get("arguments", {}) | ||
| # print(params) | ||
|
|
||
| payload = { | ||
| 'message': args.get('message'), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,15 @@ | |
|
|
||
| from models_provider.base_model_provider import MaxKBBaseModel | ||
|
|
||
| RESTfulClient = None | ||
| try: | ||
| from xinference.client import RESTfulClient | ||
| except ImportError: | ||
| try: | ||
| from xinference_client import RESTfulClient | ||
| except ImportError as e: | ||
| pass | ||
|
|
||
|
|
||
| class XInferenceReranker(MaxKBBaseModel, BaseDocumentCompressor): | ||
| server_url: Optional[str] | ||
|
|
@@ -31,21 +40,14 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], ** | |
|
|
||
| def compress_documents(self, documents: Sequence[Document], query: str, callbacks: Optional[Callbacks] = None) -> \ | ||
| Sequence[Document]: | ||
| if documents is None or len(documents) == 0: | ||
| return [] | ||
| client: Any | ||
| if documents is None or len(documents) == 0: | ||
| if not documents: | ||
| return [] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 删除冗余代码 |
||
| try: | ||
| from xinference.client import RESTfulClient | ||
| except ImportError: | ||
| try: | ||
| from xinference_client import RESTfulClient | ||
| except ImportError as e: | ||
| raise ImportError( | ||
| "Could not import RESTfulClient from xinference. Please install it" | ||
| " with `pip install xinference` or `pip install xinference_client`." | ||
| ) from e | ||
|
|
||
| if RESTfulClient is None: | ||
| raise ImportError( | ||
| "Could not import RESTfulClient from xinference. Please install it" | ||
| " with `pip install xinference` or `pip install xinference_client`." | ||
| ) from e | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import提到顶部去。 |
||
|
|
||
| client = RESTfulClient(self.server_url, self.api_key) | ||
| model: RESTfulRerankModelHandle = client.get_model(self.model_uid) | ||
|
|
||
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.
if-else 值相同,把 if-else 去掉。