VS Code 使用Continue插件接入OpenAI 兼容提供商API
本文最后更新于 183 天前,其中的信息可能已经有所发展或是发生改变。

一、安装Continue插件

在 VScode 应用商店搜索 Continue – open-source AI code agent 安装插件

二、新建node项目(以项目名字 openAPI 为例,目录为 D:/openAPI)

1、新建项目文件夹 openAPI ,在该项目文件夹下打开cmd终端,输入

npm init -y  
npm install axios

2、在项目下新建 generate-config.js 文件

const axios = require('axios');
const fs = require('fs');
const path = require('path');

// 代理API地址
const apiBaseUrl = 'https://modelapi.com/v1'; //替换为你的API地址
const apiKey = 'sk-modelkey';//替换为你的API密钥

// Continue 配置文件地址
const outputPath = 'C:\\Users\\feiyang\\.continue\\config.yaml';  //替换为你的Continue 配置文件地址

// 获取模型列表
async function getModels() {
  try {
    const response = await axios.get(`${apiBaseUrl}/models`, {
      headers: {
        Authorization: `Bearer ${apiKey}`,
      },
      timeout: 20000,
    });

    // 获取模型数据
    const models = response.data.data || [];

    if (!Array.isArray(models) || models.length === 0) {
      console.log('没有获取到模型列表');
      return;
    }
    // 生成配置内容
    const config = {
      name: 'Local Config',
      version: '1.0.0',
      schema: 'v1',
      models: models.map((model) => ({
        name: model.id,
        provider: 'openai',
        model: model.id,
        apiBase: apiBaseUrl,
        apiKey: apiKey,
        useResponsesApi: false,
      })),
    };

    // 确保目录存在
    fs.mkdirSync(path.dirname(outputPath), { recursive: true });

    // 直接覆盖 Continue 配置文件
    fs.writeFileSync(outputPath, generateYaml(config), 'utf8');

    console.log(`Continue 配置文件已生成并覆盖:${outputPath}`);
    console.log(`共写入 ${config.models.length} 个模型`);
  } catch (error) {
    console.error('获取模型列表时出错:');

    if (error.response) {
      console.error('状态码:', error.response.status);
      console.error('返回内容:', error.response.data);
    } else {
      console.error(error.message);
    }
  }
}

// 生成 YAML 配置内容
function generateYaml(config) {
  let yaml = `name: ${config.name}\nversion: ${config.version}\nschema: ${config.schema}\n\nmodels:\n`;

  config.models.forEach((model, index) => {
    yaml += `  - name: ${model.name}\n`;
    yaml += `    provider: ${model.provider}\n`;
    yaml += `    model: ${model.model}\n`;
    yaml += `    apiBase: ${model.apiBase}\n`;
    yaml += `    apiKey: ${model.apiKey}\n`;
    yaml += `    useResponsesApi: ${model.useResponsesApi}\n`;

    // 最后一项后面不再额外补空行
    if (index !== config.models.length - 1) {
      yaml += ``;
    }
  });

  return yaml;
}

// 执行获取模型并生成配置文件
getModels();  

3、运行项目

node D:\openAPI\generate-config.js

就可以生成Continue的配置文件并替换Continue原有配置文件

这样就可以自动生成配置文件,不需要一个个去配置模型

三、在windows任何位置终端下更新配置文件(可选)

在项目文件夹新建bin目录 名字随意,再在该文件目录下新建upm.bat 文件,名字随意尽量简短

@echo off
node D:\openAPI\generate-config.js
timeout /t 2 /nobreak >nul

在upm.bat里面添加以上代码

将D:\openAPI\bin 添加到windows环境变量的path

打开一个新的cmd终端输入 upm 就可以更新Continue的配置文件了。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇