Skip to content

Chat

Hopfield also provides simple APIs for interacting with chat models. It has different API providers with type guarantees with Zod.

API Providers

We currently only support OpenAI, but are working on adding further providers. Reach out on Discord or Github Discussions if you have any suggestions!

Usage

Check out how we type responses:

ts
ts
import hop from "hopfield";
import openai from "hopfield/openai";
import OpenAI from "openai";
 
const hopfield = hop.client(openai).provider(new OpenAI());
 
const chat = hopfield.chat();
 
const parsed = await chat.get({
messages: [
{
content: "What's the best pizza restaurant in NYC?",
role: "user",
},
],
});
 
const choiceType = parsed.choices[0].__type;
(property) __type: "stop" | "length" | "content_filter"
ts
import hop from "hopfield";
import openai from "hopfield/openai";
import OpenAI from "openai";
 
const hopfield = hop.client(openai).provider(new OpenAI());
 
const chat = hopfield.chat();
 
const parsed = await chat.get({
messages: [
{
content: "What's the best pizza restaurant in NYC?",
role: "user",
},
],
});
 
const choiceType = parsed.choices[0].__type;
(property) __type: "stop" | "length" | "content_filter"

You can guarantee that your response is constructed correctly (with no optional accessors) and the embedding and outer array uses the tuple type, based on the inputs you requested.

Composability

The big unlock is not only that types are guaranteed to be safe - we provide composability to allow building complex apps with RAG and embedding-driven search.

INFO

We are actively working on building a RAG solution - please reach out if you are interested in influencing the API for this!

Learn More

Learn more about the intricacies embeddings in the Embeddings page.

Released under the MIT License.