Parcourir la source

更新readme,取消openrouter

关习习 il y a 1 mois
Parent
commit
365329c8f7
4 fichiers modifiés avec 39 ajouts et 70 suppressions
  1. 3 6
      README.md
  2. 33 35
      chat_model.py
  3. 1 2
      key.example.json
  4. 2 27
      main.py

+ 3 - 6
README.md

@@ -2,24 +2,21 @@
 
 安装依赖
 ```
-pip install requirements.txt
+pip install -r requirements.txt
 ```
 
 准备你的key
-前往groq,siliflow和openrouter获取对应的api_key
+前往groq和siliconflow获取对应的api_key
 
 https://console.groq.com/home
 
 https://siliconflow.cn/
 
-https://openrouter.ai/
-
 填入key.example.json中
 ```
 {
   "groq": "YOUR_GROQ_KEY",
   "siliflow": "YOUR_SILIFLOW_KEY",
-  "openrouter": "YOUR_OPENROUTER_KEY"
 }
 ```
 然后更改key.example.json为key.json
@@ -32,7 +29,7 @@ https://openrouter.ai/
 
 链接https://github.com/LLOneBot/LLOneBot/releases
 
-确保你安装好了你的comfyUI程序并启动在了本地的8000端口,如果你的comfyUI程序运行地址不在127.0.0.1:8000上,请在config.py中自己对源码url进行调整
+确保你安装好了你的comfyUI程序并启动在了本地的8188端口,如果你的comfyUI程序运行地址不在127.0.0.1:8188上,请在config.py中自己对源码url进行调整
 
 ```
 "comfyUI_ip": "127.0.0.1:8188",

+ 33 - 35
chat_model.py

@@ -13,11 +13,11 @@ max_pic_see = 1
 
 prompt_pic = config_get("prompt_pic")
 prompt_lora = config_get("prompt_lora")
+prompt_chpic = config_get("prompt_chpic")
 
 pro_good = "solo,cat ears,black_hair,black_eye,"
 pro_bad = config_get("pro_bad")
 
-openrouter_key = key_get("openrouter")
 groq_key = key_get("groq")
 siliflow_key = key_get("siliflow")
 
@@ -59,7 +59,7 @@ def AI_chat(group_id ,word ,prompt):
     try:
         ans = groq_chat(messages)
     except Exception as e:
-        ans = chat_deepseek_r1(messages)
+        ans = siliflow_chat(messages)
     ans = ans.lstrip()
     ans = ans.lstrip("猫猫:")
     while True:
@@ -69,33 +69,7 @@ def AI_chat(group_id ,word ,prompt):
             break
     return ans
 
-def chat_deepseek_r1(messages):
-    """
-    备用对话通道,https://openrouter.ai/api/v1
-    """
-    client = OpenAI(
-        base_url="https://openrouter.ai/api/v1",
-        api_key=openrouter_key,
-    )
-
-    model2 = "deepseek/deepseek-r1-distill-llama-70b:free"
-    model = "deepseek/deepseek-r1:free"
-
-    completion = client.chat.completions.create(
-        extra_headers={
-            "HTTP-Referer": "<YOUR_SITE_URL>",  # Optional. Site URL for rankings on openrouter.ai.
-            "X-Title": "<YOUR_SITE_NAME>",  # Optional. Site title for rankings on openrouter.ai.
-        },
-        model=model2,
-        stream=False,
-        messages=messages
-    )
-
-    ans = completion.choices[0].message.content
-
-    return ans
-
-def groq_chat(messages):
+def groq_chat(messages, model = "deepseek-r1-distill-llama-70b"):
     """
     主对话通道,https://api.gxx12138.space/groq/v1
     """
@@ -104,8 +78,6 @@ def groq_chat(messages):
         api_key=groq_key
     )
 
-    model = "deepseek-r1-distill-llama-70b"
-
     completion = client.chat.completions.create(
         model=model,
         stream=False,
@@ -116,7 +88,7 @@ def groq_chat(messages):
 
     return ans
 
-def siliflow_chat(messages):
+def siliflow_chat(messages, model = "THUDM/glm-4-9b-chat"):
     """
     备用对话通道,https://api.siliconflow.cn/v1'
     """
@@ -129,7 +101,7 @@ def siliflow_chat(messages):
         # 发送AI请求
         # THUDM/glm-4-9b-chat   google/gemma-2-9b-it
         response = client.chat.completions.create(
-            model="THUDM/glm-4-9b-chat",
+            model=model,
             messages=messages,
             stream=False,
             temperature=0.8,
@@ -141,7 +113,6 @@ def siliflow_chat(messages):
 
     return ans
 
-# 根据群聊内近4条消息获取绘画提示词
 def AI_get_picprompt(group_id):
     """
     群聊id自动获取群聊记录来获取绘画提示词
@@ -160,6 +131,27 @@ def AI_get_picprompt(group_id):
     ans = groq_chat(messages)
     return pro_good + ans.strip().replace("\n", "") + ","
 
+def AI_sendphoto_ornot(event):
+    """
+    AI思考链,判断是否应该发送图片
+    """
+    messages = [{'role': 'system', 'content': prompt_chpic}]
+    messages.append({'role': 'user', 'content': event})
+    client = OpenAI(
+        base_url='https://api.siliconflow.cn/v1',
+        api_key=siliflow_key
+    )
+    # 发送AI请求
+    response = client.chat.completions.create(
+        model="THUDM/glm-4-9b-chat",
+        messages=messages,
+        stream=False,
+        temperature=0.7,
+    )
+    ans = response.choices[0].message.content
+    ans = ans.lstrip()
+    print(f"图片发送决定:{ans}")
+    return ans
 
 def AI_lora_getpic_prompt(word):
     """
@@ -169,4 +161,10 @@ def AI_lora_getpic_prompt(word):
     messages = [{'role': 'system', 'content': prompt_lora}]
     messages.append({'role': 'user', 'content': word})
     ans = siliflow_chat(messages).replace(", ", ",")
-    return ans.strip().replace("\n", "") + ","
+    return ans.strip().replace("\n", "") + ","
+
+def detect_tool(message):
+    """
+    新方法,编写中
+    """
+    model = "llama-3.3-70b-versatile"

+ 1 - 2
key.example.json

@@ -1,5 +1,4 @@
 {
   "groq": "YOUR_GROQ_KEY",
-  "siliflow": "YOUR_SILIFLOW_KEY",
-  "openrouter": "YOUR_OPENROUTER_KEY"
+  "siliflow": "YOUR_SILIFLOW_KEY"
 }

+ 2 - 27
main.py

@@ -7,16 +7,14 @@ import re
 from wakeonlan import send_magic_packet
 from ai_pic import story_start, story_start_p2p, story_start_p2p_sese
 from msg_send_save import send_private_message_word,save_group_message,send_group_message_pic,send_group_message_word,send_group_poke,del_group_message
-from chat_model import AI_chat,AI_get_picprompt,AI_lora_getpic_prompt
+from chat_model import AI_chat,AI_get_picprompt,AI_lora_getpic_prompt,AI_sendphoto_ornot
 from special_date import get_week,get_v50,get_holidays
-from config import config_get,key_get
+from config import config_get
 import random
 import os
 
 app = Flask(__name__)
 
-siliflow_key = key_get('siliflow')
-
 # 读取王石列表,存为stones数据df文件
 stones = pd.read_csv('other/stone.csv')
 if 'Unnamed: 0' in stones.columns:
@@ -38,7 +36,6 @@ for i in range(len(stones)):
 my_name = config_get("my_name")
 prompt_max = config_get("prompt_max")
 prompt_less = config_get("prompt_less")
-prompt_chpic = config_get("prompt_chpic")
 
 # 一个比较没用的变量,用来限制绘画cd的,现在默认是0就是无cd
 last_request_time = 0
@@ -138,28 +135,6 @@ def ch_stone(name):
             return stones.loc[i, 'type'] +" " + stones.loc[i, 'name'] + stone_up_on + stones.loc[i, 'stat']
     return "这里似乎没有你想找的东西喵~\n如果要查找王石,请使用/王石查询正确的王石名称,示例:\n@猫猫 /王石科隆老大\n如果不清楚王石全名,可以在[掌上波多姆]中进行模糊搜索喵"
 
-def AI_sendphoto_ornot(event):
-    """
-    AI思考链,判断是否应该发送图片
-    """
-    messages = [{'role': 'system', 'content': prompt_chpic}]
-    messages.append({'role': 'user', 'content': event})
-    client = OpenAI(
-        base_url='https://api.siliconflow.cn/v1',
-        api_key=siliflow_key
-    )
-    # 发送AI请求
-    response = client.chat.completions.create(
-        model="THUDM/glm-4-9b-chat",
-        messages=messages,
-        stream=False,
-        temperature=0.7,
-    )
-    ans = response.choices[0].message.content
-    ans = ans.lstrip()
-    print(f"图片发送决定:{ans}")
-    return ans
-
 def change2setu(raw_message,group_id,user_id):
     """
     进入变瑟图命令