68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
import time
|
||
from pathlib import Path
|
||
from openai import OpenAI
|
||
import os
|
||
|
||
def upload_file(file_path):
|
||
"""
|
||
Uploads a file to DashScope and returns the file ID.
|
||
"""
|
||
client = OpenAI(
|
||
api_key=os.getenv("DASHSCOPE_API_KEY"),
|
||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||
)
|
||
file = client.files.create(file=Path(file_path), purpose="file-extract")
|
||
return file.id
|
||
|
||
def qianwen_long(file_id, user_query):
|
||
print("call qianwen-long...")
|
||
"""
|
||
Uses a previously uploaded file to generate a response based on a user query.
|
||
"""
|
||
client = OpenAI(
|
||
api_key=os.getenv("DASHSCOPE_API_KEY"),
|
||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||
)
|
||
|
||
# Generate a response based on the file ID
|
||
completion = client.chat.completions.create(
|
||
model="qwen-long",
|
||
top_p=0.5,
|
||
temperature=0.5,
|
||
messages=[
|
||
{
|
||
'role': 'system',
|
||
'content': f'fileid://{file_id}'
|
||
},
|
||
{
|
||
'role': 'user',
|
||
'content': user_query
|
||
}
|
||
],
|
||
stream=False
|
||
)
|
||
|
||
# Return the response content
|
||
return completion.choices[0].message.content
|
||
|
||
if __name__ == "__main__":
|
||
# Example file path - replace with your actual file path
|
||
|
||
file_path = "C:\\Users\\Administrator\\Desktop\\招标文件\\output1\\ztb_evaluation_method.pdf"
|
||
file_id = upload_file(file_path)
|
||
|
||
user_query1 = ("根据该文档中的评标办法前附表,请你列出该文件的技术标,商务标,投标报价评审标准以及它们对应的具体评分要求,若对应内容中存在其他信息,在嵌套键如'技术标'中新增键名'备注'存放该信息。如果评分内容不是这3个,则返回文档中给定的评分内容以及它的评分要求,都以json的格式返回结果。请不要回答有关形式、资格、响应性评审标准的内容")
|
||
user_query2 = ("请提供文件中关于资格审查的具体内容和标准。")
|
||
start_time=time.time()
|
||
# First query
|
||
print("starting qianwen-long...")
|
||
result1 = qianwen_long(file_id, user_query1)
|
||
print("First Query Result:", result1)
|
||
|
||
# # Second query
|
||
# print("starting qianwen-long...")
|
||
# result2 = qianwen_long(file_id, user_query2)
|
||
# print("Second Query Result:", result2)
|
||
# end_time=time.time()
|
||
# print("elapsed time:"+str(end_time-start_time))
|