auto_score/original.py

54 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import openai
import time
import re
import sys
model = "Qwen/Qwen3-8B"
max_tokens = 500
output_format = """
score:
reason:
"""
def getDim(content, dim):
client = openai.OpenAI(base_url='https://api.siliconflow.cn/v1',
api_key="xxx")
time.sleep(3)
messages = []
messages.append({
"role": "system",
"content": "你是一位评分老师,请根据提供给你的评分标准对文本进行评分,结果仅仅输出分数,满分为10分,分数允许小数点后保留两位,并就当前维度给出评语,评语文本不要过长。"
"输出格式:"
f"{output_format}"
})
messages.append({
"role": "user",
"content": f"待评分内容:{content}"
f"评分标准:{dim}"
})
response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=max_tokens,
temperature=0.1
)
# print(response.choices[0].message.content)
# match = re.search(r'\d+', response.choices[0].message.content)
# if match:
# score = match.group()
# else:
# score = response.choices[0].message.content
# print(score)
# 去除多余的换行符
content = response.choices[0].message.content.strip()
return content
if __name__ == "__main__":
content = sys.argv[1]
dim = sys.argv[2]
result = getDim(content, dim)
print(result)