You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@re-ai/openai-like-api

Package Overview
Dependencies
Maintainers
0
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@re-ai/openai-like-api - npm Package Compare versions

Comparing version

to
0.0.5

src/services/azure.ts

3

package.json
{
"name": "@re-ai/openai-like-api",
"version": "0.0.4",
"version": "0.0.5",
"description": "reai openai like api",

@@ -28,2 +28,3 @@ "main": "index.js",

"dependencies": {
"@azure/openai": "^1.0.0-beta.12",
"dotenv": "^16.4.5",

@@ -30,0 +31,0 @@ "koa": "^2.15.3",

@@ -9,2 +9,3 @@ # OpenAILike API 开发文档

+ 2024.07.17: 添加**阿里dashscope**,**百川**,**豆包**,**moonshot**,**零一万物YI**,**AzureOpenAI**
+ 2024.07.16: 添加**讯飞星火**,**腾讯混元**,**智谱清言**

@@ -11,0 +12,0 @@

export * from './types/chatComplete'
export * from './types/ernie'
export * from './types/spark'
export * from './types/hunyuan'
export * from './types/zhipu'
export * from './types/baichuan'
export * from './types/qwen'
// export * from './types/doubao'
export * from './types/models'

@@ -11,0 +6,0 @@ export type { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, CreateEmbeddingResponse, ChatCompletionTool, EmbeddingCreateParams } from "openai/resources";

@@ -12,2 +12,5 @@

import { BaiChuanAPIService } from "../services/baichuan"
import { YIAPIService } from "../services/yi"
import { MoonShotAPIService } from "../services/moonShot"
import { AzureOpenAIService } from "../services/azure"

@@ -51,2 +54,11 @@

return new DashScopeAPIService(key)
} else if (apiKey.startsWith("yi:")) {
const [pre, key] = apiKey.split(":")
return new YIAPIService(key)
} else if (apiKey.startsWith("moonshot:")) {
const [pre, key] = apiKey.split(":")
return new MoonShotAPIService(key)
} else if (apiKey.startsWith("azure:")) {
const [pre, key, endpoint] = apiKey.split(":")
return new AzureOpenAIService(key, endpoint)
} else {

@@ -53,0 +65,0 @@ return new OpenAIService({

@@ -6,7 +6,6 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams, Embedding } from "openai/resources";

import { ChatCompletionsRequest, ChatCompletionsResponse, Message, Tool } from "tencentcloud-sdk-nodejs-hunyuan/tencentcloud/services/hunyuan/v20230901/hunyuan_models";
import { Logger } from "../utils/Logger";
import { Stream } from "stream";
import { isPunctuation, isTextCut } from "../utils";
import { isTextCut } from "../utils";
import { v4 } from "uuid";
import { HunYuanEmbeddingModel } from "../types/hunyuan";
import { HunYuanEmbeddingModel } from "../types/models";

@@ -81,3 +80,3 @@ export class HunYuanService implements OpenAILikeInterface {

} else {
const stream = new ChatCompletionStream<ChatCompletionChunk>()

@@ -98,3 +97,3 @@ let index = 0

const content = rep.Choices ? (rep.Choices[0].Delta?.Content || "") : ""
contentBuf += content

@@ -119,3 +118,3 @@ if (isTextCut(content) || finish !== null) {

}
stream.write(chuck)

@@ -131,3 +130,3 @@ contentBuf = ""

})
return stream

@@ -152,3 +151,3 @@ }

})
if (result.Data && result.Data[0].Embedding) {

@@ -155,0 +154,0 @@ embeddings.push({

@@ -38,3 +38,3 @@ import { ChatCompletionCreateParams, ChatCompletionChunk, ChatCompletion, CreateEmbeddingResponse, EmbeddingCreateParams } from "openai/resources";

for await (const iterator of response) {
Logger.debug("openai iterator", JSON.stringify(iterator, null, 2))
// Logger.debug("openai iterator", JSON.stringify(iterator, null, 2))
finish = iterator.choices[0].finish_reason || null

@@ -41,0 +41,0 @@ let content = iterator.choices[0].delta.content