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>
2023-11-17 16:32:13 -08:00
..
agents Clean up deprecated agents and update __init__ in experimental (#12231) 2023-10-27 13:52:50 -04:00
autonomous_agents Type hints on varargs and kwargs that take anything should be Any. (#11950) 2023-10-17 21:31:44 -04:00
chat_models EXPERIMENTAL Generic LLM wrapper to support chat model interface with configurable chat prompt format (#8295) 2023-11-17 16:32:13 -08:00
comprehend_moderation Fixed some grammatical and Exception types issues (#12015) 2023-10-26 21:12:38 -04:00
cpal Add CI check that integration tests compile (#12090) 2023-10-21 10:52:18 -04:00
data_anonymizer Anonymizer small fixes (#11915) 2023-10-17 10:27:29 -07:00
fallacy_removal adding new chain for logical fallacy removal from model output in chain (#9887) 2023-09-03 15:44:27 -07:00
generative_agents Use a submodule for pydantic v1 compat (#9371) 2023-08-17 16:35:49 +01:00
graph_transformers Diffbot Graph Transformer / Neo4j Graph document ingestion (#9979) 2023-09-06 13:32:59 -07:00
llm_bash Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 2023-10-16 21:13:31 -04:00
llm_symbolic_math Add SymbolicMathChain to experiment in preparation for deprecation (#11129) 2023-10-05 13:54:43 -04:00
llms LM Format Enforcer Integration + Sample Notebook (#12625) 2023-10-31 09:49:01 -07:00
open_clip Add Chroma multimodal cookbook (#12952) 2023-11-10 09:43:10 -08:00
openai_assistant Move OAI assistants to langchain and add callbacks (#13236) 2023-11-13 17:42:07 -08:00
pal_chain Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 2023-10-16 21:13:31 -04:00
plan_and_execute Use a submodule for pydantic v1 compat (#9371) 2023-08-17 16:35:49 +01:00
prompt_injection_identifier HF Injection Identifier Refactor 2023-09-11 14:44:51 -07:00
prompts rename repo namespace to langchain-ai (#11259) 2023-10-01 15:30:58 -04:00
pydantic_v1 poetry lock the experimental package. (#9478) 2023-08-22 14:09:35 -04:00
retrievers add missing init files (#12114) 2023-10-21 10:25:50 -07:00
rl_chain Revise vowpal_wabbit notebook 2023-10-05 18:18:19 -07:00
smart_llm Upgrade experimental package dependencies and use Poetry 1.6.1. (#11339) 2023-10-16 21:13:31 -04:00
sql fix llm_inputs duplication problem in intermediate_steps in SQLDatabaseChain (#10279) 2023-10-05 21:32:08 -07:00
synthetic_data fix experimental imports (#10875) 2023-09-20 23:44:17 -07:00
tabular_synthetic_data Install and use ruff format instead of black for code formatting. (#12585) 2023-10-31 10:53:12 -04:00
tools Clean up deprecated agents and update __init__ in experimental (#12231) 2023-10-27 13:52:50 -04:00
tot Install and use ruff format instead of black for code formatting. (#12585) 2023-10-31 10:53:12 -04:00
utilities Clean up deprecated agents and update __init__ in experimental (#12231) 2023-10-27 13:52:50 -04:00
__init__.py Add version to langchain_experimental (#11613) 2023-10-10 11:17:41 -04:00
py.typed Add py.typed file to langchain-experimental. (#9557) 2023-08-21 15:37:16 -04:00