Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions samples/test_text_rerank.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Copyright (c) Alibaba, Inc. and its affiliates.

import os
import sys

# Add the project root to Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from dashscope import TextReRank


def test_text_rerank():
"""Test text rerank API with instruct parameter."""
query = "哈尔滨在哪?"
Expand All @@ -27,26 +22,10 @@ def test_text_rerank():
instruct="Retrieval document that can answer users query."
)

print(f'response: {response}')

print("\n✅ Test passed! All assertions successful.")
print(f'response:\n{response}')

except Exception as e:
print(f"❌ Test failed with error: {str(e)}")
raise

if __name__ == "__main__":
# Load environment variables if .env file exists
try:
with open(os.path.expanduser('~/.env'), 'r') as f:
for line in f:
if line.strip() and not line.startswith('#'):
key, value = line.strip().split('=', 1)
os.environ[key] = value
except FileNotFoundError:
print("No .env file found, using system environment variables")

# Run tests
test_text_rerank()

print("\n🎉 All tests completed successfully!")
test_text_rerank()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

According to PEP 8, files should end with a single newline.1 This is a common convention that prevents issues with some tools and file manipulations.

Suggested change
test_text_rerank()
test_text_rerank()

Style Guide References

Footnotes

  1. PEP 8 (Style Guide for Python Code) recommends that all files should end with a single newline character. This is often flagged as warning W292 by linters.