ChatModel
A language model that continues a conversation. It is the only thing the rest of this module needs from a model provider, so a graph written against it runs on every Kotlin target and with any provider.
Use an implementation from an integration module (telar-anthropic, telar-openai, telar-langchain4j), or write one. In a test, a lambda is enough:
val model = ChatModel { request -> ChatResponse(ChatMessage.Assistant("Hello!")) }chat waits for the whole answer and stream delivers it piece by piece. A model of your own only needs chat.
Functions
Returns the model's next message for request as an instance of the @Serializable class Answer, with the message it was read from. Use it to ask for a value at the end of a conversation. See the overload with a prompt for how the model is asked.
Sends prompt as a single user message and returns the answer as an instance of the @Serializable class Answer, for a node that needs a value from the model and not a text.
Returns the model's next message for request as a value read with serializer. See the overload with a reified type.
Returns the model's next message for request.
Sends prompt as a single user message and returns the text of the answer, for a node that only needs a piece of text from the model. Call ChatModel.chat with a ChatRequest when you need to know whether the answer was cut off.
Returns the model's next message for request, like ChatModel.chat, and lets a streamed run watch the model write it. Use it in a node in place of ChatModel.chat:
Sends prompt as a single user message and returns the text of the answer, like chat with a prompt, and lets a streamed run watch the model write it. See the overload with a ChatRequest.
Returns the model's next message for request as the model writes it: a ChatEvent.TextDelta for each piece of text, and then one ChatEvent.Completed with the whole answer. The flow is cold: the model is asked when the flow is collected.