From ea532373ec6b5253bb25af008c68cedc7bc4861d Mon Sep 17 00:00:00 2001 From: liwenyun Date: Mon, 2 Dec 2024 18:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20evaluation.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- evaluation.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/evaluation.py b/evaluation.py index 2701b7e..7fe71ad 100644 --- a/evaluation.py +++ b/evaluation.py @@ -3,7 +3,6 @@ import openai import time import json import argparse -import tiktoken from openai import OpenAI from openai import OpenAIError @@ -61,19 +60,9 @@ def get_qa_response(model, question, answer): -def num_tokens_from_message(message, model="davinci"): - encoding = tiktoken.encoding_for_model(model) - num_tokens = len(encoding.encode(message)) - return num_tokens -def truncate_message(prompt1, prompt2, model="davinci"): - if num_tokens_from_message(prompt1 + prompt2, model) > 2033: - truncation_length = 2033 - num_tokens_from_message(prompt2) - while num_tokens_from_message(prompt1) > truncation_length: - prompt1 = " ".join(prompt1.split()[:-1]) - prompt = prompt1 + prompt2 - return prompt +