Javascript / Typescript SDK
Learn how to use the SDKs to interact with the Latitude API.
Latitude SDK Documentation
The Latitude SDK provides an easy way to interact with the Latitude API, allowing you to run documents and chat with AI models.
You can reach out to us with any question or request through our Slack channel.
Installation
To install the Latitude SDK, use your preferred package manager:
Getting Started
First, import the Latitude class from the SDK:
Then, create an instance of the Latitude class with your API key:
Running a Document
To run a document, use the run
method:
Chatting with an AI Model
The document run method previously described returns events which all contain a
singular uuid
field. This field can be used to further continue the
conversation with the document, including the context from the document run.
Here’s how to do it.
To continue a chat conversation, use the chat
method:
Handling Streams
Both run
and chat
methods return streams of events. You can handle these events in real-time using the onEvent
callback:
Error Handling
Errors are handled through the onError
callback. It’s recommended to always provide this callback to catch and handle any errors that may occur during execution:
IMPORTANT: If you don’t provide onError
callback await sdk.run
will throw an error.
Pushing a log to Latitude
You can push a log to Latitude in order to evaluate it, using the log
method:
Logs follow OpenAI’s format. If you’re using a different method to run your prompts, you’ll need to format your logs accordingly.
If you include the assistant response in the optional response
parameter,
make sure to not include it in the log so it isn’t included twice.
Evaluating Conversations
To evaluate a conversation using configured evaluators, use the eval
method:
This allows you to evaluate a conversation at any point in time. Specially helpful when building agents that have multiple interactions with users, and you intend to evaluate the agent’s performance after the interaction is fully completed, or at particular points in time.