You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/libs/experimental/langchain_experimental
Martin Krasser 79ed66f870
EXPERIMENTAL Generic LLM wrapper to support chat model interface with configurable chat prompt format (#8295)
## Update 2023-09-08

This PR now supports further models in addition to Lllama-2 chat models.
See [this comment](#issuecomment-1668988543) for further details. The
title of this PR has been updated accordingly.

## Original PR description

This PR adds a generic `Llama2Chat` model, a wrapper for LLMs able to
serve Llama-2 chat models (like `LlamaCPP`,
`HuggingFaceTextGenInference`, ...). It implements `BaseChatModel`,
converts a list of chat messages into the [required Llama-2 chat prompt
format](https://huggingface.co/blog/llama2#how-to-prompt-llama-2) and
forwards the formatted prompt as `str` to the wrapped `LLM`. Usage
example:

```python
# uses a locally hosted Llama2 chat model
llm = HuggingFaceTextGenInference(
    inference_server_url="http://127.0.0.1:8080/",
    max_new_tokens=512,
    top_k=50,
    temperature=0.1,
    repetition_penalty=1.03,
)

# Wrap llm to support Llama2 chat prompt format.
# Resulting model is a chat model
model = Llama2Chat(llm=llm)

messages = [
    SystemMessage(content="You are a helpful assistant."),
    MessagesPlaceholder(variable_name="chat_history"),
    HumanMessagePromptTemplate.from_template("{text}"),
]

prompt = ChatPromptTemplate.from_messages(messages)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
chain = LLMChain(llm=model, prompt=prompt, memory=memory)

# use chat model in a conversation
# ...
```

Also part of this PR are tests and a demo notebook.

- Tag maintainer: @hwchase17
- Twitter handle: `@mrt1nz`

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
10 months ago
..
agents Clean up deprecated agents and update __init__ in experimental (#12231) 11 months ago
autonomous_agents Type hints on varargs and kwargs that take anything should be `Any`. (#11950) 11 months ago
chat_models EXPERIMENTAL Generic LLM wrapper to support chat model interface with configurable chat prompt format (#8295) 10 months ago
comprehend_moderation Fixed some grammatical and Exception types issues (#12015) 11 months ago
cpal Add CI check that integration tests compile (#12090) 11 months ago
data_anonymizer Anonymizer small fixes (#11915) 11 months ago
fallacy_removal adding new chain for logical fallacy removal from model output in chain (#9887) 1 year ago
generative_agents Use a submodule for pydantic v1 compat (#9371) 1 year ago
graph_transformers Diffbot Graph Transformer / Neo4j Graph document ingestion (#9979) 1 year ago
llm_bash Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 11 months ago
llm_symbolic_math Add SymbolicMathChain to experiment in preparation for deprecation (#11129) 12 months ago
llms LM Format Enforcer Integration + Sample Notebook (#12625) 11 months ago
open_clip Add Chroma multimodal cookbook (#12952) 10 months ago
openai_assistant Move OAI assistants to langchain and add callbacks (#13236) 10 months ago
pal_chain Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 11 months ago
plan_and_execute Use a submodule for pydantic v1 compat (#9371) 1 year ago
prompt_injection_identifier HF Injection Identifier Refactor 1 year ago
prompts rename repo namespace to langchain-ai (#11259) 12 months ago
pydantic_v1 `poetry lock` the experimental package. (#9478) 1 year ago
retrievers add missing init files (#12114) 11 months ago
rl_chain Revise vowpal_wabbit notebook 12 months ago
smart_llm Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 11 months ago
sql fix llm_inputs duplication problem in intermediate_steps in SQLDatabaseChain (#10279) 12 months ago
synthetic_data fix experimental imports (#10875) 1 year ago
tabular_synthetic_data Install and use `ruff format` instead of black for code formatting. (#12585) 11 months ago
tools Clean up deprecated agents and update __init__ in experimental (#12231) 11 months ago
tot Install and use `ruff format` instead of black for code formatting. (#12585) 11 months ago
utilities Clean up deprecated agents and update __init__ in experimental (#12231) 11 months ago
__init__.py Add version to langchain_experimental (#11613) 12 months ago
py.typed Add `py.typed` file to `langchain-experimental`. (#9557) 1 year ago