@ godspideai/ cognate- professor- openai- 兼容
任何 OpenAI 兼容的聊天完成端点的 Cognate 模型提供者 – lama.cpp,
vLLM,奥拉玛的 /v1,LM工作室,或托管 API —— 超平面 fetch没有供应商SDK.
何时使用此软件包 : 您的应用程序需要一个真正的模型,服务器会说话
开放AI /chat/completions 线条格式. 在测试中用于确定脚本的答案, 使用
@godspeedai/cognate-provider-local
换句话说.
安装
bun add @godspeedai/cognate-provider-openai-compatible
要求数 阿宝 >= 1.4.0 (使用平台) fetch, (中文(简体) ), AbortSignal网络
溪流). SDK号飞船 Bun-native TypeScript源, 所以添加 @types/bun 财务报告和审定财务报表 @types/node
在检查您的工程时, 作为非依赖性 .
快开始
import { openAICompatible } from "@godspeedai/cognate-provider-openai-compatible";
const provider = openAICompatible({
id: "gpt-4o-mini", // provider id becomes `openai-compatible:gpt-4o-mini`
baseURL: process.env.OPENAI_BASE_URL ?? "https://api.openai.com/v1",
model: "gpt-4o-mini",
apiKey: () => process.env.OPENAI_API_KEY ?? "", // read per request, never stored
timeoutMs: 60_000,
});
const response = await provider.generate({
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.message.content);
console.log(response.usage); // { inputTokens, outputTokens } when the server reports usage
// Streaming: text deltas and tool-call deltas, then a final `done` delta
// carrying the assembled full response.
for await (const delta of provider.stream({ messages: [{ role: "user", content: "Hello!" }] })) {
if (delta.type === "text") process.stdout.write(delta.text);
}
点 baseURL 例如,在任何兼容的服务器上 http://localhost:11434/v1 奥拉马
或者你的lama.cpp/vLLM路线. 供应商向 <baseURL>/chat/completions。 。 。 .
地图
- 信件和工具 成为 OpenAI 线形: 工具为
{ type: "function", function: { name, description, parameters } },助理工具调用 与JSON的争辩,responseFormat.schema作为json_schema(或json_object没有计划),加max_tokens财务报告和审定财务报表temperature。 。 。 . - 流线 解析 SSE
data:线条(容忍块边界),累积工具 名称和论据被分割成小块 接下来是tool_call条目和 adone三角洲与集合反应. - 错误 输入
ModelProviderError类型 :unauthorized(401/403) (中文(简体) ),rate_limited(429个),invalid_request(其他为4xx),unavailable(5xx,网络错误, 暂停,cancelled(电话中断)和malformed_response(无相体相.
这个 apiKey 函数被调用到每个请求,其值从未被存储、记录或包含
在错误信息或能力合同中,提供者公布.
内核组件
modelComponent(provider) 将提供者包成内核 Component 出版时间
model.generate 因此,运行时间可以像其他能力一样选择和引用:
import { modelComponent } from "@godspeedai/cognate-provider-openai-compatible";
const component = modelComponent(provider);
// pass it in the runtime's `components` list
限制
- 只聊天补全:没有嵌入,文件,音频,或助理状态的API.
- 特性旗默认为
stream编号 :tool_use编号 :structured_outputtrue, (中文(简体) ),multimodal_inputfalse, (中文(简体) ),context_limit8192覆盖features来配合你的 服务器实际支持,否则资格检查会信任服务器可能不尊重的标记. - 结构化输出取决于服务器的荣誉
response_format; 提供者提供 无论服务器返回什么. - 工具调用参数必须有效 JSON 在线上; 流出错误的服务器
参数表面
malformed_response。 。 。 .
相关软件包
@godspeedai/cognate-capabilities—— 说 页:1ModelProvider合同,ModelProviderError,和选择引擎.@godspeedai/cognate-provider-local—— 说 确定测试和离线使用的脚本提供者.@godspeedai/cognate-runtime-bun—— 说 引用运行时间; 通过一个提供者(或其组件)给代理商一个模型.@godspeedai/cognateSDK伞.
许可证
阿帕奇 - 2.0