vectara / stream-query-client

A TypeScript utility for easily making requests/parsing responses to/from Vectara's streaming query API
Apache License 2.0
3 stars 0 forks source link

Add client and types for API v2 #19

Closed cjcenizal closed 2 months ago

cjcenizal commented 2 months ago

Summary

The API v2 client is unopinionated. It accepts configuration options that are a 1:1 representation of the API configuration options. It also doesn't preprocess the results -- that's left to the consumer. This will make it easier for folks who are familiar with the API or reading the API docs to map concepts to the client.

To-do

Bug fixes

New features

Breaking changes

Package interface is now:

import {
  streamQueryV1,
  ApiV1,
  streamQueryV2,
  ApiV2,
} from "@vectara/stream-query-client";

The API has been dramatically simplified and ergonomics much improved, so I don't think we need to inject any opinions or sugar into the interface. As a result, requests are now configured with the same objects and fields as described in the Corpus Query docs.

StreamEvent now has this shape:

export type StreamEvent =
  | ErrorEvent
  | SearchResultsEvent
  | ChatInfoEvent
  | GenerationChunkEvent
  | FactualConsistencyScoreEvent
  | EndEvent;

export type ErrorEvent = {
  type: "error";
  messages?: string[];
};

export type SearchResultsEvent = {
  type: "searchResults";
  searchResults: SearchResult[];
};

export type ChatInfoEvent = {
  type: "chatInfo";
  chatId: string;
  turnId: string;
};

export type GenerationChunkEvent = {
  type: "generationChunk";
  updatedText: string;
  generationChunk: string;
};

export type FactualConsistencyScoreEvent = {
  type: "factualConsistencyScore";
  factualConsistencyScore: number;
};

export type EndEvent = {
  type: "end";
};

References

https://javascript.info/fetch-abort https://github.com/whatwg/streams/issues/1255 https://github.com/openai/openai-node/blob/master/src/streaming.ts