rllm.llm.LangChainLLM

class rllm.llm.LangChainLLM(llm: BaseLanguageModel, system_prompt: str | None = None, messages_to_prompt: Callable[[Sequence[ChatMessage]], str] | None = None, completion_to_prompt: Callable[[str], str] | None = None, output_parser: BaseOutputParser | None = None)[source]

Bases: LLM

Adapter for a LangChain LLM.

Examples

pip install llama-index-llms-langchain

```python from langchain_openai import ChatOpenAI

from rllm.llm.llm_module.langchain import LangChainLLM

llm = LangChainLLM(llm=ChatOpenAI(…))

response_gen = llm.complete(“What is the meaning of life?”) ```

chat(messages: Sequence[ChatMessage], **kwargs) ChatResponse[source]

Chat endpoint for LLM.

Parameters:
  • messages (Sequence[ChatMessage]) – Sequence of chat messages.

  • kwargs (Any) – Additional keyword arguments to pass to the LLM.

Returns:

Chat response from the LLM.

Return type:

ChatResponse

Examples

```python from rllm.llm.types import ChatMessage

response = llm.chat([ChatMessage(role=”user”, content=”Hello”)]) print(response.content) ```

complete(prompt: str, formatted: bool = False, **kwargs) CompletionResponse[source]

Completion endpoint for LLM.

If the LLM is a chat model, the prompt is transformed into a single user message.

Parameters:
  • prompt (str) – Prompt to send to the LLM.

  • formatted (bool, optional) – Whether the prompt is already formatted for the LLM, by default False.

  • kwargs (Any) – Additional keyword arguments to pass to the LLM.

Returns:

Completion response from the LLM.

Return type:

CompletionResponse

Examples

`python response = llm.complete("your prompt") print(response.text) `

property metadata: LLMMetadata

LLM metadata.

Returns:

LLM metadata containing various information about the LLM.

Return type:

LLMMetadata