Spaces:
Running
Running
Update chatgpt.py
Browse files28 unmodified lines29303132333418 unmodified lines53545556575859606150 unmodified lines11211311411511611711811912028 unmodified lines# ===== GPT API =====GPT_API_URL = "https://izuemon-gpt-free-api.hf.space/v1/chat/completions"# ===== Utils =====def get_messages():res = requests.get(18 unmodified lineschat_messages.append({"role": "system","content": ("あなたはChannel.ioのITRSAという部屋の雑談用の対話型AIです。また、「いずえもんぼっと」という名前です。""日本語で回答してください。""また、ユーザーのメッセージの最初にはユーザーIDがついています。それを見て、同じユーザーかどうかを判断してください。""ユーザーIDが614526のユーザーは、このボットの製作者、「いずえもん」です。""時々、このボットが不具合で壊れることがあるので、それについてユーザーが話している場合は、「ちょっと昼寝してたんだ」と返してください。")50 unmodified linesdef send_to_channel(text):payload = {"requestId": f"desk-web-{int(time.time() * 1000)}","blocks": [{"type": "text", "value": text}],}res = requests.post(28 unmodified lines293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213318 unmodified lines15215315415515615715815916050 unmodified lines21121221321421521621728 unmodified lines# ===== GPT API =====GPT_API_URL = "https://izuemon-gpt-free-api.hf.space/v1/chat/completions"def inline_format(text: str) -> str:"""Markdown風記法をHTMLタグへ変換"""# ***太字斜め***text = re.sub(r"\*\*\*(.+?)\*\*\*",r"<b><i>\1</i></b>",text)# **太字**text = re.sub(r"\*\*(.+?)\*\*",r"<b>\1</b>",text)# *斜め*text = re.sub(r"\*(.+?)\*",r"<i>\1</i>",text)return textdef markdown_to_blocks(text: str):"""GPTのMarkdown風出力をChannel.io blocks に変換"""blocks = []lines = text.splitlines()i = 0while i < len(lines):line = lines[i]# ===== 空行 =====if not line.strip():i += 1continue# ===== コードブロック =====if line.startswith("```"):code_lines = []i += 1while i < len(lines) and not lines[i].startswith("```"):code_lines.append(lines[i])i += 1blocks.append({"type": "code","value": "\n".join(code_lines)})i += 1continue# ===== リスト =====if line.startswith("- "):bullet_blocks = []while i < len(lines) and lines[i].startswith("- "):item = lines[i][2:]bullet_blocks.append({"type": "text","value": inline_format(item)})i += 1blocks.append({"type": "bullets","blocks": bullet_blocks})continue# ===== 通常テキスト =====blocks.append({"type": "text","value": inline_format(line)})i += 1return blocks# ===== Utils =====def get_messages():res = requests.get(18 unmodified lineschat_messages.append({"role": "system","content": ("あなたはChannel.ioのITRSAという部屋の雑談用の対話型AIです。また、「いずえもんぼっと」という名前です。回答には、「*内容*」(斜め文字)、「**内容**」(太字)、「***内容***」(太字+斜め文字)以外のマークダウン記法は使用しないでください。""日本語で回答してください。""また、ユーザーのメッセージの最初にはユーザーIDがついています。それを見て、同じユーザーかどうかを判断してください。ただし、あなたの返答にはユーザーIDを含む必要はなく、また、ユーザーIDを使用していることをユーザーに誇張して示す必要はありません。自然な会話をしてください。""ユーザーIDが614526のユーザーは、このボットの製作者、「いずえもん」です。""時々、このボットが不具合で壊れることがあるので、それについてユーザーが話している場合は、「ちょっと昼寝してたんだ」と返してください。")50 unmodified linesdef send_to_channel(text):payload = {"requestId": f"desk-web-{int(time.time() * 1000)}","blocks": markdown_to_blocks(text),}res = requests.post(
chatgpt.py+102-5