前言
cline
是一款可以在多个ide上运行的ai助手插件,其好用程度不输 cursor
、trae
等ai编辑器。在使用中我相信大家也已经掌握如何通过根据厂商和所提供模型,或者是通过兼容 openai
格式的 api 去配置。但是我们所属的公司内部提供的闭源模型或者内部部署的如 deepseek
模型通常是不提供 apikey
认证的,那应该怎么配置 cline
去使用呢?
这也是我最近自己的使用中遇到的问题,接下来我就简单说下我是怎么解决的。在配置apikey的界面中可以看到cline
已经提供了许多类型的 api 提供商类型,诸如下图的LM Studio
格式,其并不会要求你配置 apikey 。但是这种方式缺少了其它头信息的配置,而公司内部的按照的模型一般需要员工号作为头信息来校验。

切换到openAi 兼容的提供商格式后,可以配置其它头信息,但是要求传入apikey,如果不传则保存不会成功,但是随便给个数字的话,使用的时候通常是会报404
error。

解决之道
其实本质上cline
是通过调用接口的方式使用大模型的,那只要我们提供的接口满足cline
的提供商所要求的格式,即可配 api
供其使用,所以这里转换思路,我只要将原 api 再按照 cline 的格式封装一下即可。
那么将要求告诉 deepseek ,让他帮我写一段适配代码:
python
@app.route('/chat/v1/chat/completions', methods=['POST'])
def proxy_chat():
try:
# 获取原始请求数据
data = request.get_json()
if not data:
return jsonify({"error": "Invalid JSON payload"}), 400
# 构造上游请求参数
upstream_data = {
"model": data.get("model", "ShanekAI"),
"messages": data.get("messages", []),
"max_tokens": data.get("max_tokens", 1024),
"stream": True # 强制流式模式
}
# 可选参数传递
if "temperature" in data:
upstream_data["temperature"] = data["temperature"]
if "top_p" in data:
upstream_data["top_p"] = data["top_p"]
logger.info(f"Forwarding request to upstream: {upstream_data}")
# 发起流式请求
response = requests.post(
UPSTREAM_URL,
headers=create_upstream_headers(),
json=upstream_data,
stream=True,
timeout=TIMEOUT
)
# 验证上游响应
if response.status_code != 200:
logger.error(f"Upstream error: {response.status_code} - {response.text}")
return jsonify({"error": f"Upstream error: {response.text}"}), response.status_code
# 流式响应处理
def generate():
try:
content_type = response.headers.get('Content-Type', '')
is_sse = 'text/event-stream' in content_type.lower()
for chunk in response.iter_content(chunk_size=8192):
if chunk:
# 处理字节流到字符串的转换
chunk_str = chunk.decode('utf-8') if isinstance(chunk, bytes) else str(chunk)
if is_sse:
# 确保SSE格式正确
for line in chunk_str.splitlines():
if line.strip():
yield line + "\n"
else:
yield chunk_str
except Exception as e:
logger.error(f"Stream generation error: {str(e)}")
yield f"event: error\ndata: {str(e)}\n\n"
# 设置正确的响应头
headers = {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'X-Accel-Buffering': 'no' # 禁用Nginx缓冲
}
return Response(
generate(),
mimetype='text/event-stream',
headers=headers
)
except requests.RequestException as e:
logger.error(f"Request error: {str(e)}")
return jsonify({"error": str(e)}), 500
except Exception as e:
logger.error(f"Unexpected error: {str(e)}")
return jsonify({"error": f"Proxy error: {str(e)}"}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, threaded=True)
将其配置到cline上,可以看到在使用中我们也把cline的提示词模板给拿到了,算是意外收获了。

小结
以上就是我自己在使用cline api配置上遇到的一个小问题以及解决办法,顺便知道了cline的系统提示词是如何设计的。最后把cline提示词放在最后把(由于这个提示词有点过于大,所以下面去掉中间内容了)。
vbnet
'You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
\n\n====\n\nTOOL USE\n\nYou have access to a set of tools that are executed upon the user\'s approval. You can use one tool per message, and will receive the result of that tool use in the user\'s response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
\n\n# Tool Use Formatting\n\nTool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags.
//省略...
Prioritize these goals in a logical order.\n2. Work through these goals sequentially, utilizing available tools one at a time as necessary.
Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what\'s remaining as you go.\n3.
Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags.
First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user\'s task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value.
If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool.
DO NOT ask for more information on optional parameters if it is not provided.\n4. Once you\'ve completed the user\'s task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. `open index.html` to show the website you\'ve built.\n5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don\'t end your responses with questions or offers for further assistance.'