mirror of
https://github.com/artiemis/artemis.git
synced 2026-02-14 08:31:55 +00:00
prompt
This commit is contained in:
parent
af202e8014
commit
46b25d9a67
@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
@ -12,6 +11,7 @@ from discord.ext import commands
|
|||||||
from huggingface_hub import AsyncInferenceClient
|
from huggingface_hub import AsyncInferenceClient
|
||||||
|
|
||||||
from artemis.utils import config
|
from artemis.utils import config
|
||||||
|
from artemis.utils.constants import TEMP_DIR
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -107,10 +107,12 @@ class Chat(commands.Cog):
|
|||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
|
|
||||||
def read_prompt(self):
|
def read_prompt(self):
|
||||||
return Path("temp/prompt").read_text() if Path("temp/prompt").exists() else ""
|
path = TEMP_DIR / "prompt"
|
||||||
|
return path.read_text() if path.exists() else ""
|
||||||
|
|
||||||
def write_prompt(self, prompt: str):
|
def write_prompt(self, prompt: str):
|
||||||
Path("temp/prompt").write_text(prompt)
|
path = TEMP_DIR / "prompt"
|
||||||
|
path.write_text(prompt)
|
||||||
|
|
||||||
def replace_emojis(self, text: str) -> str:
|
def replace_emojis(self, text: str) -> str:
|
||||||
return EMOJI_RE.sub(lambda match: emoji_map[match.group(0)], text)
|
return EMOJI_RE.sub(lambda match: emoji_map[match.group(0)], text)
|
||||||
@ -210,8 +212,12 @@ class Chat(commands.Cog):
|
|||||||
async def _prompt(self, ctx: commands.Context, *, prompt: str = None):
|
async def _prompt(self, ctx: commands.Context, *, prompt: str = None):
|
||||||
"""Get or set system prompt and reset chat memory."""
|
"""Get or set system prompt and reset chat memory."""
|
||||||
if not prompt:
|
if not prompt:
|
||||||
await ctx.send(self.prompt)
|
await ctx.send(repr(self.prompt) if len(self.prompt) > 0 else "No prompt set.")
|
||||||
return
|
elif prompt == "reset":
|
||||||
|
self.prompt = ""
|
||||||
|
self.write_prompt(self.prompt)
|
||||||
|
await ctx.send("Prompt reset.")
|
||||||
|
else:
|
||||||
self.prompt = prompt
|
self.prompt = prompt
|
||||||
self.write_prompt(prompt)
|
self.write_prompt(prompt)
|
||||||
self.memory = []
|
self.memory = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user