-
Notifications
You must be signed in to change notification settings - Fork 20
feat(model/rerank): support instruct #55
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
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||||||||||||||||||||||||||||||||||||
| # 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 = "哈尔滨在哪?" | ||||||||||||||||||||||||||||||||||||||
| documents = [ | ||||||||||||||||||||||||||||||||||||||
| "黑龙江离俄罗斯很近", | ||||||||||||||||||||||||||||||||||||||
| "哈尔滨是中国黑龙江省的省会,位于中国东北" | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| response = TextReRank.call( | ||||||||||||||||||||||||||||||||||||||
| model=os.getenv("MODEL_NAME"), | ||||||||||||||||||||||||||||||||||||||
| query=query, | ||||||||||||||||||||||||||||||||||||||
| documents=documents, | ||||||||||||||||||||||||||||||||||||||
| return_documents=True, | ||||||||||||||||||||||||||||||||||||||
| top_n=5, | ||||||||||||||||||||||||||||||||||||||
| instruct="Retrieval document that can answer users query." | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| print(f'response: {response}') | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| print("\n✅ Test passed! All assertions successful.") | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+32
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. The function is named
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 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") | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+47
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. The current implementation loads environment variables from
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Run tests | ||||||||||||||||||||||||||||||||||||||
| test_text_rerank() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| print("\n🎉 All tests completed successfully!") | ||||||||||||||||||||||||||||||||||||||
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.
There appears to be a grammatical error and a typo in the
instructstring. "Retrieval" is a noun, but an instruction should typically start with a verb like "Retrieve". Also, "document" should probably be plural "documents", and "users" should be possessive "user's". Correcting this will improve clarity and may lead to better model performance.