Langchain stripping out emojis when using Llama2 via llama_cpp
Labels: name: auto:bug, name: area: models

### System Info

Langchain Version: 0.0.263 (latest at time of writing)
llama-cpp-python Version: 0.1.77 (latest at time of writing)
Python Version: 3.11.4
Platform: Apple M1 Macbook 16GB
Llama2 Model: llama-2-7b-chat.ggmlv3.q4_1.bin via [https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML](https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML)

### Who can help?

@hwchase17 @ago

### Information

- [X] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [X] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I am trying to use the [Llama.cpp](https://python.langchain.com/docs/integrations/llms/llamacpp) integration to use the Llama2 model. I am battling with how the integration handles the output of emojis, which I assume is some kind of Unicode issue. However, I don't see the _exact_ same issue when using [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) directly (although there does seem to be some kind of issue with how llama-cpp handles emojis as well...).

Here are the two simple tests for comparison:

### Langchain Llama-Cpp Integration

```python
from langchain.llms import LlamaCpp
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

prompt = """

 

You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.



Tell me a story about a cat. Use as many different emojis as possible.

"""

llm = LlamaCpp(
    model_path="models/llama-2-7b-chat.ggmlv3.q4_1.bin",
    n_gpu_layers=1,
    n_batch=512,
    n_ctx=2048,
    f16_kv=True,
    callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]),
    verbose=True
)

llm(prompt=prompt)
```

Provides the output (truncated for the sake of brevity)

> Once upon a time, there was a curious  cat named Whiskers. She lived in a cozy  house with her loving ️ family. One day, while lounging in the sunny ️ garden, she spotted a  fascinating fly buzzing by.

This output has a complete lack of emojis, but I expect they were supposed output in the locations where there are double spaces, for example, after the words curious, cozy, loving etc (I have other examples below that are not just white space)

### Llama-cpp-python

```python
from llama_cpp import Llama

prompt = """

 

You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.



Tell me a story about a cat. Use as many different emojis as possible.

"""

llm = Llama(
    model_path="models/llama-2-7b-chat.ggmlv3.q4_1.bin",
    n_gpu_layers=1,
    n_ctx=2048,
    n_batch=512,
    f16_kv=True,
    verbose=True
)

llm(prompt=prompt)
```

Provides the output (again, truncated for brevity):

> 😺🐱💤 Once upon a time, there was a curious 🐱 named Fluffy 😻. She lived in a cozy 🏠 with her loving owner, Lily 🌹

### Other Output Examples

I have a significantly longer and more complex prompt in our application, that I've not included here, but creates some odd output with regards to emojis.

Here is using Langchain (exact same code as above, just a different prompt):

> Hey Paddy! Great job meeting your run pledge yesterday! Keep up the good work  Your consistency is on point ‍♂️

(There is a problem pasting the text directly, so here is a screenshot to see the odd unicode char being output):

![image](https://github.com/langchain-ai/langchain/assets/2673527/d7d0f73f-f9a2-44bf-b203-c5ab5be605b2)

Notice the <0x200d> and male symbol, as well as the double spacing, again, where I suspect there were supposed to be emojis output.

By comparison, here is the same prompt with the llama-cpp-python library code from above:

> 💪 Yo Paddy! 👍 You killed it today, bro! Met your run pledge 🏃\u200d♂️ 

The same unicode chars are output, so I suspect that issues is coming from the underlying model and or llama-cpp and may well be a red herring in this context.

However, all other emojis are somehow being discarded as part of the output.

As a final comparison, here is another simple prompt to try:

> How can I travel from London to Johannesburg. Use only emojis to explain the trip.

Langchains response is simply an empty string:

> '️'

Llama-cpp has the following response for the same prompt:

> 🇬🇧🛫🌏🚂💨🕰️



### Expected behavior

Expected behaviour here is for langchain to not strip out emojis as part of the response from the underlying model. We can see that when using llama-cpp directly we get a (mostly) well formed response but when using the langchain wrapper, we lose said emojis.