Coder Social home page Coder Social logo

ai-chat-protocol's Introduction

Microsoft AI Chat Protocol

NPM Package TypeScript Build

The Microsoft AI Chat Protocol SDK is a library for easily building AI Chat interfaces from services that follow the AI Chat Protocol API Specification, both of which are located in this repository.

By agreeing on a standard API contract, AI backend consumption and evaluation can be performed easily and consistently across different services regardless of the models, orchestration tooling, or design patterns used.

Note: we are currently in public preview. Your feedback is greatly appreciated as we get ready to be generally available!

With the AI Chat Protocol, you will be able to:

  • Develop AI chat interfaces, components, and applications in JavaScript/TypeScript (more languages to follow!)
  • Consistently consume and evaluate AI inference backends and middle tiers with ease, either synchronously or by streaming
  • Easily incorporate HTTP middleware for logging, authentication, and more.

Please star the repo to show your support for this project!

Getting Started

Our comprehensive getting started guide is coming soon! Be sure to check out the samples and API specification for more details.

To take a look locally, install the library via npm:

npm install @microsoft/ai-chat-protocol

Create the client object:

const client = new AIChatProtocolClient("/api/chat");

Stream completions to your UI:

let sessionState = undefined;

// add any logic to handle state here
function setSessionState(value) {
    sessionState = value;
}

const message: AIChatMessage = {
    role: "user",
    content: "Hello World!",
};

const result = await client.getStreamedCompletion([message], {
    sessionState: sessionState,
});

for await (const response of result) {
    if (response.sessionState) {
        //do something with the session state returned
    }
    if (response.delta.role) {
        // do something with the information about the role
    }
    if (response.delta.content) { 
        // do something with the content of the message
    }
}

Samples on Azure

If you're curious on samples hosted on Azure, the following samples utilize the AI Chat Protocol SDK on the frontend:

Additionally, many Azure AI sample projects utilize the AI Chat Protocol API spec without the SDK, either because they don't have a frontend, or because they were made before the library's release:

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT license.

ai-chat-protocol's People

Contributors

glecaros avatar rohit-ganguly avatar dargilco avatar dependabot[bot] avatar microsoftopensource avatar achandmsft avatar codebytes avatar pamelafox avatar

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.