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
importhop from "hopfield";importopenai from "hopfield/openai";importOpenAI from "openai";consthopfield =hop .client (openai ).provider (newOpenAI ());constchat =hopfield .chat ();constparsed = awaitchat .get ({messages : [{content : "What's the best pizza restaurant in NYC?",role : "user",},],});constchoiceType =parsed .choices [0].__type ;
ts
importhop from "hopfield";importopenai from "hopfield/openai";importOpenAI from "openai";consthopfield =hop .client (openai ).provider (newOpenAI ());constchat =hopfield .chat ();constparsed = awaitchat .get ({messages : [{content : "What's the best pizza restaurant in NYC?",role : "user",},],});constchoiceType =parsed .choices [0].__type ;
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.