@re-ai/openai-like-api
Advanced tools
Comparing version 0.2.10 to 0.2.11
import { DefaultContext } from "koa"; | ||
export declare const ChatCompletionAPI: (ctx: DefaultContext) => Promise<void>; |
@@ -0,0 +0,0 @@ "use strict"; |
import { DefaultContext } from "koa"; | ||
export declare const EmbeddingsAPI: (ctx: DefaultContext) => Promise<void>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Koa from 'koa'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare enum BaiChuanModels { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Transform } from "stream"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -7,1 +7,5 @@ export type ChatToolCallFuntion = { | ||
}; | ||
export type ChatToolCall = { | ||
id: string; | ||
function: ChatToolCallFuntion; | ||
}; |
"use strict"; |
@@ -0,0 +0,0 @@ export declare enum QwenModels { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare enum SparkModels { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export type ImageParams = { |
@@ -0,0 +0,0 @@ export declare enum ZhiPuModels { |
@@ -0,0 +0,0 @@ "use strict"; |
"use strict"; |
import { Transform } from "stream"; | ||
import { ChatCompletionChunk } from "openai/resources"; | ||
import { ChatToolCallFuntion } from "../types"; | ||
import { ChatToolCall } from "../types"; | ||
export declare class ChatCompletionStream<T> extends Transform { | ||
@@ -17,3 +17,3 @@ constructor(); | ||
export declare const streamingResponseCut: (stream: ChatCompletionStream<ChatCompletionChunk>, callback: (data: string | null) => void, options?: {}) => Promise<void>; | ||
export declare const streamResponseToolCallsFormat: (stream: ChatCompletionStream<ChatCompletionChunk>) => Promise<ChatToolCallFuntion[]>; | ||
export declare const streamResponseToolCallsFormat: (stream: ChatCompletionStream<ChatCompletionChunk>) => Promise<ChatToolCall[]>; | ||
export declare const streamResponseFormat: (stream: ChatCompletionStream<ChatCompletionChunk>, callbacks?: { | ||
@@ -57,3 +57,3 @@ onData?: (data: any) => void; | ||
*/ | ||
toolCallsFormat: (stream: ChatCompletionStream<ChatCompletionChunk>) => Promise<ChatToolCallFuntion[]>; | ||
toolCallsFormat: (stream: ChatCompletionStream<ChatCompletionChunk>) => Promise<ChatToolCall[]>; | ||
/** | ||
@@ -60,0 +60,0 @@ * 处理响应的格式化函数。 |
@@ -97,3 +97,3 @@ "use strict"; | ||
const streamResponseToolCallsFormat = async (stream) => { | ||
const functionCalls = []; | ||
const toolCalls = []; | ||
for await (const iterator of stream) { | ||
@@ -103,28 +103,17 @@ const { choices } = iterator; | ||
delta.tool_calls?.forEach((toolCall, i) => { | ||
if (!functionCalls[i]) { | ||
functionCalls[i] = { | ||
name: "", | ||
arguments: "" | ||
}; | ||
} | ||
functionCalls[i].name += (toolCall.function?.name || ""); | ||
functionCalls[i].arguments += (toolCall.function?.arguments || ""); | ||
const name = toolCall.function?.name || ""; | ||
const args = toolCall.function?.arguments ? JSON.parse(toolCall.function?.arguments || "") : {}; | ||
if (!name) | ||
return; | ||
let item = { | ||
id: toolCall.id || "", | ||
function: { | ||
name: toolCall.function?.name || "", | ||
arguments: args | ||
} | ||
}; | ||
toolCalls.push(item); | ||
}); | ||
} | ||
return functionCalls.map((functionCall) => { | ||
try { | ||
return { | ||
name: functionCall.name, | ||
arguments: JSON.parse(functionCall.arguments) | ||
}; | ||
} | ||
catch (err) { | ||
return { | ||
name: functionCall.name, | ||
arguments: { | ||
error: "parse arguments error" | ||
} | ||
}; | ||
} | ||
}); | ||
return toolCalls; | ||
}; | ||
@@ -131,0 +120,0 @@ exports.streamResponseToolCallsFormat = streamResponseToolCallsFormat; |
@@ -0,0 +0,0 @@ # ReAIVisonAPI |
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "@re-ai/openai-like-api", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"description": "reai openai like api", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -0,0 +0,0 @@ # OpenAILike API 开发文档 |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ import { ImageGenerateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams, ChatCompletionMessageParam } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams, Embedding, ImageGenerateParams, ImagesResponse } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, ChatCompletionMessageParam, ChatCompletionMessageToolCall, CreateEmbeddingResponse, Embedding, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams, ImageGenerateParams, ImagesResponse } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { Image, ImageGenerateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ImageResult } from "../../types/vision/vision"; |
@@ -0,0 +0,0 @@ import { ImageGenerateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ImageGenerateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ImageGenerateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { VisionInterface } from "../../interfaces/Vision"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources"; |
@@ -0,0 +0,0 @@ import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, EmbeddingCreateParams, ImageGenerateParams, ImagesResponse } from "openai/resources"; |
@@ -0,0 +0,0 @@ export enum ErnieModels { |
@@ -0,0 +0,0 @@ export enum API_HOSTS { |
@@ -0,0 +0,0 @@ // 枚举类型定义艺术风格 |
@@ -6,2 +6,7 @@ export type ChatToolCallFuntion = { | ||
} | ||
} | ||
export type ChatToolCall = { | ||
id: string, | ||
function: ChatToolCallFuntion | ||
} |
@@ -0,0 +0,0 @@ export enum SparkModels { |
@@ -0,0 +0,0 @@ export type SenseKnowledgeConfig = { |
@@ -0,0 +0,0 @@ export type BaiduTextToImageSpeechRequest = { |
@@ -0,0 +0,0 @@ export enum FluxModels { |
@@ -0,0 +0,0 @@ export type ImageParams = { |
@@ -0,0 +0,0 @@ import { Logger } from "./Logger"; |
@@ -0,0 +0,0 @@ export const isPunctuation = (char: string): boolean => { |
@@ -0,0 +0,0 @@ export enum LogLevel { |
@@ -0,0 +0,0 @@ export class StructPromptBuilder { |
@@ -6,3 +6,3 @@ import { Transform } from "stream"; | ||
import { FunctionCall } from "@azure/openai"; | ||
import { ChatToolCallFuntion } from "../types"; | ||
import { ChatToolCall, ChatToolCallFuntion } from "../types"; | ||
@@ -118,4 +118,4 @@ | ||
export const streamResponseToolCallsFormat = async (stream: ChatCompletionStream<ChatCompletionChunk>): Promise<ChatToolCallFuntion[]> => { | ||
const functionCalls: FunctionCall[] = [] | ||
export const streamResponseToolCallsFormat = async (stream: ChatCompletionStream<ChatCompletionChunk>): Promise<ChatToolCall[]> => { | ||
const toolCalls: ChatToolCall[] = [] | ||
for await (const iterator of stream) { | ||
@@ -125,32 +125,19 @@ const { choices } = iterator as ChatCompletionChunk | ||
delta.tool_calls?.forEach((toolCall, i) => { | ||
if (!functionCalls[i]) { | ||
functionCalls[i] = { | ||
name: "", | ||
arguments: "" | ||
const name = toolCall.function?.name || "" | ||
const args = toolCall.function?.arguments ? JSON.parse(toolCall.function?.arguments || "") : {} | ||
if (!name) return | ||
let item:ChatToolCall = { | ||
id: toolCall.id || "", | ||
function: { | ||
name: toolCall.function?.name || "", | ||
arguments: args | ||
} | ||
} | ||
functionCalls[i].name += (toolCall.function?.name || "") | ||
functionCalls[i].arguments += (toolCall.function?.arguments || "") | ||
toolCalls.push(item) | ||
}) | ||
} | ||
return functionCalls.map((functionCall) => { | ||
try { | ||
return { | ||
name: functionCall.name, | ||
arguments: JSON.parse(functionCall.arguments) | ||
} | ||
} catch (err) { | ||
return { | ||
name: functionCall.name, | ||
arguments: { | ||
error: "parse arguments error" | ||
} | ||
} | ||
} | ||
return toolCalls | ||
}) | ||
} | ||
@@ -157,0 +144,0 @@ |
@@ -0,0 +0,0 @@ { |
946520
6718