Code Monkey home page Code Monkey logo

ax's Introduction

Ax - Build LLMs Powered Agents (Typescript)

Build intelligent agents quickly — inspired by the power of "Agentic workflows" and the Stanford DSPy paper. Seamlessly integrates with multiple LLMs and VectorDBs to build RAG pipelines or collaborative agents that can solve complex problems. Advanced features streaming validation, multi-modal DSPy, etc.

NPM Package Discord Chat Twitter

image

Our focus on agents

We've renamed from "llmclient" to "ax" to highlight our focus on powering agentic workflows. We agree with many experts like "Andrew Ng" that agentic workflows are the key to unlocking the true power of large language models and what can be achieved with in-context learning. Also, we are big fans of the Stanford DSPy paper, and this library is the result of all of this coming together to build a powerful framework for you to build with.

image

Why use Ax?

  • Support for various LLMs and Vector DBs
  • Prompts auto-generated from simple signatures
  • Build Agents that can call other agents
  • Convert docs of any format to text
  • RAG, smart chunking, embedding, querying
  • Works with Vercel AI SDK
  • Output validation while streaming
  • Multi-modal DSPy supported
  • Automatic prompt tuning using optimizers
  • OpenTelemetry tracing / observability
  • Production ready Typescript code
  • Lite weight, zero-dependencies

What's a prompt signature?

shapes at 24-03-31 00 05 55

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.

You can have multiple input and output fields, and each field can be of the types stringnumberbooleanJSON, 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.

LLMs Supported

Provider Best Models Tested
OpenAI GPT: All 4 models 🟢 100%
Azure OpenAI GPT: All 4 models 🟢 100%
Together Several OSS Models 🟢 100%
Cohere CommandR, Command 🟢 100%
Anthropic Claude 2, Claude 3 🟢 100%
Mistral 7B, 8x7B, S, L 🟢 100%
Groq Lama2-70B, Mixtral-8x7b 🟢 100%
DeepSeek Chat and Code 🟢 100%
Ollama All models 🟢 100%
Google Gemini Gemini: Flash, Pro 🟢 100%
Hugging Face OSS Model 🟡 50%
Reka Core, Flash, Edge 🟡 50%

Install

npm install @ax-llm/ax
# or
yarn add @ax-llm/ax

Example: Using chain-of-thought to summarize text

import { AxAI, AxChainOfThought } from '@ax-llm/ax';

const textToSummarize = `
The technological singularity—or simply the singularity[1]—is a hypothetical future point in time at which technological growth becomes uncontrollable and irreversible, resulting in unforeseeable changes to human civilization.[2][3] ...`;

const ai = new AxAI({
  name: 'openai',
  apiKey: process.env.OPENAI_APIKEY as string
});

const gen = new AxChainOfThought(
  ai,
  `textToSummarize -> shortSummary "summarize in 5 to 10 words"`
);

const res = await gen.forward({ textToSummarize });

console.log('>', res);

Example: Building an agent

Use the agent prompt (framework) to build agents that work with other agents to complete tasks. Agents are easy to make with prompt signatures. Try out the agent example.

# npm run tsx ./src/examples/agent.ts

const researcher = new AxAgent(ai, {
  name: 'researcher',
  description: 'Researcher agent',
  signature: `physicsQuestion "physics questions" -> answer "reply in bullet points"`
});

const summarizer = new AxAgent(ai, {
  name: 'summarizer',
  description: 'Summarizer agent',
  signature: `text "text so summarize" -> shortSummary "summarize in 5 to 10 words"`
});

const agent = new AxAgent(ai, {
  name: 'agent',
  description: 'A an agent to research complex topics',
  signature: `question -> answer`,
  agents: [researcher, summarizer]
});

agent.forward({ questions: "How many atoms are there in the universe" })

Vector DBs Supported

Vector databases are critical to building LLM workflows. We have clean abstractions over popular vector databases and our own quick in-memory vector database.

Provider Tested
In Memory 🟢 100%
Weaviate 🟢 100%
Cloudflare 🟡 50%
Pinecone 🟡 50%
// Create embeddings from text using an LLM
const ret = await this.ai.embed({ texts: 'hello world' });

// Create an in memory vector db
const db = new axDB('memory');

// Insert into vector db
await this.db.upsert({
  id: 'abc',
  table: 'products',
  values: ret.embeddings[0]
});

// Query for similar entries using embeddings
const matches = await this.db.query({
  table: 'products',
  values: embeddings[0]
});

Alternatively you can use the AxDBManager which handles smart chunking, embedding and querying everything for you, it makes things almost too easy.

const manager = new AxDBManager({ ai, db });
await manager.insert(text);

const matches = await manager.query(
  'John von Neumann on human intelligence and singularity.'
);
console.log(matches);

RAG Documents

Using documents like PDF, DOCX, PPT, XLS, etc., with LLMs is a huge pain. We make it easy with Apache Tika, an open-source document processing engine.

Launch Apache Tika

docker run -p 9998:9998 apache/tika

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.

const tika = new AxApacheTika();
const text = await tika.convert('/path/to/document.pdf');

const manager = new AxDBManager({ ai, db });
await manager.insert(text);

const matches = await manager.query('Find some text');
console.log(matches);

Multi-modal DSPy

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.

const image = fs
  .readFileSync('./src/examples/assets/kitten.jpeg')
  .toString('base64');

const gen = new AxChainOfThought(ai, `question, animalImage:image -> answer`);

const res = await gen.forward({
  question: 'What family does this animal belong to?',
  animalImage: { mimeType: 'image/jpeg', data: image }
});

Streaming

We support parsing output fields and function execution while streaming. This allows for fail-fast and error correction without waiting for the whole output, saving tokens and costs and reducing latency. Assertions are a powerful way to ensure the output matches your requirements; they also work with streaming.

// setup the prompt program
const gen = new AxChainOfThought(
  ai,
  `startNumber:number -> next10Numbers:number[]`
);

// add a assertion to ensure that the number 5 is not in an output field
gen.addAssert(({ next10Numbers }: Readonly<{ next10Numbers: number[] }>) => {
  return next10Numbers ? !next10Numbers.includes(5) : undefined;
}, 'Numbers 5 is not allowed');

// run the program with streaming enabled
const res = await gen.forward({ startNumber: 1 }, { stream: true });

The above example allows you to validate entire output fields as they are streamed in. This validation works with streaming and when not streaming and is triggered when the whole field value is available. For true validation while streaming, check out the example below. This will massively improve performance and save tokens at scale in production.

// add a assertion to ensure all lines start with a number and a dot.
gen.addStreamingAssert(
  'answerInPoints',
  (value: string) => {
    const re = /^\d+\./;

    // split the value by lines, trim each line,
    // filter out empty lines and check if all lines match the regex
    return value
      .split('\n')
      .map((x) => x.trim())
      .filter((x) => x.length > 0)
      .every((x) => re.test(x));
  },
  'Lines must start with a number and a dot. Eg: 1. This is a line.'
);

// run the program with streaming enabled
const res = await gen.forward(
  {
    question: 'Provide a list of optimizations to speedup LLM inference.'
  },
  { stream: true, debug: true }
);

Fast LLM Router

A special router that uses no LLM calls, only embeddings, to route user requests smartly.

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.

# npm run tsx ./src/examples/routing.ts

const customerSupport = new AxRoute('customerSupport', [
  'how can I return a product?',
  'where is my order?',
  'can you help me with a refund?',
  'I need to update my shipping address',
  'my product arrived damaged, what should I do?'
]);

const technicalSupport = new AxRoute('technicalSupport', [
  'how do I install your software?',
  'I’m having trouble logging in',
  'can you help me configure my settings?',
  'my application keeps crashing',
  'how do I update to the latest version?'
]);

const ai = new AxAI({ name: 'openai', apiKey: process.env.OPENAI_APIKEY as string });

const router = new AxRouter(ai);
await router.setRoutes(
  [customerSupport, technicalSupport],
  { filename: 'router.json' }
);

const tag = await router.forward('I need help with my order');

if (tag === "customerSupport") {
    ...
}
if (tag === "technicalSupport") {
    ...
}

Vercel AI SDK Integration

Install the ax provider package

npm i @ax-llm/ax-ai-sdk-provider

Then use it with the AI SDK, you can either use the AI provider or the Agent Provider

const ai = new AxAI({
    name: 'openai',
    apiKey: process.env['OPENAI_APIKEY'] ?? "",
});

// Create a model using the provider
const model = new AxAIProvider(ai);

export const foodAgent = new AxAgent(ai, {
  name: 'food-search',
  description:
    'Use this agent to find restaurants based on what the customer wants',
  signature,
  functions
})

// Get vercel ai sdk state
const aiState = getMutableAIState()

// Create an agent for a specific task
const foodAgent = new AxAgentProvider({
    agent: foodAgent,
    updateState: (state) => {
         aiState.done({ ...aiState.get(), state })
    },
    generate: async ({ restaurant, priceRange }) => {
        return (
            <BotCard>
                <h1>{restaurant as string} {priceRange as string}</h1>
            </BotCard>
        )
    }
})

// Use with streamUI a critical part of building chat UIs in the AI SDK
const result = await streamUI({
    model,
    initial: <SpinnerMessage />,
    messages: [
        // ...
    ],
    text: ({ content, done, delta }) => {
        // ...
    },
    tools: {
        // @ts-ignore
        'find-food': foodAgent,
    }
})

OpenTelemetry support

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.

import { trace } from '@opentelemetry/api';
import {
  BasicTracerProvider,
  ConsoleSpanExporter,
  SimpleSpanProcessor
} from '@opentelemetry/sdk-trace-base';

const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
trace.setGlobalTracerProvider(provider);

const tracer = trace.getTracer('test');

const ai = new AxAI({
  name: 'ollama',
  config: { model: 'nous-hermes2' },
  options: { tracer }
});

const gen = new AxChainOfThought(
  ai,
  `text -> shortSummary "summarize in 5 to 10 words"`
);

const res = await gen.forward({ text });
{
  "traceId": "ddc7405e9848c8c884e53b823e120845",
  "name": "Chat Request",
  "id": "d376daad21da7a3c",
  "kind": "SERVER",
  "timestamp": 1716622997025000,
  "duration": 14190456.542,
  "attributes": {
    "gen_ai.system": "Ollama",
    "gen_ai.request.model": "nous-hermes2",
    "gen_ai.request.max_tokens": 500,
    "gen_ai.request.temperature": 0.1,
    "gen_ai.request.top_p": 0.9,
    "gen_ai.request.frequency_penalty": 0.5,
    "gen_ai.request.llm_is_streaming": false,
    "http.request.method": "POST",
    "url.full": "http://localhost:11434/v1/chat/completions",
    "gen_ai.usage.completion_tokens": 160,
    "gen_ai.usage.prompt_tokens": 290
  }
}

Tuning the prompts (programs)

You can tune your prompts using a larger model to help them run more efficiently and give you better results. This is done by using an optimizer like AxBootstrapFewShot with and examples from the popular HotPotQA dataset. The optimizer generates demonstrations demos which when used with the prompt help improve its efficiency.

// Download the HotPotQA dataset from huggingface
const hf = new AxHFDataLoader({
  dataset: 'hotpot_qa',
  split: 'train'
});

const examples = await hf.getData<{ question: string; answer: string }>({
  count: 100,
  fields: ['question', 'answer']
});

const ai = new AxAI({
  name: 'openai',
  apiKey: process.env.OPENAI_APIKEY as string
});

// Setup the program to tune
const program = new AxChainOfThought<{ question: string }, { answer: string }>(
  ai,
  `question -> answer "in short 2 or 3 words"`
);

// Setup a Bootstrap Few Shot optimizer to tune the above program
const optimize = new AxBootstrapFewShot<
  { question: string },
  { answer: string }
>({
  program,
  examples
});

// Setup a evaluation metric em, f1 scores are a popular way measure retrieval performance.
const metricFn: AxMetricFn = ({ prediction, example }) =>
  emScore(prediction.answer as string, example.answer as string);

// Run the optimizer and remember to save the result to use later
const result = await optimize.compile(metricFn);
tune-prompt

And to use the generated demos with the above ChainOfThought program

const ai = new AxAI({
  name: 'openai',
  apiKey: process.env.OPENAI_APIKEY as string
});

// Setup the program to use the tuned data
const program = new AxChainOfThought<{ question: string }, { answer: string }>(
  ai,
  `question -> answer "in short 2 or 3 words"`
);

// load tuning data
program.loadDemos('demos.json');

const res = await program.forward({
  question: 'What castle did David Gregory inherit?'
});

console.log(res);

Built-in Functions

Function Name Description
JS Interpreter AxJSInterpreter Execute JS code in a sandboxed env
Docker Sandbox AxDockerSession Execute commands within a docker environment
Embeddings Adapter AxEmbeddingAdapter Fetch and pass embedding to your function

Check out all the examples

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.

OPENAI_APIKEY=openai_key npm run tsx ./src/examples/marketing.ts
Example Description
customer-support.ts Extract valuable details from customer communications
food-search.ts Use multiple APIs are used to find dinning options
marketing.ts Generate short effective marketing sms messages
vectordb.ts Chunk, embed and search text
fibonacci.ts Use the JS code interpreter to compute fibonacci
summarize.ts Generate a short summary of a large block of text
chain-of-thought.ts Use chain-of-thought prompting to answer questions
rag.ts Use multi-hop retrieval to answer questions
rag-docs.ts Convert PDF to text and embed for rag search
react.ts Use function calling and reasoning to answer questions
agent.ts Agent framework, agents can use other agents, tools etc
qna-tune.ts Use an optimizer to improve prompt efficiency
qna-use-tuned.ts Use the optimized tuned prompts
streaming1.ts Output fields validation while streaming
streaming2.ts Per output field validation while streaming
smart-hone.ts Agent looks for dog in smart home
multi-modal.ts Use an image input along with other text inputs
balancer.ts Balance between various llm's based on cost, etc
docker.ts Use the docker sandbox to find files by description

Our Goal

Large language models (LLMs) are becoming really powerful and have reached a point where they can work as the backend for your entire product. However, there's still a lot of complexity to manage from using the correct prompts, models, streaming, function calls, error correction, and much more. We aim to package all this complexity into a well-maintained, easy-to-use library that can work with all state-of-the-art LLMs. Additionally, we are using the latest research to add new capabilities like DSPy to the library.

How to use this library?

1. Pick an AI to work with

// Pick a LLM
const ai = new AxOpenAI({ apiKey: process.env.OPENAI_APIKEY } as AxOpenAIArgs);

2. Create a prompt signature based on your usecase

// Signature defines the inputs and outputs of your prompt program
const cot = new ChainOfThought(ai, `question:string -> answer:string`, { mem });

3. Execute this new prompt program

// Pass in the input fields defined in the above signature
const res = await cot.forward({ question: 'Are we in a simulation?' });

4. Or if you just want to directly use the LLM

const res = await ai.chat([
  { role: "system", content: "Help the customer with his questions" }
  { role: "user", content: "I'm looking for a Macbook Pro M2 With 96GB RAM?" }
]);

How do you use function calling

1. Define the functions

// define one or more functions and a function handler
const functions = [
  {
    name: 'getCurrentWeather',
    description: 'get the current weather for a location',
    parameters: {
      type: 'object',
      properties: {
        location: {
          type: 'string',
          description: 'location to get weather for'
        },
        units: {
          type: 'string',
          enum: ['imperial', 'metric'],
          default: 'imperial',
          description: 'units to use'
        }
      },
      required: ['location']
    },
    func: async (args: Readonly<{ location: string; units: string }>) => {
      return `The weather in ${args.location} is 72 degrees`;
    }
  }
];

2. Pass the functions to a prompt

const cot = new AxReAct(ai, `question:string -> answer:string`, { functions });

Enable debug logs

const ai = new AxOpenAI({ apiKey: process.env.OPENAI_APIKEY } as AxOpenAIArgs);
ai.setOptions({ debug: true });

Reach out

We're happy to help reach out if you have questions or join the Discord twitter/dosco

FAQ

1. The LLM can't find the correct function to use

Improve the function naming and description. Be very clear about what the function does. Also, ensure the function parameters have good descriptions. The descriptions can be a little short but need to be precise.

2. How do I change the configuration of the LLM I'm using?

You can pass a configuration object as the second parameter when creating a new LLM object.

const apiKey = process.env.OPENAI_APIKEY;
const conf = AxOpenAIBestConfig();
const ai = new AxOpenAI({ apiKey, conf } as AxOpenAIArgs);

3. My prompt is too long / can I change the max tokens?

const conf = axOpenAIDefaultConfig(); // or OpenAIBestOptions()
conf.maxTokens = 2000;

4. How do I change the model? (e.g., I want to use GPT4)

const conf = axOpenAIDefaultConfig(); // or OpenAIBestOptions()
conf.model = OpenAIModel.GPT4Turbo;

Monorepo tips & tricks

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.

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).

ax's People

Contributors

beddows avatar dosco avatar helloalexpan avatar karol-f avatar marcbuils avatar mileszim avatar polydeuxes avatar tyronemichael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ax's Issues

Ask-Question.js

Dosco, in the examples folder you have an ask-questions.js file mentioned in the readme but the actual file example is not linked. This the file that shows how to use Google Search with your library. Any chance you can add it?

Where to get tracer output?

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ x] question about how to use this project

  • Summary

Hi.

In your Open Telemetry example code you show some setup and then the output, but you don't show where the trace below is being acquired from. How do you access that?

I tried some example code with cot.getTraces() but I only get the actual answer trace, not the statistical data as below from the ai call.
But I don't see any getTraces methods in the ai object or ai.tracer object

{
"traceId": "ddc7405e9848c8c884e53b823e120845",
"name": "Chat Request",
"id": "d376daad21da7a3c",
"kind": "SERVER",
"timestamp": 1716622997025000,
"duration": 14190456.542,
"attributes": {
"gen_ai.system": "Ollama",
"gen_ai.request.model": "nous-hermes2",
"gen_ai.request.max_tokens": 500,
"gen_ai.request.temperature": 0.1,
"gen_ai.request.top_p": 0.9,
"gen_ai.request.frequency_penalty": 0.5,
"gen_ai.request.llm_is_streaming": false,
"http.request.method": "POST",
"url.full": "http://localhost:11434/v1/chat/completions",
"gen_ai.usage.completion_tokens": 160,
"gen_ai.usage.prompt_tokens": 290
}
}

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Cohere AI provider error

I'm submitting a bug report

  • Summary
    The following code causes the exception: Cannot read properties of undefined (reading 'map'), this happens when calling a.forward
const ai = new Anthropic({
  apiKey,
});
const cot = new ChainOfThought(
  ai,
  `question:string -> answer:string`
);
const res = await a.forward({ question });

Error processing text: Error: Embed model not set when using ollama.

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [X ] question about how to use this project

  • Summary
    I modified the example vectordb.ts to use ollama:

const ai = axAI('ollama', {
  model: 'llama3:latest',
  url: 'http://localhost:11434'
} as AxOllamaArgs);

but got this error:

PS C:\Users\remis\ax\src\examples> bun run .\vectordb.ts
 98 | 
 99 |         // Batch upsert embeddings
100 |         await this.db.batchUpsert(embeddings);
101 |       }
102 |     } catch (error) {
103 |       throw new Error(`Error processing text: ${error}`);
                  ^
error: Error processing text: Error: Embed model not set
      at C:\Users\remis\ax\src\docs\manager.ts:103:13
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Indeed in ollama i have only one model: 'llama3:latest' installed. Should I install an embedding model like explained here https://ollama.com/blog/embedding-models

But then how do I configure this model in here:

export type AxOllamaArgs = {
  model: string;
  url?: string;
  apiKey?: string;
  config?: Readonly<Omit<AxOllamaAIConfig, 'model'>>;
  options?: Readonly<AxAIServiceOptions>;
};

thanks for the help!

Aws bedrock

  • I'm submitting a ...
    [ ] bug report
    [X ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Looking to add custom providers but immediately
looking for AWS Bedrock provider. Possible to add that?

This helps to integrate with new providers easily. Looking forward for an update soon.

Documentation?

Hey guys,

First I wanted to start by thanking the repo owner for including example scripts and samples in the README. However, I was wondering if there is any link to documentation that describes all the methods and classes available. This would be helpful in understanding how to leverage the package for novel workflows that have not been covered by the samples yet.

Add Polyfill for TextDecoderStream to Ensure Compatibility with Bun

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

TextDecoderStream is currently not supported in Bun. I propose adding a polyfill for TextDecoderStream to ensure compatibility without requiring an additional import statement. This will enhance the usability of the project and prevent potential issues for users running their code in environments where TextDecoderStream is not natively supported.

Example:

import { TextDecoderStream as NativeTextDecoderStream } from 'stream/web';
import { TextDecoderStream as PolyfillTextDecoderStream } from './path/to/text-encoding-polyfill';

// Check if TextDecoderStream is available, if not use the polyfill
const TextDecoderStream = typeof NativeTextDecoderStream !== 'undefined' ? NativeTextDecoderStream : PolyfillTextDecoderStream;

export { TextDecoderStream }

MIPRO v2

  • I'm submitting a ...
    [x] feature request

  • Summary
    I would love to see MIPRO v2 implemented in here.

[Guide Request] Production Deployment

Discussed in #46

Originally posted by DanielSongYu July 4, 2024
Hi, thank you all for your effort on making this amazing open-source project.

Currently I'm trying to build PoCs with this DSP technology, but I want to go further to build actual services that can be used in production. You can imagine how excited I am to see this claim Production ready Typescript code.

I would really appreciate it if you could provide a very basic example on deploying an ax project (e.g. containerisation, cloud deployment setup) for production use.

Thank you again and I'm looking forward to your replies!

Error "Image type is not supported in output fields." for Input field

I'm submitting a:

  • bug report

Summary:

When using the AxGenerate::forward function with an input parameter of type image, the following error occurs: "Image type is not supported in output fields."

Other information:

Here is a detailed explanation of the problem:

  1. I called the AxGenerate::forward function with an image input parameter.
  2. The function threw an exception with the error message: "Image type is not supported in output fields."

I will propose a pull request to fix this issue.

Named export 'AxAI' not found when importing

  • I'm submitting a bug report

  • Summary
    On a fresh install, when importing AxAI, here is the log :

import { AxAI, AxChainOfThought } from '@ax-llm/ax';
         ^^^^
SyntaxError: Named export 'AxAI' not found. The requested module '@ax-llm/ax' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@ax-llm/ax';
const { AxAI, AxChainOfThought } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:254:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:475:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)

Note : I use vanilla JS, not TS

Azure OpenAI chat/completion call failed

  • I'm submitting a ...
    [ x ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    When I configure an azure model with the following code:
    const modelInstance = AI('azure-openai', {
    "apiKey": "123456789",
    "resourceName": "myResource",
    "deploymentName": "myDeployment",
    "version": "2024-02-01"
    });

Expected result:
End point called: https://sqalia.openai.azure.com/openai/deployments/Sqalia4o/chat/completions/?api-version=2024-02-01

Actual result:
End point called: https://sqalia.openai.azure.com/openai/deployments/Sqalia4o/chat/completions/
(with an error 404 not found because api-version is required)

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
    The issue is from the apiCall function who forgets the search parameters from baseURL

Prompt to extract details and classify customer communication

  • I'm submitting a ...
    [ ] bug report
    [ X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Build a new prompt to extract customer and product information. And to classify the customer communication.

Create a discussion listing business workflows to target

  • I'm submitting a ...
    [ ] bug report
    [X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Use Github discussions to start a discussion listing business workflow ideas we should target in this library. For example PII detection, Classification list for customer communications, Email communication rewriting, etc

Function calling (using food-search.ts)

I'm submitting a ...
[ x] bug report

Summary
I'm getting errors with:

Anthropic
@ax-llm/ax/build/module/src/util/apicall.js:39
        throw new Error(`API Error: ${apiUrl.href}, ${e}`);
              ^

Error: API Error: https://api.anthropic.com/v1/messages, Error: API Error: https://api.anthropic.com/v1/messages, 400, Bad Request
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Your API request included an `assistant` message in the final position, which would pre-fill the `assistant` response. When using tools, pre-filling the `assistant` response is not supported."
  }
}

Also:

  • Anthropic just released "claude-3-5-sonnet-20240620" 🎉
Groq
@ax-llm/ax/build/module/src/ai/openai/api.js:166
        ({ delta: { content, role, tool_calls }, finish_reason }) => {
                    ^

TypeError: Cannot read properties of undefined (reading 'content')

Also:

  • ai/groq/index.ts is missing "export * from './types.js';"
  • is 'AxAxGroqArgs' a typo?
Cohere

@ax-llm/ax/build/module/src/util/apicall.js:39
        throw new Error(`API Error: ${apiUrl.href}, ${e}`);
              ^

Error: API Error: https://api.cohere.ai/v1/generate, Error: API Error: https://api.cohere.ai/v1/generate, 400, Bad Request
{
  "message": "invalid request: prompt must be at least 1 token long."
}

Google

@ax-llm/ax/build/module/src/util/apicall.js:39
        throw new Error(`API Error: ${apiUrl.href}, ${e}`);
              ^

Error: API Error: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:streamGenerateContent?alt=sse&key=, Error: API Error: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:streamGenerateContent?alt=sse&key=, 400, Bad Request
{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"default\" at 'tools[0].function_declarations[0].parameters.properties[1].value': Cannot find field.\nInvalid JSON payload received. Unknown name \"default\" at 'tools[0].function_declarations[1].parameters.properties[1].value': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "tools[0].function_declarations[0].parameters.properties[1].value",
            "description": "Invalid JSON payload received. Unknown name \"default\" at 'tools[0].function_declarations[0].parameters.properties[1].value': Cannot find field."
          },
          {
            "field": "tools[0].function_declarations[1].parameters.properties[1].value",
            "description": "Invalid JSON payload received. Unknown name \"default\" at 'tools[0].function_declarations[1].parameters.properties[1].value': Cannot find field."
          }
        ]
      }
    ]
  }
}

Other observations:

  • DeepSeek worked quite well, except when I changed "sushi" to "sashimi", then it failed... But it's a coding model, not a foodie.
  • None of the Together function calling models worked (they're either confused or hallucinating):
    mistralai/Mixtral-8x7B-Instruct-v0.1
    mistralai/Mistral-7B-Instruct-v0.1
    togethercomputer/CodeLlama-34b-Instruct

Add Helicone support

  • I'm submitting a ...
    [ ] bug report
    [ X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Although Ax has OpenTelemetry support included I think it would be beneficial to add https://www.helicone.ai/ as a provider.
Helicone is also an Open Source project https://github.com/Helicone/helicone , so there's synergy there as well.

Accessing Stream Chunks (Streamed generation)

  • I'm submitting a ...
    [x] question about how to use this project

  • Summary
    I'm encountering two problems when working with the streaming example:

  1. When running the code from examples/streaming2.ts with stream: true, I get an error: Missing required fields: answerInPoints. What's causing this error and how can I resolve it?
  2. After setting stream: true, how can I access the result chunks? Are there methods similar to for await (const chunk of result) or completion.data.on() that I can use to process the incoming stream? (Similar to openai/openai-node#18)

Any guidance on resolving these issues would be greatly appreciated. Thank you!

Compilation errors

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [X ] question about how to use this project

  • Summary

Looks like a great project so I decided to test it out with a https://quasar.dev/ js project.
This is compatible with ts package imports, so I imported as per the guide.

So, the issue is I imported https://github.com/ax-llm/ax aok as per npm install @ax-llm/ax did a quasar build and my project is aok. Runs fine.
It's when I go to use AX strange things begine to happen.
If I add the following line to a file import { AxAgent, AxAI, AxFunction, AxSignature } from '@ax-llm/ax'; in preparation for using it I immediately get compilation error #1:

Compilation error 1: [Resolved]
Syntax Error: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

I fixed this by modifying the quaser.config chain webpack:
chainWebpack(chain) {
chain
.plugin("eslint-webpack-plugin")
.use(ESLintPlugin, [{ extensions: ["js", "vue"] }]),
chain.merge({
externals: {
"node:fs": "commonjs util",
},
});
},
},

So that passed, but then I got another bunch of compilation errors, which I copy just below.
I tried importing one out of interest [npm install --save stream/web] but that failed with fatal: Could not read from remote repository.

Any clues as to what is going on here? Would love to test it out in an integration project.
I ran the examples locally ok, just trying to integrate it into a basic Quasar js project doesn't seem to work too well.
Thanks!

Compilation errors #2 [Unresolved]

App • ERROR • UI in ./node_modules/@ax-llm/ax/ai/util.js

Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto

App • ERROR • UI in ./node_modules/@ax-llm/ax/dsp/generate.js

Module not found: Can't resolve imported dependency "stream/web"
Did you forget to install it? You can run: npm install --save stream/web

App • ERROR • UI in ./node_modules/@ax-llm/ax/dsp/sig.js

Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "http"
Did you forget to install it? You can run: npm install --save http

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "https"
Did you forget to install it? You can run: npm install --save https

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "os"
Did you forget to install it? You can run: npm install --save os

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "process"
Did you forget to install it? You can run: npm install --save process

App • ERROR • UI in ./node_modules/@ax-llm/ax/funcs/code.js

Module not found: Can't resolve imported dependency "vm"
Did you forget to install it? You can run: npm install --save vm

App • ERROR • UI in ./node_modules/@ax-llm/ax/util/apicall.js

Module not found: Can't resolve imported dependency "path"
Did you forget to install it? You can run: npm install --save path

App • ERROR • UI in ./node_modules/@ax-llm/ax/util/apicall.js

Module not found: Can't resolve imported dependency "stream/web"
Did you forget to install it? You can run: npm install --save stream/web

App • COMPILATION FAILED • Please check the log above for details.

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Allow to extend BaseAI

  • I'm submitting a ...
    [ ] bug report
    [X ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

We have a special AI client that customizes existing AI like Anthropic, Bedrock and OpenAI. In order to use llm-client with them, it helps to build on top of llm-client and requesting to make it possible.

  1. BaseAI - https://github.com/dosco/llm-client/blob/main/src/ai/base.ts#L43 OR
  2. a better alternative.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.