Comparing version 0.7.6 to 0.8.7
@@ -77,3 +77,3 @@ import OpenAI from 'openai'; | ||
/** | ||
* All chat turn types | ||
* All chat turn types. Put new chat turn types here. | ||
*/ | ||
@@ -102,2 +102,29 @@ declare const chatTurnSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{ | ||
timestamp: z.ZodString; | ||
type: z.ZodLiteral<"error">; | ||
name: z.ZodString; | ||
message: z.ZodString; | ||
cause: z.ZodOptional<z.ZodString>; | ||
stack: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "error"; | ||
id: string; | ||
sender: string; | ||
timestamp: string; | ||
message: string; | ||
name: string; | ||
cause?: string | undefined; | ||
stack?: string | undefined; | ||
}, { | ||
type: "error"; | ||
id: string; | ||
sender: string; | ||
timestamp: string; | ||
message: string; | ||
name: string; | ||
cause?: string | undefined; | ||
stack?: string | undefined; | ||
}>, z.ZodObject<{ | ||
id: z.ZodString; | ||
sender: z.ZodString; | ||
timestamp: z.ZodString; | ||
type: z.ZodLiteral<"image">; | ||
@@ -655,4 +682,4 @@ image: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
name: string; | ||
description: string; | ||
name: string; | ||
parameters: ({ | ||
@@ -1085,4 +1112,4 @@ type: "object"; | ||
}, { | ||
name: string; | ||
description: string; | ||
name: string; | ||
parameters: ({ | ||
@@ -1518,3 +1545,3 @@ type: "object"; | ||
declare const DEFAULT_BASE_URL = "https://5pz08znmzj.execute-api.us-west-2.amazonaws.com"; | ||
declare const DEFAULT_BASE_URL = "https://api.iudex.ai"; | ||
type IudexMessage = ChatTurn; | ||
@@ -1541,3 +1568,3 @@ type ChatCompletionMessageWithIudex = OpenAI.ChatCompletionMessageParam & ({ | ||
apiKey: string; | ||
functionLinker?: (fnName: string) => (...args: any[]) => any; | ||
functionLinker?: (fnName: string) => (...args: any[]) => unknown; | ||
constructor({ apiKey, baseUrl, }?: { | ||
@@ -1548,3 +1575,14 @@ apiKey?: string; | ||
uploadFunctions: (jsons: Array<OpenAI.ChatCompletionCreateParams.Function | FunctionJson>, modules?: string) => Promise<void>; | ||
linkFunctions: (functionLinker: (fnName: string) => (...args: any[]) => any) => void; | ||
linkFunctions: (functionLinker: (fnName: string) => (...args: any[]) => unknown) => void; | ||
/** | ||
* @param message message to send | ||
* @returns response as a chat object | ||
*/ | ||
sendChatTurn: (message: string, opts?: { | ||
onChatTurn?: ((c: ChatTurn) => void) | undefined; | ||
}) => Promise<ChatText>; | ||
/** | ||
* @param message message to send | ||
* @returns response message as a string | ||
*/ | ||
sendMessage: (message: string) => Promise<string>; | ||
@@ -1551,0 +1589,0 @@ chatCompletionsCreate: (body: OpenAI.ChatCompletionCreateParamsNonStreaming & { |
@@ -42,3 +42,6 @@ "use strict"; | ||
} | ||
return r; | ||
if (r.status === 204) { | ||
return Promise.resolve(); | ||
} | ||
return r.json(); | ||
} | ||
@@ -58,3 +61,3 @@ function throwOnApiError(json) { | ||
function parseIudexResponse(r) { | ||
return checkResponse(r).json().then(throwOnApiError).then(unwrapApi).catch((e) => { | ||
return checkResponse(r).then(throwOnApiError).then(unwrapApi).catch((e) => { | ||
throw Error(`Request ${r.url} failed with ${r.status}: ${e.message}`); | ||
@@ -222,3 +225,3 @@ }); | ||
// src/index.ts | ||
var DEFAULT_BASE_URL = "https://5pz08znmzj.execute-api.us-west-2.amazonaws.com"; | ||
var DEFAULT_BASE_URL = "https://api.iudex.ai"; | ||
var Iudex = class { | ||
@@ -249,21 +252,53 @@ baseUrl; | ||
}; | ||
sendMessage = async (message) => { | ||
if (!this.functionLinker) { | ||
throw Error( | ||
"Establish a way to call functions using `.linkFunctions` before sending a message." | ||
); | ||
} | ||
const { workflowId } = await startWorkflow(this.baseUrl, this.apiKey)(message); | ||
/** | ||
* @param message message to send | ||
* @returns response as a chat object | ||
*/ | ||
sendChatTurn = async (message, opts = {}) => { | ||
const { onChatTurn } = opts; | ||
const userTurn = { | ||
id: "msg_ephemeral_" + (/* @__PURE__ */ new Date()).toISOString(), | ||
type: "text", | ||
sender: "you", | ||
timestamp: (/* @__PURE__ */ new Date()).toISOString(), | ||
text: message | ||
}; | ||
onChatTurn?.(userTurn); | ||
const { workflowId } = await startWorkflow(this.baseUrl, this.apiKey)(userTurn.text); | ||
let nextMessage2 = await poll(nextMessage(this.baseUrl, this.apiKey), [workflowId]); | ||
onChatTurn?.(nextMessage2); | ||
while (nextMessage2.type === "functionCall") { | ||
if (!this.functionLinker) { | ||
throw Error( | ||
"Establish a way to call functions using `.linkFunctions` before sending a message that might require your functions to answer." | ||
); | ||
} | ||
const fn = this.functionLinker(nextMessage2.functionName); | ||
const fnReturn = await fn(nextMessage2.functionArgs); | ||
const fnReturnTurn = { | ||
id: "msg_ephemeral_" + (/* @__PURE__ */ new Date()).toISOString(), | ||
type: "functionReturn", | ||
sender: nextMessage2.functionName, | ||
timestamp: (/* @__PURE__ */ new Date()).toISOString(), | ||
functionCallId: nextMessage2.functionCallId, | ||
functionReturn: JSON.stringify(fnReturn) | ||
}; | ||
onChatTurn?.(fnReturnTurn); | ||
await returnFunctionCall(this.baseUrl, this.apiKey)( | ||
nextMessage2.functionCallId, | ||
JSON.stringify(fnReturn) | ||
fnReturnTurn.functionCallId, | ||
fnReturnTurn.functionReturn | ||
); | ||
nextMessage2 = await poll(nextMessage(this.baseUrl, this.apiKey), [workflowId]); | ||
onChatTurn?.(nextMessage2); | ||
} | ||
return nextMessage2.text; | ||
return nextMessage2; | ||
}; | ||
/** | ||
* @param message message to send | ||
* @returns response message as a string | ||
*/ | ||
sendMessage = async (message) => { | ||
const chatTurn = await this.sendChatTurn(message); | ||
return chatTurn.text; | ||
}; | ||
// OpenAI interface shim | ||
@@ -270,0 +305,0 @@ chatCompletionsCreate = (body) => { |
{ | ||
"name": "iudex", | ||
"version": "0.7.6", | ||
"version": "0.8.7", | ||
"description": "Iudex client", | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "jest" | ||
}, | ||
"main": "./dist/index.js", | ||
@@ -41,7 +45,3 @@ "module": "./dist/index.mjs", | ||
"zod": "^3.21.4" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "jest" | ||
} | ||
} | ||
} |
# Iudex client | ||
**Easily build 🛠️ natural language interfaces for ✨ your own ✨ applications 💻** | ||
**✨ Build 🛠 With Next Gen LLM Function Calling ✨** | ||
Iudex is an API layer that allows you to quickly build applications that can use LLM reasoning in a way that is more | ||
accurate, secure, and scalable than the toy examples from other projects. Iudex does this by providing an out-of-the-box | ||
LLM orchestration architecture capable of working with millions of functions and documents. | ||
[Iudex](https://iudex.ai) is an agent accessible via API that provides more accurate, secure, and scalable LLM function calling. | ||
- Scales to support 1000s of functions per query, not 10s | ||
- Supports arbitrarily complex queries and automatically handles edgecases | ||
- Ensures accuracy and interpretability using automated task orchestration | ||
- Iudex never has to ingest your code or data | ||
**❗ Leverage the power 🦾 of LLMs 🤖 with Iudex ❗** | ||
Sign Up at [iudex.ai](https://iudex.ai) or shoot a message at support@iudex.ai to get an API key. | ||
## Installation | ||
```bash | ||
@@ -20,37 +23,8 @@ npm install iudex | ||
## Getting Started | ||
1. Sign up at [iudex.ai](https://iudex.ai) or shoot a message at support@iudex.ai to get an API key. | ||
2. Install either the Node or Python client into your project. For Node, use `npm install iudex`. | ||
3. Store the API key as an environment variable e.g. `IUDEX_API_KEY`. | ||
4. Upload your function specs as function JSON schema. | ||
5. Send a message to Iudex. | ||
6. Get a computed result back. | ||
## What can Iudex help you build? | ||
1. Chat bots that can perform actions. | ||
2. Connecting LLMs with any external APIs (Google, Reddit, Twitter, Slack, etc). | ||
3. Generating dashboards from events databases. | ||
4. Adding rules based evaluation to extracted data. | ||
## How Iudex Works | ||
Iudex works by first indexing your functions. Afterwards, when making a query, Iudex will figure out the best way to accomplish that query | ||
by intelligently sequencing the functions you have connected and with the prebuilt functions we have created. This way, Iudex ensures | ||
that the functions that get called do not suffer from hallucinations and can properly use the results from previously run functions. | ||
 | ||
## Quickstart | ||
## Usage | ||
*Basic example* | ||
@@ -57,0 +31,0 @@ |
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
6
8
180449
8
2359
224