跳到主要内容

接口文档

Chat Completion

请求地址

POST https://api.infly.cn/v1/chat/completions

请求Header

{
"Authorization": "Bearer <API_KEY>"
}

请求内容

示例

{
"model": "inf-chat-v1",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant"
},
{ "role": "user", "content": "hi!" }
],
"temperature": 0.3
}

参数说明

参数是否必须说明类型默认取值
modelrequired模型名称string目前支持inf-chat-v1
messagesrequired对话消息列表List[Dict]这是一个结构体的列表,每个元素类似如下:{"role": "user", "content": "你好"} role 只支持 system,user,assistant 其一,content 不得为空
max_tokensoptional对话完成时生成的最大token数,如果生成了max_tokens的内容仍然没有结束,finish_reason的值是‘length’,否则是'stop'int4096
temperatureoptional采样温度越高,输出越随机,越低时输出越确定,取值范围为[0,1]float1.0
top_poptional另一种采样机制,较小的topp值,生成的结果更具有确定性,较大的top_p值则会导致生成结果更多样化,取值范围[0, 1]float0.9
noptional每个prompt生成结果数,取值不大于4的正整数int1
presence_penaltyoptional存在惩罚,正值会根据新生成的词汇是否出现在文本中来进行惩罚,增加模型讨论新话题的可能性,取值范围[-2, 2]float0.0
frequency_penaltyoptional频率惩罚,正值会根据新生成的词汇在文本中现有的频率来进行惩罚,减少模型一字不差重复同样话语的可能性,取值范围[-2, 2]float0.0
repetition_penaltyoptional重复惩罚,较高的值会让模型更强烈地避免重复,取值范围(0, 2]float1.0
stopoptional停止词,当匹配到这个(组)词后会停止输出,这个(组)词本身不会输出。List[string]null
streamoptional是否流式输出结果boolfalse
toolsoptional工具列表,详情请查看 function callingarraynull
response_formatoptional结构化输出,详情请查看 structured outputobjectnull

返回内容

非流式

{
"id": "chatcmpl-9mc4YqcON8S6s9oN0M2hFAHRyiMAz",
"object": "chat.completion",
"created": 1721373122,
"model": "inf-chat-v1",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么我可以帮助你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 9,
"total_tokens": 17
}
}

流式

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"role": "assistant"}}], "usage": {"completion_tokens": 0, "prompt_tokens": 0, "total_tokens": 0}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "Hello"}}], "usage": {"completion_tokens": 1, "prompt_tokens": 10, "total_tokens": 11}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "!"}}], "usage": {"completion_tokens": 2, "prompt_tokens": 10, "total_tokens": 12}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " I"}}], "usage": {"completion_tokens": 3, "prompt_tokens": 10, "total_tokens": 13}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " am"}}], "usage": {"completion_tokens": 4, "prompt_tokens": 10, "total_tokens": 14}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " 光"}}], "usage": {"completion_tokens": 5, "prompt_tokens": 10, "total_tokens": 15}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "语"}}], "usage": {"completion_tokens": 6, "prompt_tokens": 10, "total_tokens": 16}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "慧"}}], "usage": {"completion_tokens": 7, "prompt_tokens": 10, "total_tokens": 17}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "言"}}], "usage": {"completion_tokens": 8, "prompt_tokens": 10, "total_tokens": 18}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "!"}}], "usage": {"completion_tokens": 9, "prompt_tokens": 10, "total_tokens": 19}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " How"}}], "usage": {"completion_tokens": 10, "prompt_tokens": 10, "total_tokens": 20}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " can"}}], "usage": {"completion_tokens": 11, "prompt_tokens": 10, "total_tokens": 21}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " I"}}], "usage": {"completion_tokens": 12, "prompt_tokens": 10, "total_tokens": 22}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " assist"}}], "usage": {"completion_tokens": 13, "prompt_tokens": 10, "total_tokens": 23}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " you"}}], "usage": {"completion_tokens": 14, "prompt_tokens": 10, "total_tokens": 24}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": " today"}}], "usage": {"completion_tokens": 15, "prompt_tokens": 10, "total_tokens": 25}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": "?"}}], "usage": {"completion_tokens": 16, "prompt_tokens": 10, "total_tokens": 26}}

data:{"id": "0218957931dd46118e0c6705d5afc352", "object": "chat.completion.chunk", "created": 1724907803, "model": "inf-chat-v1", "choices": [{"index": 0, "delta": {"content": ""}, "finish_reason": "stop"}], "usage": {"completion_tokens": 17, "prompt_tokens": 10, "total_tokens": 27}}

data: [DONE]

List Models

请求地址

GET https://api.infly.cn/v1/models

请求Header

{
"Authorization": "Bearer <API_KEY>"
}

返回内容

[
{
"id": "cf4fd88b-452d-417b-b161-51806a8712df",
"name": "inf-chat-v1",
"description": "34b大模型",
"api_version": "v1",
"source": "inf",
"created_at": "2024-08-05 14:55:41"
}
]