skip to content
Logo Logo ZhenXI Blog

New API似涌泉,万法更新汇成篇。

/ 7 min read

image-20241228002903030

一 New API介绍

New API是AI模型接口管理与分发系统,支持将多种大模型转为OpenAI格式调用、支持Midjourney Proxy、Suno、Rerank,兼容易支付协议,仅供个人或者企业内部管理与分发渠道使用,请勿用于商业用途,本项目基于One API二次开发。

二 安装New API

GitHub地址:https://github.com/Calcium-Ion/new-api

基于Doker安装:

Terminal window
# 使用 SQLite 的部署命令:
docker run --name new-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest
# 使用 MySQL 的部署命令,在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`,请自行修改数据库连接参数。
# 例如:
docker run --name new-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/new-api:/data calciumion/new-api:latest

部署成功图:

image-20240922171626989

更新New-api: image-20241118181729123

三 GitHub Models

3.1 申请GitHub Models

GitHub Models 是GitHub最新推出的模型托管服务,提供免费的AI模型供开发者测试。

申请加入https://github.com/marketplace/models/waitlist

image-20240922174354775

拥有模型:

image-20240922181133769 image-20240922181147766

申请成功后会收到一封邮件:

image-20240922174547790

3.2New API 加载 Github Models

①登录New API后进入渠道添加Github Models:

image-20240922193449974

②选择自定义渠道

③Base URL填写:https://models.inference.ai.azure.com/chat/completions

image-20240922193629322

④填写模型

image-20240922194234433

⑤填写Github token

Github Token地址:https://github.com/settings/tokens

image-20240922194333880 image-20240922194458285 image-20240922194624894

⑥测试渠道是否正常

PixPin_2024-09-22_19-54-21

⑦生成令牌

image-20240922195959056

⑧使用NextChat

image-20240922203244014

其中New API的域名请通过Nginx进行转发:

image-20240922204534364 image-20240922204553134 image-20240922204738203 image-20240922203341789

四 英伟达Llama-3.1-Nemotron-70B-Instruct

今天,英伟达又开源了一个性能超级强大的模型 —— Llama-3.1-Nemotron-70B-Instruct,它击败了 OpenAI 的 GPT-4o 等闭源模型和 Anthropic 的 Claude-3.5 sonnet 等开源模型。

从命名来看,显然 Llama-3.1-Nemotron-70B-Instruct 是基于 Llama-3.1-70B 打造而成。

在多个基准测试中,它一举超越多个最先进的 AI 模型,包括 OpenAI 的 GPT-4、GPT-4 Turbo 以及 Anthropic 的 Claude 3.5 Sonnet 等 140 多个开闭源模型。并且仅次于 OpenAI 最新模型 o1。

业内人士评价:英伟达在 Llama 3.1 的基础上训练出不太大的模型,超越了 GPT-4o 和 Claude 3.5 Sonnet,简直是神来之笔。

image-20241017235606501

4.1 通过CF创建企业邮箱

image-20241017222829469 image-20241017222839095 image-20241017222929514 image-20241017223007080

4.2 注册Nvidia

地址:https://build.nvidia.com/nvidia/llama-3_1-nemotron-70b-instruct

image-20241017223016384 image-20241017223102010 image-20241017223134675 image-20241017223214946 image-20241017223231698 image-20241017223259132 image-20241017223309681 image-20241017225851405

点击右上角的Request More:

image-20241017223415546 image-20241017223433380 image-20241017223553103 image-20241017223601094 image-20241017223647753

缩小屏幕:

image-20241017223830999

4.3 添加到New API

类型:自定义渠道 Base URL:https://integrate.api.nvidia.com/v1/chat/completions 模型:nvidia/llama-3.1-nemotron-70b-instruct

Terminal window
curl https://integrate.api.nvidia.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY_REQUIRED_IF_EXECUTING_OUTSIDE_NGC" \
-d '{
"model": "nvidia/llama-3.1-nemotron-70b-instruct",
"messages": [{"role":"user","content":"Write a limerick about the wonders of GPU computing."}],
"temperature": 0.5,
"top_p": 1,
"max_tokens": 1024,
"stream": true
}'
image-20241017224029617

API-KEY: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(可以使用的!1000额度)

image-20241017224124171 image-20241017224147778

在NextChat-Web中添加自定义模型:nvidia/llama-3.1-nemotron-70b-instruct

image-20241017224229590 image-20241017224305947

可以看到一次消耗1积分:

image-20241017224400750

五 Hugging face Qwen2.5 72B

5.1 CF创建应用程序

image-20241018193244521 image-20241018193634616 image-20241018193702017

5.2 创建Hugging Face API

image-20241018193359202 image-20241018193434568 image-20241018193446417

5.3 重新部署CF应用程序

image-20241018193812074

代码源自:感谢分享:https://linux.do/t/topic/229833

Terminal window
//对接one-api/new-api使用
const API_KEY = "sk-1234567890";
//你的hugging face api key去hugging face申请
const HUGGINGFACE_API_KEY = "hf_xxxxxxxxxxx";
//目前发现的可用模型,请求时如模型不在该列表内,则使用你请求的模型
const CUSTOMER_MODEL_MAP = {
"qwen2.5-72b-instruct": "Qwen/Qwen2.5-72B-Instruct",
"gemma2-2b-it": "google/gemma-2-2b-it",
"gemma2-27b-it": "google/gemma-2-27b-it",
"llama-3-8b-instruct": "meta-llama/Meta-Llama-3-8B-Instruct",
"llama-3.2-1b-instruct": "meta-llama/Llama-3.2-1B-Instruct",
"llama-3.2-3b-instruct": "meta-llama/Llama-3.2-3B-Instruct",
"phi-3.5": "microsoft/Phi-3.5-mini-instruct"
};
async function handleRequest(request) {
try {
if (request.method === "OPTIONS") {
return getResponse("", 204);
}
const authHeader = request.headers.get("Authorization");
if (!authHeader || !authHeader.startsWith("Bearer ") || authHeader.split(" ")[1] !== API_KEY) {
return getResponse("Unauthorized", 401);
}
if (request.url.endsWith("/v1/models")) {
const arrs = [];
Object.keys(CUSTOMER_MODEL_MAP).map(element => arrs.push({ id: element, object: "model" }))
const response = {
data: arrs,
success: true
};
return getResponse(JSON.stringify(response), 200);
}
if (request.method !== "POST") {
return getResponse("Only POST requests are allowed", 405);
}
if (!request.url.endsWith("/v1/chat/completions")) {
return getResponse("Not Found", 404);
}
const data = await request.json();
const messages = data.messages || [];
const model = CUSTOMER_MODEL_MAP[data.model] || data.model;
const temperature = data.temperature || 0.7;
const max_tokens = data.max_tokens || 8196;
const top_p = Math.min(Math.max(data.top_p || 0.9, 0.0001), 0.9999);
const stream = data.stream || false;
const requestBody = {
model: model,
stream: stream,
temperature: temperature,
max_tokens: max_tokens,
top_p: top_p,
messages: messages
};
const apiUrl = `https://api-inference.huggingface.co/models/${model}/v1/chat/completions`;
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Authorization': `Bearer ${HUGGINGFACE_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
if (!response.ok) {
const errorText = await response.text();
return getResponse(`Error from API: ${response.statusText} - ${errorText}`, response.status);
}
const newResponse = new Response(response.body, {
status: response.status,
headers: {
...Object.fromEntries(response.headers),
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': '*',
'Access-Control-Allow-Headers': '*'
}
});
return newResponse;
} catch (error) {
return getResponse(JSON.stringify({
error: `处理请求失败: ${error.message}`
}), 500);
}
}
function getResponse(resp, status) {
return new Response(resp, {
status: status,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*"
}
});
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

查看调用地址:

image-20241018194049670 image-20241018194230617

获取模型列表:

image-20241018194332067 image-20241018194415659 image-20241018194405466

5.4 ChatGPT-Next-Web使用Qwen2.5-72b-instruct

image-20241018195842907 image-20241018195709958 image-20241018195833785 image-20241018200017518

体验下来还是qwen2.5-72b-instruct更适合我们使用~

六 X-AI

6.1 申请X-AI

官网:https://x.ai/

注册地址:https://accounts.x.ai/sign-up?redirect=cloud-console

image-20241118172254474 image-20241118172531822 image-20241118172751297 image-20241118172804688 image-20241118172827365 image-20241118172842193 image-20241118172850706

6.2 使用X-AI

https://api.x.ai/v1/chat/completions

grok-beta

xai-ZsT5i2VIs1z6Rjvw7nuf16WO9Rdnl9hhUJ1VuKnApSpKUc1p91DGNebRGvpNLvIp55sPFaN5WkCceXM9

image-20241118172931722 image-20241118172954563

七 Gemini

7.1 申请Gemini

官网:https://ai.google.dev/

image-20241118180954640 image-20241118181036464 image-20241118181055142 image-20241118181105489

7.2 使用Gemini

gemini-1.5-pro-002,gemini-1.5-pro,gemini-1.5-flash,gemini-1.5-flash-002,gemini-flash-8b

https://gemini-proxy.keyikai.me

image-20241118181136993 image-20241118181149653 image-20241118181326009

八 genspark

Genspark是由Mainfunc Inc.创建的AI助手。包含大型语言模型,能够处理各种任务,包括创意写作、编码、分析、教学和一般对话。

image-20241228222208146 image-20241228222340023

8.1 申请genspark

地址:https://www.genspark.ai/invite?invite_code=ZjU1M2E4YjNMZWMyOEw5NGU0TGVhY2JMZTU5MDFmZTY5MzY1

接码平台:https://sms-activate.org/

可刷20个月使用权限:

image-20241228222512011

8.2 使用genspark

部署genspark2api,部署完成后可加入New API

https://github.com/deanxv/genspark2api

image-20241228222729651

九 DeepSeek

DeepSeek-V3 多项评测成绩超越了 Qwen2.5-72B 和 Llama-3.1-405B 等其他开源模型,并在性能上和世界顶尖的闭源模型 GPT-4o 以及 Claude-3.5-Sonnet 不分伯仲。

image-20241228223027333 image-20241228223049927

9.1 DeepSeek注册

注册地址:https://www.deepseek.com/

9.2 DeepSeek使用

创建API Keys:

image-20241228223121939

New API创建DeepSeek后添加密钥即可:

image-20241228223456761 image-20241228223229293

十 硅基流动

image-20241228223845147

10.1 硅基流动注册

注册地址:https://cloud.siliconflow.cn/i/d40omfvY

image-20241228224033539 image-20241228224214741

10.2 硅基流动使用

类型选择SiliconCloud,模型获取模型列表,添加密钥即可使用~

image-20241228223638759 image-20241228223651977

10.3 刷硅基流动API

找到免费接码平台:

image-20250104234123375 image-20250104234138260 image-20250104234216619

如果出现以下情况:

image-20250104234609721

请使用指纹浏览器:https://github.com/Virtual-Browser/VirtualBrowser

image-20250104234630902

拉人头的API Key不要扔。多个14元也可以用很久,https://cherry-ai.com/

image-20250105000241186 image-20250105000428377

送一些14元的API:

Terminal window
sk-szhaoobqvkbupemcgdduwkjhnhpuqbsobpevsyutyrrtjwai
sk-areclqfwlogjoxpxcswqufgavciessxbzaymtsmizzptlueu
sk-enyquynazjeodoetgjfyashsnfwtdscwwjmhsqolyslotifp
sk-tgvjzrfpynjyulmmvfrffdbmxnffpgczovzijcaafbzmampe
sk-zamlisxvwvsuhsbnitrwbjamvhcbrivulvvfmdcnptwttsza
sk-hkjehocdrdhbcwmygvuoqhrpobyehuzjzmtiqmqcjmbyhxfr
sk-yjwatpmjxktgqrfmoafrrlbfcjtxohpwozyuhzhxlziewktn
sk-jprlohnrjqblpzyenbvtjtwbhbwpokngzuosazqbqzkxuovt
sk-flwwllmbgwcfwdwafjveliwyxemvzqkblazxkjmwyljchpke
sk-ccromdofalqjzarfnuvdjwpjnhueijlrlrykqszeprjsjwhn
sk-gyvissagxdoyvohkjetvvilvdwqqvajjgzppmhjvwrzethdr
sk-bsmobjzcsjiswqulehydsonamjgwbdvduzkucugictmjnvrx
sk-wcleesounbogvrokxjjzswtiicsltymtfjnrtzqlubzomhzz
sk-iygqluhnchvvmuoerbjsqymgswgjyitvdzhuekpstsnzgvvg
sk-egphrebomznvaplhslhkhbfczmvsjpfkifhvjqtblajbooto