注:本文章只做简单介绍,完整代码请转到github仓库(https://github.com/SJYssr/CX_EXAM_python)
pip install requests websocket-client pynput tkinter
新建config.ini:
[AI_set]
type = 1 # 0关闭 1星火 2DeepSeek
[SPARK]
appid = 您的应用ID
api_secret = 您的密钥
api_key = 您的API_KEY
Spark_url = ws://spark-api.xf-yun.com/v1.1/chat
domain = general
[deepseek]
api_key = sk-your-key
model = deepseek-chat
启动方式
python demo1.py
# 双界面切换设计
main_frame = tk.Frame(root) # 主题库界面
ai_frame = tk.Frame(root) # AI问答界面
# 动态布局管理
def switch_to_ai_search():
main_frame.pack_forget()
ai_frame.pack(fill="both", expand=True)
# 星火大模型WebSocket连接
class Ws_Param:
def create_url(self):
# 生成鉴权URL
signature_sha = hmac.new(self.APISecret.encode(),
signature_origin.encode(),
digestmod=hashlib.sha256).digest()
# DeepSeek接口调用
def call_deepseek_api(key, prompt):
headers = {"Authorization": f"Bearer {key}"}
response = requests.post("https://api.deepseek.com/v1/chat/completions",
json={"model": "deepseek-chat",...})```
隐私安全:所有配置本地存储
资源占用低:内存<50MB
多场景适配:考试辅助/文档处理/编程开发
扩展性强:轻松接入新AI接口
源码地址:Github仓库(https://github.com/SJYssr/CX_EXAM_python)