Commit a7d83fc
Changed files (1)
src
llm
src/llm/contexts.py
@@ -99,7 +99,12 @@ async def single_context(client: Client, message: Message) -> dict:
# media.append({"type": "video_url", "video_url": {"url": b64}})
elif info["mtype"] == "document" and info["mime_type"] == "text/plain":
res = await base64_media(client, msg)
- media.append({"type": "text", "text": res["value"]})
+ media.append(
+ {
+ "type": "text",
+ "text": f"[from user]: {info['full_name']}\n[file name]: {info['file_name']}\n[file content begin]\n{res['value'].strip()}\n[file content end]",
+ }
+ )
else:
path: str = await client.download_media(msg) # type: ignore
logger.debug(f"Downloaded GPT media: {path}")
@@ -108,10 +113,15 @@ async def single_context(client: Client, message: Message) -> dict:
# elif info["mtype"] == "video":
# media.append({"type": "video_url", "video_url": {"url": f"{GPT.MEDIA_SERVER}/{Path(path).name}"}})
elif info["mtype"] == "document" and info["mime_type"] == "text/plain":
- media.append({"type": "text", "text": Path(path).read_text()})
+ media.append(
+ {
+ "type": "text",
+ "text": f"[from user]: {info['full_name']}\n[file name]: {info['file_name']}\n[file content begin]\n{Path(path).read_text().strip()}\n[file content end]",
+ }
+ )
Path(path).unlink(missing_ok=True)
if msg_text:
- media.append({"type": "text", "text": msg_text})
+ media.append({"type": "text", "text": f"[from user]: {info['full_name']}\n[message begin]\n{msg_text}\n[message end]"})
except Exception as e:
logger.warning(f"Download media from message failed: {e}")
continue