Iudex JS client
Iudex is an infrastructure that enables complex and accurate function calling apis. Our infrastructure provides a
natural language interface that can accomplish complex or answer complex queries given the control of your own functions.
We do this by indexing functions and dividing down queries into runnable parts before surfacing the right function
at the right time.
Check out iudex.ai to sign up.
Installation
npm install iudex
yarn add iudex
pnpm add iudex
Usage
*Example where using Iudex replaces OpenAI
Here, fnMap
just needs to be defined to link all functions you want the function calling
api to be able to call. For Iudex all parameters except messages
is ignored.
import dotenv from 'dotenv';
dotenv.config();
import OpenAI from 'openai';
import { Iudex } from 'iudex';
import _ from 'lodash';
const iudex = new Iudex({ apiKey: process.env.IUDEX_API_KEY });
const messagesHist: OpenAI.ChatCompletionMessageParam[] = [];
const messages = {
push: (...items: OpenAI.ChatCompletionMessageParam[]) => {
console.log('new message:', items);
messagesHist.push(...items);
},
value: messagesHist,
};
messages.push({
role: 'user',
content: `what is ubers revenue in yen, use edgar`,
});
messages.push(await iudex.chat.completions.create({
model: 'gpt-4-turbo-preview',
messages: messages.value,
tools: [],
tool_choice: 'auto',
}).then(res => res.choices[0].message));
let toolMessage = _.last(messages.value);
while (toolMessage && messageHasToolCall(toolMessage)) {
const {
function: { name: fnName, arguments: fnArgs },
id: tool_call_id,
} = toolMessage.tool_calls[0];
const fnReturn = 'stubbed value';
messages.push({
role: 'tool',
tool_call_id,
content: JSON.stringify(fnReturn),
});
messages.push(await iudex.chat.completions.create({
model: 'gpt-4-turbo-preview',
messages: messages.value,
}).then(res => res.choices[0].message));
toolMessage = _.last(messages.value);
}
console.log('FINISHED');
type OpenAIToolCallMessage = OpenAI.ChatCompletionAssistantMessageParam
& { tool_calls: OpenAI.ChatCompletionMessageToolCall[] };
function messageHasToolCall(
message: OpenAI.ChatCompletionMessageParam,
): message is OpenAIToolCallMessage {
return !!(message as OpenAI.ChatCompletionAssistantMessageParam).tool_calls;
}