pycharm 集成Continue、ollama、DeepSeek 与硅基流动平台

一、Continue插件安装

  1. 打开pycharm,进入 File > Settings > Plugins,搜索 Continue 并安装

在这里插入图片描述

  1. 重启 pycharm 完成激活

    ”This file does not belong to the project“ 时,选择"This file",然后确定。

在这里插入图片描述

二、Continue插件配置

1.打开config 配置文件方法

在这里插入图片描述

2.remote ollama 配置

Continue 插件配置信息修改

config.json 中配置信息部分如下:

{
  "models": [
    {
      // title 可以自己随便定义
      "title": "deepseek-ai-remote/DeepSeek-R1-1.5b", 
      // model 为ollama 中已有模型
      "model": "deepseek-r1:1.5b",
      // 模型提供商写ollama
      "provider": "ollama",
      // remote ollama 的ip地址,端口号默认是11434  
      "apiBase": "http://<my endpoint>:11434"
    }
   ]
}

配置信息写入更新后(仅替换默认config 文件中的"models"部分即可),重启pycharm即可。

3.硅基流动配置

1.首先在硅基流动官网 完成注册;

2.在个人中心 > API 密钥 中创建 API Key

在这里插入图片描述

3.Continue 插件配置信息修改

结构化后的硅基流动 config 配置文件如下

在这里插入图片描述

包含remote ollama 配置和硅基流动配置的config 文件如下

{
  "models": [
    {
      "title": "deepseek-ai-remote/DeepSeek-R1-1.5b",
      "model": "deepseek-r1:1.5b",
      "provider": "ollama",
      "apiBase": "http://<my endpoint>:11434"
    },
    {
      "title": "deepseek-ai/DeepSeek-R1",
      "model": "deepseek-ai/DeepSeek-R1",
      "contextLength": 30000,
      "provider": "openai",
      "apiBase": "https://api.siliconflow.cn/v1",
      "apiKey": "sk-***********************************************",
      "requestOptions": {
        "extraBodyProperties": {
          "transforms": []
        }
      }
    },
    {
      "title": "deepseek-ai/DeepSeek-V3",
      "model": "deepseek-ai/DeepSeek-V3",
      "contextLength": 30000,
      "provider": "openai",
      "apiBase": "https://api.siliconflow.cn/v1",
      "apiKey": "sk-***********************************************",
      "requestOptions": {
        "extraBodyProperties": {
          "transforms": []
        }
      }
    }
  ],
  "customCommands": [
    {
      "name": "test",
      "prompt": "{{{ input }}}\n\nWrite a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.",
      "description": "Write unit tests for highlighted code"
    },
    {
      "name": "explain",
      "prompt": "{{{ input }}}\n\n详细解释所选代码。详细说明其功能、用途和工作原理。使用示例来说明您的解释。",
      "description": "解释代码"
    },
    {
      "name": "fix",
      "prompt": "{{{ input }}}\n\n分析并修复代码中的错误。提供详细的解释和解决方案,包括但不限于语法错误、逻辑错误或性能问题。确保您的解决方案是正确的,并且能够解决所有已知的问题。",
      "description": "修复代码"
    },
    {
      "name": "check",
      "prompt": "{{{ input }}}\n\n请阅读突出显示的代码并检查是否有任何错误。您应该查找以下内容并保持高度警惕:\n- 语法错误\n- 逻辑错误\n- 安全漏洞\n- 性能问题\n- 任何其他看似错误的内容\n\n一旦您发现错误,请尽可能清楚地解释,但不要使用多余的词语。例如,不要说“我认为第 5 行有一个语法错误”,而应该说“第 5 行有语法错误”。针对发现的每个错误,给出一个要点作为答案。",
      "description": "检查代码是否存在错误"
    }
  ],
  "tabAutocompleteModel": [
    {
      "title": "deepseek-ai/DeepSeek-V3",
      "provider": "openai",
      "model": "deepseek-ai/DeepSeek-V3",
      "contextLength": 30000,
      "apiBase": "https://api.siliconflow.cn/v1",
      "apiKey": "sk-***********************************************",
      "useLegacyCompletionsEndpoint": false
    }
  ],
  "contextProviders": [
    {
      "name": "code",
      "params": {
        "nRetrieve": 25,
        "nFinal": 5,
        "useReranking": true
      },
      "useLegacyCompletionsEndpoint": false
    },
    {
      "name": "docs",
      "params": {}
    },
    {
      "name": "diff",
      "params": {
        "nRetrieve": 25,
        "nFinal": 5,
        "useReranking": true
      },
      "useLegacyCompletionsEndpoint": false
    },
    {
      "name": "terminal",
      "params": {}
    },
    {
      "name": "problems",
      "params": {}
    },
    {
      "name": "folder",
      "params": {}
    },
    {
      "name": "codebase",
      "params": {
        "nRetrieve": 25,
        "nFinal": 5,
        "useReranking": true
      },
      "useLegacyCompletionsEndpoint": false
    }
  ],
  "slashCommands": [
    {
      "name": "share",
      "description": "Export the current chat session to markdown"
    },
    {
      "name": "cmd",
      "description": "Generate a shell command"
    },
    {
      "name": "commit",
      "description": "Generate a git commit message"
    },
    {
      "name": "edit",
      "description": "Edit selected code"
    },
    {
      "name": "comment",
      "description": "Write comments for the selected code"
    }
  ],
  "embeddingsProvider": {
    "provider": "openai",
    "model": "BAAI/bge-m3",
    "apiBase": "https://api.siliconflow.cn/v1",
    "apiKey": "sk-***********************************************"
  },
  "rerank": {
    "title": "BAAI/bge-reranker-v2-m3",
    "model": "BAAI/bge-reranker-v2-m3",
    "provider": "openai",
    "apiBase": "https://api.siliconflow.cn/v1",
    "apiKey": "sk-***********************************************"
  },
  "tabAutocompleteOptions": {
    "template": "Please teach me what I should write in the `hole` tag, but without any further explanation and code backticks, i.e., as if you are directly outputting to a code editor. It can be codes or comments or strings. Don't provide existing & repetitive codes. If the provided prefix and suffix contain incomplete code and statement, your response should be able to be directly concatenated to the provided prefix and suffix. Also note that I may tell you what I'd like to write inside comments. \n{{{prefix}}}<hole></hole>{{{suffix}}}\n\nPlease be aware of the environment the hole is placed, e.g., inside strings or comments or code blocks, and please don't wrap your response in ```. You should always provide non-empty output.\n",
    "maxPromptTokens": 2048,
    "prefixPercentage": 0.85,
    "maxSuffixPercentage": 0.15,
    "debounceDelay": 500,
    "slidingWindowPrefixPercentage": 0.75,
    "slidingWindowSize": 350,
    "maxSnippetPercentage": 0.6,
    "recentlyEditedSimilarityThreshold": 0.3,
    "onlyMyCode": false,
    "useOtherFiles": false,
    "useRecentlyEdited": true,
    "recentLinePrefixMatchMinLength": 7
  }
}

三、continue 常用操作

1.ctrl + J 询问选中代码

在这里插入图片描述

在这里插入图片描述

2.ctrl + I 编辑代码·

在这里插入图片描述

3.通过/test 自动生成测试用例

在这里插入图片描述

4.通过/explain 进行代码解释

在这里插入图片描述

5.通过/fix进行代码修复

在这里插入图片描述

推荐链接

1.https://docs.continue.dev/customize/model-providers/ollama

2.https://github.com/continuedev/continue/issues/1175

内容概要:本文档详尽介绍了在PyCharm中接入DeepSeek API的操作流程。首先,准备工作中包括了获取DeepSeek API密钥的方法步骤,即通过注册/登录DeepSeek官网并在API管理页面创建API Key。接着,在创建PyCharm项目时需要建立新的Python项目并且推荐创建虚拟环境来安装相关依赖库如requests,此外还提供了一段示例代码用于调用DeepSeek聊天接口,涵盖了定义发送POST请求的函数及其使用方法,以及如何解析返回值。安全方面强调避免硬编码API Key可采用环境变量或配合.python-dotenv配置.env文件来保护敏感数据的安全性和保密性。为了确保代码质量和方便排错提出了利用HTTP客户端调试API和服务,同时给出了针对常见网络异常情况如权限不足(401)、速率限制(429)和服务器内部故障(500)时的解决思路。最后,介绍了有关PyCharm作为强大高效的Python集成开发环境所提供的众多特性例如项目管理、智能提示、调试代码等,并展示了如何设置字体、颜色主题以及管理和切换解释器,帮助开发者更好地使用这款工具进行软件开发。 适合人群:熟悉本编程概念并对AI领域有一定兴趣的技术爱好者、希望掌握PyCharmDeepSeek交互机制的开发者群体。 使用场景及目标:指导读者正确完成PyCharm集成DeepSeek API的所有操作,使得用户能够在自己的项目中轻松引入自然语言处理的能力,提高应用程序的功能性和用户体验。 其他说明:整个过程中涉及到的具体命令及参数可以根据官方文档进一步优化和完善;此外,在实际应用中应当遵循安全最佳实践保证个人信息和商业机密免受潜在威胁;文中还提供了关于调整编辑器外观和其他高级选项的小贴士供深入探索。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值