You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+113-42
Original file line number
Diff line number
Diff line change
@@ -26,9 +26,9 @@ Use Ax and get an end-to-end streaming, multi-modal DSPy framework with agents a
26
26
27
27
<imgwidth="860"alt="shapes at 24-03-31 00 05 55"src="https://github.com/dosco/llm-client/assets/832235/0f0306ea-1812-4a0a-9ed5-76cd908cd26b">
28
28
29
-
Efficient type-safe prompts are auto-generated from a simple signature. A prompt signature is made up of a`"task description" inputField:type "field description" -> "outputField:type`. The idea behind prompt signatures is based on work done in the "Demonstrate-Search-Predict" paper.
29
+
Efficient type-safe prompts are auto-generated from a simple signature. A prompt signature is made up of a`"task description" inputField:type "field description" -> "outputField:type`. The idea behind prompt signatures is based on work done in the "Demonstrate-Search-Predict" paper.
30
30
31
-
You can have multiple input and output fields, and each field can be of the types`string`,`number`,`boolean`,`date`, `datetime`, `class "class1, class2"`, `JSON`, or an array of any of these, e.g.,`string[]`. When a type is not defined, it defaults to`string`. The underlying AI is encouraged to generate the correct JSON when the `JSON` type is used.
31
+
You can have multiple input and output fields, and each field can be of the types`string`,`number`,`boolean`,`date`, `datetime`, `class "class1, class2"`, `JSON`, or an array of any of these, e.g.,`string[]`. When a type is not defined, it defaults to`string`. The suffix `?` makes the field optional (required by default) and `!` makes the field internal which is good for things like reasoning.
32
32
33
33
## Output Field Types
34
34
@@ -46,6 +46,7 @@ You can have multiple input and output fields, and each field can be of the type
46
46
|`date[]`| An array of dates. |`holidayDates:date[]`|`["2023-10-01", "2023-10-02"]`|
47
47
|`datetime[]`| An array of date and time values. |`logTimestamps:datetime[]`|`["2023-10-01T12:00:00Z", "2023-10-02T12:00:00Z"]`|
|`code "language"`| A code block in a specific language |`code:code "python"`|`print('Hello, world!')`|
49
50
50
51
51
52
@@ -167,7 +168,7 @@ Launch Apache Tika
167
168
docker run -p 9998:9998 apache/tika
168
169
```
169
170
170
-
Convert documents to text and embed them for retrieval using the`AxDBManager`, which also supports a reranker and query rewriter. Two default implementations, `AxDefaultResultReranker` and `AxDefaultQueryRewriter`, are available.
171
+
Convert documents to text and embed them for retrieval using the`AxDBManager`, which also supports a reranker and query rewriter. Two default implementations, `AxDefaultResultReranker` and `AxDefaultQueryRewriter`, are available.
171
172
172
173
```typescript
173
174
const tika =newAxApacheTika();
@@ -182,7 +183,7 @@ console.log(matches);
182
183
183
184
## Multi-modal DSPy
184
185
185
-
When using models like`GPT-4o`and`Gemini`that support multi-modal prompts, we support using image fields, and this works with the whole DSP pipeline.
186
+
When using models like`GPT-4o`and`Gemini`that support multi-modal prompts, we support using image fields, and this works with the whole DSP pipeline.
186
187
187
188
```typescript
188
189
const image =fs
@@ -197,7 +198,7 @@ const res = await gen.forward(ai, {
197
198
});
198
199
```
199
200
200
-
When using models like`gpt-4o-audio-preview`that support multi-modal prompts with audio support, we support using audio fields, and this works with the whole DSP pipeline.
201
+
When using models like`gpt-4o-audio-preview`that support multi-modal prompts with audio support, we support using audio fields, and this works with the whole DSP pipeline.
Ax provides two powerful ways to work with multiple AI services: a load balancer for high availability and a router for model-specific routing.
294
296
295
-
A special router that uses no LLM calls, only embeddings, to route user requests smartly.
297
+
### Load Balancer
296
298
297
-
Use the Router to efficiently route user queries to specific routes designed to handle certain questions or tasks. Each route is tailored to a particular domain or service area. Instead of using a slow or expensive LLM to decide how user input should be handled, use our fast "Semantic Router," which uses inexpensive and fast embedding queries.
299
+
The load balancer automatically distributes requests across multiple AI services based on performance and availability. If one service fails, it automatically fails over to the next available service.
298
300
299
301
```typescript
300
-
# npm run tsx ./src/examples/routing.ts
301
-
302
-
const customerSupport = new AxRoute('customerSupport', [
303
-
'how can I return a product?',
304
-
'where is my order?',
305
-
'can you help me with a refund?',
306
-
'I need to update my shipping address',
307
-
'my product arrived damaged, what should I do?'
308
-
]);
302
+
import { AxAI, AxBalancer } from'@ax-llm/ax'
309
303
310
-
const technicalSupport = new AxRoute('technicalSupport', [
311
-
'how do I install your software?',
312
-
'I’m having trouble logging in',
313
-
'can you help me configure my settings?',
314
-
'my application keeps crashing',
315
-
'how do I update to the latest version?'
316
-
]);
304
+
// Setup multiple AI services
305
+
const openai =newAxAI({
306
+
name: 'openai',
307
+
apiKey: process.env.OPENAI_APIKEY,
308
+
})
317
309
318
-
const ai = new AxAI({ name: 'openai', apiKey: process.env.OPENAI_APIKEY as string });
310
+
const ollama =newAxAI({
311
+
name: 'ollama',
312
+
config: { model: "nous-hermes2" }
313
+
})
319
314
320
-
const router = new AxRouter(ai);
321
-
await router.setRoutes(
322
-
[customerSupport, technicalSupport],
323
-
{ filename: 'router.json' }
324
-
);
315
+
const gemini =newAxAI({
316
+
name: 'google-gemini',
317
+
apiKey: process.env.GOOGLE_APIKEY
318
+
})
325
319
326
-
const tag = await router.forward('I need help with my order');
const res =awaitgen.forward(balancer,{ question: 'Hello!' })
331
+
```
332
+
333
+
### Multi-Service Router
334
+
335
+
The router lets you use multiple AI services through a single interface, automatically routing requests to the right service based on the model specified.
const res =awaitgen.forward(router, { question: 'Hello!' })
399
+
```
400
+
401
+
The load balancer is ideal for high availability while the router is perfect when you need specific models for specific tasks Both can be used with any of Ax's features like streaming, function calling, and chain-of-thought prompting.
402
+
403
+
**They can also be used together**
404
+
405
+
You can also use the balancer and the router together either the multiple balancers can be used with the router or the router can be used with the balancer.
335
406
336
407
## Vercel AI SDK Integration
337
408
@@ -397,7 +468,7 @@ const result = await streamUI({
397
468
398
469
## OpenTelemetry support
399
470
400
-
The ability to trace and observe your llm workflow is critical to building production workflows. OpenTelemetry is an industry-standard, and we support the new`gen_ai`attribute namespace.
471
+
The ability to trace and observe your llm workflow is critical to building production workflows. OpenTelemetry is an industry-standard, and we support the new`gen_ai`attribute namespace.
401
472
402
473
```typescript
403
474
import { trace } from'@opentelemetry/api';
@@ -531,7 +602,7 @@ console.log(res);
531
602
532
603
## Check out all the examples
533
604
534
-
Use the`tsx`command to run the examples. It makes the node run typescript code. It also supports using an`.env`file to pass the AI API Keys instead of putting them in the command line.
605
+
Use the`tsx`command to run the examples. It makes the node run typescript code. It also supports using an`.env`file to pass the AI API Keys instead of putting them in the command line.
535
606
536
607
```shell
537
608
OPENAI_APIKEY=openai_key npm run tsx ./src/examples/marketing.ts
It is essential to remember that we should only run`npm install`from the root directory. This prevents the creation of nested`package-lock.json`files and avoids non-deduplicated`node_modules`.
755
+
It is essential to remember that we should only run`npm install`from the root directory. This prevents the creation of nested`package-lock.json`files and avoids non-deduplicated`node_modules`.
685
756
686
-
Adding new dependencies in packages should be done with e.g.`npm install lodash --workspace=ax`(or just modify the appropriate`package.json`and run`npm install`from root).
757
+
Adding new dependencies in packages should be done with e.g.`npm install lodash --workspace=ax`(or just modify the appropriate`package.json`and run`npm install`from root).
0 commit comments