当前位置: 首页 > java >正文

python -m build打包成为tar.gz或者whl

一个非常简单的命令行工具
在这里插入图片描述

在这里插入图片描述

体验地址

https://deepblog.net/p/482ca30d58fe4bc09fe3d8a6e9abdc58?u=csdn_lineuman&utm_source=share_project&f=link

main.py

import typer
import requests
from typing import Optional
import os
import json# 假设的 DeepSeek API 配置(需替换为实际值)
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")app = typer.Typer(help="cli tools power by DeepSeek")@app.command()
def main(message: str,model: Optional[str] = typer.Option("deepseek-chat", help="指定模型"),stream: Optional[bool] = typer.Option(False, help="流式输出"),
):"""get a reply from DeepSeek"""headers = {"Authorization": f"Bearer {DEEPSEEK_API_KEY}","Content-Type": "application/json",}data = {"model": model,"messages": [{"role": "user", "content": message}],"stream": stream,}try:if stream:# 流式输出(逐词显示)response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data, stream=True)response.raise_for_status()for chunk in response.iter_lines():if chunk:# 解码并移除可能的 "data: " 前缀chunk_str = chunk.decode("utf-8").strip()if chunk_str.startswith("data: "):chunk_str = chunk_str[6:]  # 移除 "data: "try:# 解析 JSONchunk_data = json.loads(chunk_str)# 提取内容(根据 DeepSeek API 的实际结构调整)if "choices" in chunk_data:content = chunk_data["choices"][0].get("delta", {}).get("content", "")if content:typer.echo(content, nl=False)except json.JSONDecodeError:# 忽略非 JSON 数据(如心跳信号)passelse:# 普通输出response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)response.raise_for_status()reply = response.json()["choices"][0]["message"]["content"]typer.echo(reply)except Exception as e:typer.secho(f"Error: {e}", fg=typer.colors.RED, err=True)if __name__ == "__main__":app()

pyproject.toml

[project]
name = "deep_cli"
version = "0.1.0"
description = "cli tool powered by deepseek"
authors = [{ name = "lineuman", email = "lxx" }]
requires-python = ">=3.8"
license = "MIT" dependencies = ["typer>=0.9.0","requests>=2.31.0","rich>=13.0.0",  # 可选:美化输出
][project.scripts]
deep_cli = "deep_cli.main:app"[tool.setuptools]
packages = ["deep_cli"][build-system]
requires = ["setuptools>=65.0.0"]
build-backend = "setuptools.build_meta"
http://www.xdnf.cn/news/16959.html

相关文章:

  • Qemu-NUC980(二):时钟clock代码添加
  • Redis数据库存储键值对的底层原理
  • SpringBoot相关注解
  • #Linux内存管理#缺页中断处理的核心函数是do_page_fault()的工作原理
  • Vulnhub ELECTRICAL靶机复现(附提权)
  • RPG增容2.尝试使用MMC根据游戏难度自定义更改怪物属性(三)
  • (LeetCode 面试经典 150 题) 138. 随机链表的复制 (哈希表)
  • Kotlin单例模式懒汉模式:LazyThreadSafetyMode.SYNCHRONIZED(2)
  • 深度学习(鱼书)day09--与学习相关的技巧(前三节)
  • P10816 [EC Final 2020] Namomo Subsequence|普及+
  • 机器学习实战:KNN算法全解析 - 从原理到创新应用
  • 【LeetCode 热题 100】(三)滑动窗口
  • Windows下定位Mingw编译的Qt程序崩溃堆栈
  • Python编程基础与实践:Python模块与包入门实践
  • 滚珠花键在汽车制造中有哪些高要求?
  • 什么叫湖仓一体
  • 存储过程的介绍、基本语法、delimiter的使用
  • Effective C++ 条款18:让接口容易被正确使用,不易被误用
  • Qwen3 Embedding:新一代文本表征与排序模型
  • [硬件电路-123]:模拟电路 - 信号处理电路 - 常见的高速运放芯片、典型电路、电路实施注意事项
  • 高效游戏状态管理:使用双模式位运算与数学运算
  • 网络基础实操篇-05-路由基础-最佳实践
  • WinForm之NumericUpDown控件
  • linux ssh公钥移除办法
  • Day 29: 复习
  • 保证金率(Margin Ratio)
  • Mybatis学习之获取参数值(四)
  • 力扣面试150题--回文数
  • golang——viper库学习记录
  • AWS上部署Spring Boot应用的完整指南