Commit a3fedeb
Changed files (2)
src
ai
src/ai/texts/contexts.py
@@ -21,7 +21,7 @@ from ai.utils import BOT_TIPS, clean_context
from asr.utils import GEMINI_AUDIO_EXT, downsampe_audio
from config import AI, DOWNLOAD_DIR, TID
from database.r2 import head_cf_r2, set_cf_r2
-from messages.parser import get_thread_id, parse_msg
+from messages.parser import parse_msg
from utils import convert_md, read_text
if TYPE_CHECKING:
@@ -144,8 +144,7 @@ async def get_openai_response_contexts(client: Client, message: Message, params:
api_key = params["api_key"]
model_id = params["model_id"]
key_hash = hashlib.sha256(api_key.encode()).hexdigest()
- tid = get_thread_id(msg)
- resp = await head_cf_r2(f"TTL/{cache_day}d/OpenAI/{msg.chat.id}/{msg.id}{'/' + str(tid) if tid else ''}/{model_id}/{key_hash}")
+ resp = await head_cf_r2(f"TTL/{cache_day}d/OpenAI/{msg.chat.id}/{msg.id}/{model_id}/{key_hash}")
return glom(resp, "Metadata.response_id", default="") or ""
previous_response_id = ""
@@ -278,8 +277,7 @@ async def get_openai_file_id(client: Client, message: Message, params: dict) ->
api_key = params["api_key"]
model_id = params["model_id"]
key_hash = hashlib.sha256(api_key.encode()).hexdigest()
- tid = get_thread_id(message)
- r2_key = f"TTL/{cache_day}d/OpenAI/{message.chat.id}/{message.id}{'/' + str(tid) if tid else ''}/{model_id}/{key_hash}-file_id"
+ r2_key = f"TTL/{cache_day}d/OpenAI/{message.chat.id}/{message.id}/{model_id}/{key_hash}-file_id"
r2 = await head_cf_r2(r2_key)
if file_id := glom(r2, "Metadata.file_id", default=""):
return file_id
@@ -473,9 +471,8 @@ async def single_anthropic_context(
async def get_anthropic_file_id(client: Client, message: Message, anthropic: AsyncAnthropic, cache_hour: int) -> str:
api_key: str = anthropic.api_key # ty:ignore[invalid-assignment]
key_hash = hashlib.sha256(api_key.encode()).hexdigest()
- tid = get_thread_id(message)
cache_hour = cache_hour or 12
- r2_key = f"TTL/{cache_hour}h/Anthropic/{key_hash}/{message.chat.id}/{message.id}{'/' + str(tid) if tid else ''}-file_id"
+ r2_key = f"TTL/{cache_hour}h/Anthropic/{key_hash}/{message.chat.id}/{message.id}-file_id"
r2 = await head_cf_r2(r2_key)
if file_id := glom(r2, "Metadata.file_id", default=""):
return file_id
src/ai/texts/openai_response.py
@@ -18,7 +18,6 @@ from ai.texts.contexts import get_openai_response_contexts
from ai.utils import BOT_TIPS, EMOJI_REASONING_BEGIN, EMOJI_TEXT_BOT, beautify_llm_response, deep_merge, literal_eval, load_skills, trim_none
from config import AI, PROXY, TEXT_LENGTH
from database.r2 import set_cf_r2
-from messages.parser import get_thread_id
from messages.progress import modify_progress
from messages.utils import blockquote, count_without_entities, delete_message, quote, smart_split
from utils import number_to_emoji, strings_list
@@ -128,9 +127,8 @@ async def openai_responses_api(
day = round(cache_response_ttl // 86400)
for sent_msg in sent_messages: # save the reponse to R2
key_hash = hashlib.sha256(api_key.encode()).hexdigest()
- tid = get_thread_id(sent_msg)
await set_cf_r2(
- f"TTL/{day}d/OpenAI/{sent_msg.chat.id}/{sent_msg.id}{'/' + str(tid) if tid else ''}/{model_id}/{key_hash}",
+ f"TTL/{day}d/OpenAI/{sent_msg.chat.id}/{sent_msg.id}/{model_id}/{key_hash}",
data=resp["full_response"],
metadata={"response_id": resp["response_id"]},
silent=silent,