调用模型
如未满足上述条件,请联系管理员申请令牌及模型调用权限。申请时请提供:账户信息、目标模型及所属渠道信息。
调用对话 API
Section titled “调用对话 API”您可以使用以下样例来调用对话接口和模型,进行对话内容的生成。样例为非流式输出,您可以将 stream 设置为 true 来使用流式输出,对于更多参数,可以参考openai官方格式自行添加。
curl --location https://aifusion.newtouch.com/ai/v1/chat/completions \ --header "Content-Type: application/json" \ --header "Authorization: Bearer Newtouch_API_KEY" \ --data '{ "model": "model-name", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ], "stream": false }'# Please install OpenAI SDK first: `pip3 install openai`import osfrom openai import OpenAI
client = OpenAI( api_key=os.environ.get('Newtouch_API_KEY'), base_url="https://aifusion.newtouch.com")
response = client.chat.completions.create( model="model-name", messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": "Hello"}, ], stream=False)
print(response.choices[0].message.content)// Please install OpenAI SDK first: `npm install openai`import OpenAI from "openai";
const openai = new OpenAI({ baseURL: 'https://aifusion.newtouch.com', apiKey: process.env.Newtouch_API_KEY,});
async function main() { const completion = await openai.chat.completions.create({ messages: [{ role: "system", content: "You are a helpful assistant." }], model: "model-name", });
console.log(completion.choices[0].message.content);}
main();| 名称 | 建议值 |
|---|---|
| Newtouch_API_KEY | 指创建并给予了调用权限的api-key |
| model | 指需要调用模型的代号,需和平台提供代号保持一致 |
| message | 指发送给模型的内容,其中 “role”: “system” 一行的 content 中要填入的是用户希望模型扮演的角色;而 “role”: “system” 一行的 content 中要填入的是用户希望模型做出回复的内容 |
调用向量 API
Section titled “调用向量 API”在创建 api-key 之后,您可以使用以下 bash 样例来调用embedding接口和模型,对文本内容进行向量化处理。
curl --location https://aifusion.newtouch.com/v1/embeddings \ --header "Content-Type: application/json" \ --header "Authorization: Bearer Newtouch_API_KEY" \ --data '{ "input": "Your text string goes here", "model": "model-name" }'from openai import OpenAIclient = OpenAI()
response = client.embeddings.create( input="text", model="model-name")
print(response.data[0].embedding)import OpenAI from "openai";const openai = new OpenAI();
const embedding = await openai.embeddings.create({ model: "model-name", input: "text", encoding_format: "float",});
console.log(embedding);| 名称 | 建议值 |
|---|---|
| Newtouch_API_KEY | 指创建并给予了调用权限的api-key |
| input | 指需要进行向量化处理的文本内容,可按照 “text” 的格式增删内容条数 |
| model | 指需要调用的模型名称 |
其他接口和模型
Section titled “其他接口和模型”对于入参/出参格式相对多样的接口和模型,本文档也提供基于 Apifox 的接口文档进行参考和在线调试:
OCR 模型