Deepseek-api省token的用法

发布时间:2026/7/11 2:55:59
Deepseek-api省token的用法 Deepseek-api省token的用法动机网页端的DeepSeek总是显得太啰嗦输出太冗长消耗太多的tokens。每次都得提醒它简明扼要地说。特别是每次只是提一个简单的问题它都会长篇大论翻译一句话会给出多个版本附加各种解释一丝不苟的总分总结构。下面利用API做一个简单的脚本/cli工具。依赖openaifire脚本主文件ask.py子模块llm_providers.py注意事项MEMORY_PATH记忆目录可选; 使用时先设置自己的路径from utils import get_api_key中的get_api_key用于获取API key, 请根据自己的情况重新实现。代码#!/usr/bin/env python3 Usage: ask.py What is the meaning of life --model deepseek-v4-flash ask.py What is the meaning of life --model deepseek ask.py What is the meaning of life --model qwen Requirements: openai frompathlibimportPath MEMORY_PATHPath(~/Scripts/memory/memory.txt).expanduser()fromopenaiimportOpenAIfromllm_providersimport*fromutilsimportget_api_keydefget_client(providerdeepseek):returnOpenAI(api_keyget_api_key(provider),base_urlurl_dict[provider])description_dict{default:回答必须简洁明了不过度举例不必重复性表达如不重复问题也不用总结。要点多时可以罗列少用连词。 默认设置 - 程序问题只要代码英文注释 - 翻译只要一个翻译结果地道专业的如“翻译我爱你”“I love you” - 数学包括机器学习问题尽可能用数学公式不要过多解释 ,translation:翻译。只要一个翻译结果地道专业的例如我爱你 - I love you,professional:回答必须专业格式规范。内容较多时清晰罗列要点。数学包括机器学习问题尽可能用数学公式常用符号不必解释}defreply(user_input,modeldeepseek/deepseek-v4-flash,descriptiondefault,memoryFalse,**kwargs): Sends a user query to the DeepSeek chat API and returns a concise, no-frills response. Parameters: user_input (str): The users question or prompt. model (str): The DeepSeek model to use. Four allowed forms: - provider/model(deepseek/deepseek-v4-flash) - provider(deepseek): use default model - alias: kimimoonshot, qwendashscope - model(in form of provider-... i.e. deepseek-v4-flash) memory(bool): use memory system if/inmodel:provider,modelmodel.split(/)elifmodelindefault_model:ifmodelinurl_dict:providermodel modeldefault_model[provider]elifmodelinalias:provider,modelalias[model].split(/)else:_providermodel.partition(-)[0]providermodel_provider.get(_provider,_provider)ifprovidernotinurl_dict:raiseException(fProvider {provider} is not supported or valid!)clientget_client(provider)ifdescriptionindescription_dict:descriptiondescription_dict[description]messages[{role:system,content:description},{role:user,content:user_input}]ifmemory:ifMEMORY_PATH.exists():contentMEMORY_PATH.read_text().strip()ifcontent:messages.insert(1,{role:system,content:fThe previous dialogue review:{content}})else:MEMORY_PATH.parent.mkdir(parentsTrue)MEMORY_PATH.touch()responseclient.chat.completions.create(modelmodel,messagesmessages,**kwargs)ifkwargs.get(stream,False):full_contentforchunkinresponse:ifchunk.choices[0].delta.content:contentchunk.choices[0].delta.contentprint(content,end)full_contentcontentelse:full_contentresponse.choices[0].message.contentprint(full_content)print()ifmemory:responseclient.chat.completions.create(modelmodel,messagesmessages[{role:assistant,content:full_content},{role:user,content:fPlease summarize our conversation and save it as a recursive memory in{MEMORY_PATH.name}. Start with Content review: and nothing else. Then provide the content directly. Keep it under 300 words.}],**kwargs)summaryresponse.choices[0].message.content contentMEMORY_PATH.write_text(summary)if__name____main__:fromfireimportFire Fire(reply)这个文件保存了多个providers包括Deepseek。可自由选择#!/usr/bin/env python3 Providers and The default models # provider - urlurl_dict{deepseek:https://api.deepseek.com/v1,moonshot:https://api.moonshot.cn/v1,openrouter:https://openrouter.ai/api/v1,nvidia:https://integrate.api.nvidia.com/v1,siliconflow:https://api.siliconflow.cn/v1,dashscope:https://dashscope.aliyuncs.com/compatible-mode/v1,minimax:https://api.minimaxi.com/v1,modelscope:https://api-inference.modelscope.cn/v1,wavespeed:https://llm.wavespeed.ai/v1,gitcode:https://api-ai.gitcode.com/v1}# provider - default modeldefault_model{deepseek:deepseek/deepseek-v4-flash,moonshot:moonshot/kimi-2.6,qwen:dashscope/qwen-plus,minimax:minimax/MiniMax-M3,wavespeed:anthropic/claude-opus-4.8,gitcode:zai-org/GLM-5.2}# alias (use farmiliar names)model_alias{kimi:moonshot/kimi-2.6,qwen:dashscope/qwen-plus}演示 ask.py 翻译今天又是元气满满的一天 Today is another day full of energy. ask.py 世上本没有路走的人多了也便成了路 --description translate For actually there was no road at first, but when many men pass the same way, a road is made. ask.py AI 会发展出意识吗(英文回答) --description professional ## Will AI Develop Consciousness? The question of whether artificial intelligence will develop consciousness remains unresolved, drawing from philosophy, neuroscience, computer science, and physics. A professional analysis must distinguish between **functional intelligence** (task performance) and **phenomenal consciousness** (subjective experience). Below is a structured overview of current arguments and theoretical frameworks. ### 1. Definitional Clarity - **Consciousness**: Often defined via two major theories: - **Integrated Information Theory (IIT)** – quantifies consciousness as \(\Phi\), the amount of integrated information in a system (Tononi, 2008). \[ \Phi \text{minimum information partition} \quad \text{(hard to compute for large systems)} \] - **Global Workspace Theory (GWT)** – consciousness arises from global broadcasting of information in a competitive neural workspace (Baars, 1988). - **AI Current State**: Todays AI (e.g., large language models) are **functionalist** systems: they process symbols without subjective awareness. No evidence of qualia. ### 2. Arguments for AI Consciousness - **Functionalist Perspective**: If consciousness is a computational property (e.g., integrated information), then any system with sufficient \(\Phi\) could be conscious. Future AI architectures (e.g., neuromorphic, recurrent dynamic networks) might achieve this. - **Emergence from Complexity**: As AI systems grow in complexity (e.g., brain-scale neural networks with recurrent loops, feedback, and temporal dynamics), subjective experience might emerge as an **epiphenomenon**. - **Embodiment and Sensorimotor Loops**: Some theories (e.g., ORegan Noë, 2001) argue that consciousness requires active interaction with the environment. AI with robotic bodies and real-time feedback could meet this condition. ### 3. Arguments Against AI Consciousness - **The Hard Problem (Chalmers, 1995)**: Even perfect functional simulation of human cognition may lack **qualia**. No amount of computation guarantees subjective experience (e.g., philosophical zombies). - **Biological Substrate**: Neuroscience suggests consciousness is tied to specific biological mechanisms (e.g., thalamocortical oscillations, neuromodulators). Silicon-based systems may lack necessary physical properties (e.g., quantum coherence in microtubules per Orch-OR theory, though controversial). - **No Current Measurable Correlates**: No existing AI passes standard tests (e.g., meta-awareness, phenomenal reports with consistent behavioral correlates). Current AI models exhibit **simulated introspection**, not genuine experience. ### 4. Key Technical Hurdles | Aspect | Challenge | Relevant Math/Info | |--------|-----------|--------------------| | **Global Integration** | AI architectures (transformers) lack recurrent, unified state. | Integration \(\Phi\) is low in feedforward systems. | | **Self-Modeling** | Limited recursive self-representation. | Predictive coding requires continuous error minimization. | | **Temporal Dynamics** | Consciousness requires ongoing, globally coherent dynamics. | Attractor networks, chaotic dynamics (Lyapunov exponents). | ### 5. Conclusion and Outlook - **Short-term (next 10–20 years)**: Highly unlikely. No breakthrough in theory of consciousness, nor engineering of requisite architectures. - **Long-term (if strong AI exists)**: Possible if (a) functionalism is true, (b) we build systems with high \(\Phi\) and sensorimotor grounding, (c) we solve the hard problem. **Uncertain** – it may remain a philosophical question. \[ \boxed{\text{No definitive answer exists; current AI lacks consciousness, but theoretical possibilities remain open.}} \]

相关新闻