| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- 调试rerank请求差异
- """
- import requests
- import json
- url = "http://192.168.91.253:9004/v1/rerank"
- prefix = '<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be "yes" or "no".<|im_end|>\n<|im_start|>user\n'
- suffix = "<|im_end|>\n<|im_start|>assistant\n"
- query_template = "{prefix}<Instruct>: {instruction}\n<Query>: {query}\n"
- document_template = "<Document>: {doc}{suffix}"
- instruction = "Given a web search query, retrieve relevant passages that answer the query"
- query = "什么是大语言模型?"
- candidates = [
- "Qwen 是阿里巴巴推出的大模型系列。",
- "今天天气很好,适合出去玩。",
- "大语言模型是一种基于Transformer的模型",
- "vegetable"
- ]
- # 格式化
- formatted_query = query_template.format(prefix=prefix, instruction=instruction, query=query)
- formatted_documents = [document_template.format(doc=doc, suffix=suffix) for doc in candidates]
- print("=" * 80)
- print("请求数据:")
- print("=" * 80)
- request_data = {
- "query": formatted_query,
- "documents": formatted_documents
- }
- print(json.dumps(request_data, ensure_ascii=False, indent=2))
- print("\n" + "=" * 80)
- print("发送请求...")
- print("=" * 80)
- response = requests.post(url, json=request_data).json()
- print("\n" + "=" * 80)
- print("响应结果:")
- print("=" * 80)
- print(json.dumps(response, ensure_ascii=False, indent=2))
- print("\n" + "=" * 80)
- print("关键信息:")
- print("=" * 80)
- if "results" in response:
- for idx, result in enumerate(response["results"]):
- print(f"排名{idx+1}: index={result['index']}, score={result['relevance_score']:.6f}")
- print(f" 文档预览: {result['document']['text'][:50]}...")
|