Comparing version 0.1.0 to 0.2.0
@@ -1,3 +0,43 @@ | ||
declare function add(a: number, b: number): number; | ||
import OpenAI from 'openai'; | ||
export { add }; | ||
type MessageFunctionCall = { | ||
id: string; | ||
type: 'function_call'; | ||
sender: 'iudex'; | ||
timestamp: string; | ||
functionName: string; | ||
functionArgs: any; | ||
}; | ||
type MessageText = { | ||
id: string; | ||
type: 'text'; | ||
sender: 'iudex'; | ||
timestamp: string; | ||
text: string; | ||
}; | ||
type IudexMessage = MessageFunctionCall | MessageText; | ||
declare function mapIudexToOpenAi(m: IudexMessage): Omit<OpenAI.ChatCompletion, 'model'>; | ||
declare class Iudex { | ||
baseUrl: string; | ||
apiKey: string; | ||
constructor({ apiKey, baseUrl, }?: { | ||
apiKey?: string; | ||
baseUrl?: string; | ||
}); | ||
chatCompletionsCreate: (body: OpenAI.ChatCompletionCreateParamsNonStreaming & { | ||
messages: Array<OpenAI.ChatCompletionMessageParam & { | ||
tool_call_id?: string; | ||
}>; | ||
}) => Promise<OpenAI.ChatCompletion>; | ||
chat: { | ||
completions: { | ||
create: (body: OpenAI.ChatCompletionCreateParamsNonStreaming & { | ||
messages: Array<OpenAI.ChatCompletionMessageParam & { | ||
tool_call_id?: string; | ||
}>; | ||
}) => Promise<OpenAI.ChatCompletion>; | ||
}; | ||
}; | ||
} | ||
export { Iudex, type IudexMessage, Iudex as default, mapIudexToOpenAi }; |
@@ -23,13 +23,109 @@ "use strict"; | ||
__export(src_exports, { | ||
add: () => add | ||
Iudex: () => Iudex, | ||
default: () => src_default, | ||
mapIudexToOpenAi: () => mapIudexToOpenAi | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
function add(a, b) { | ||
return a + b; | ||
function mapIudexToOpenAi(m) { | ||
if (m.type === "function_call") { | ||
const message2 = { | ||
content: null, | ||
role: "assistant", | ||
tool_calls: [{ | ||
id: "r.callId", | ||
function: { name: m.functionName, arguments: JSON.stringify(m.functionArgs) }, | ||
type: "function" | ||
}] | ||
}; | ||
return { | ||
id: m.id, | ||
choices: [{ | ||
index: 0, | ||
finish_reason: "tool_calls", | ||
logprobs: null, | ||
message: message2 | ||
}], | ||
created: new Date(m.timestamp).valueOf(), | ||
object: "chat.completion" | ||
}; | ||
} | ||
const message = { | ||
content: m.text, | ||
role: "assistant" | ||
}; | ||
return { | ||
id: m.id, | ||
choices: [{ | ||
index: 0, | ||
finish_reason: "stop", | ||
logprobs: null, | ||
message | ||
}], | ||
created: new Date(m.timestamp).valueOf(), | ||
object: "chat.completion" | ||
}; | ||
} | ||
console.log(add(3, 5)); | ||
var Iudex = class { | ||
baseUrl; | ||
apiKey; | ||
constructor({ | ||
apiKey = process.env.IUDEX_API_KEY, | ||
baseUrl = process.env.IUDEX_BASE_URL || "https://api.iudex.ai" | ||
} = { | ||
apiKey: process.env.IUDEX_API_KEY, | ||
baseUrl: "https://api.iudex.ai" | ||
}) { | ||
if (!apiKey) { | ||
throw Error( | ||
`The IUDEX_API_KEY environment variable is missing or empty. Provide IUDEX_API_KEY to the environment on load OR instantiate the Iudex client with the apiKey option. Example: \`new Iudex({ apiKey: 'My API Key' })\`` | ||
); | ||
} | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
chatCompletionsCreate = (body) => { | ||
if (!body.messages.length) { | ||
throw Error(`The messages array is empty`); | ||
} | ||
const penUltMessage = body.messages[body.messages.length - 2]; | ||
if (penUltMessage?.tool_call_id) { | ||
const callId = penUltMessage.tool_call_id; | ||
const lastMessage = body.messages[body.messages.length - 1]; | ||
const functionReturn = lastMessage.content; | ||
const res2 = fetch(this.baseUrl + "/function_calls/" + callId, { | ||
method: "PUT", | ||
headers: { Authorization: `Bearer ${this.apiKey}` }, | ||
body: JSON.stringify({ callId, functionReturn }) | ||
}); | ||
return res2.then((r) => r.json()).then((r) => { | ||
return { | ||
model: body.model, | ||
...mapIudexToOpenAi(r) | ||
}; | ||
}); | ||
} | ||
const res = fetch(this.baseUrl + "/workflows", { | ||
method: "POST", | ||
headers: { Authorization: `Bearer ${this.apiKey}` }, | ||
body: JSON.stringify(body) | ||
}); | ||
return res.then((r) => r.json()).then((r) => { | ||
return { | ||
model: body.model, | ||
...mapIudexToOpenAi(r) | ||
}; | ||
}); | ||
}; | ||
chat = { | ||
completions: { | ||
create: this.chatCompletionsCreate | ||
} | ||
}; | ||
}; | ||
var src_default = Iudex; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
add | ||
Iudex, | ||
mapIudexToOpenAi | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "iudex", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Iudex client", | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "jest" | ||
}, | ||
"main": "./dist/index.js", | ||
@@ -11,6 +15,2 @@ "module": "./dist/index.mjs", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/iudexai/iudex.git" | ||
}, | ||
"keywords": [ | ||
@@ -25,2 +25,6 @@ "iudex", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/iudexai/iudex.git" | ||
}, | ||
"bugs": { | ||
@@ -34,10 +38,7 @@ "url": "https://github.com/iudexai/iudex/issues" | ||
"jest": "^29.7.0", | ||
"openai": "^4.26.1", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "jest" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
22130
272
1
13
7
5