Support for openai finetuned models 
Labels: name: area: memory, name: area: agent, name: auto:bug, name: stale, name: area: models

### System Info

langchain==0.0.198
MacOS 13.5.2 Ventura
Python 3.11


### Who can help?

@agola11
@hwchase17



### Information

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

### Related Components

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

### Reproduction

Steps to reproduce the behavior:

1. Finetune a model using OpenAI's API
2. Retrieve your model tag in the form: `ft:gpt-3.5-turbo-0613:{your_org}::{snapshot_id}`
3. Instantiate a ChatOpenAI object with the finetuned model:
```
from langchain.chat_models import ChatOpenAI
openai = ChatOpenAI(model_name="gpt-3.5-turbo](ft:gpt-3.5-turbo-0613:{your_org}::{snapshot_id}")
```
4. Load an AgentExecuter from Agent, llm, and tools
5. Execute a query, eg:
```
response = executor.run(input="hello, where is my hat?")
```

The query will execute against the LLM at first, then produce an output like this:
```
WARNING:langchain.chat_models.openai:Warning: model not found. Using cl100k_base encoding.
Traceback (most recent call last):
  File "/Users/wlane/projects/api-navgpt/demo/mapgpt-agent-demo/cli.py", line 59, in <module>
    executor.run(input=query)
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/chains/base.py", line 261, in run
    return self(kwargs, callbacks=callbacks)[self.output_keys[0]]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/chains/base.py", line 149, in __call__
    final_outputs: Dict[str, Any] = self.prep_outputs(
                                    ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/chains/base.py", line 213, in prep_outputs
    self.memory.save_context(inputs, outputs)
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/memory/summary_buffer.py", line 60, in save_context
    self.prune()
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/memory/summary_buffer.py", line 65, in prune
    curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/langchain/chat_models/openai.py", line 458, in get_num_tokens_from_messages
    raise NotImplementedError(
NotImplementedError: get_num_tokens_from_messages() is not presently implemented for model gpt-3.5-turbo.See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.
```



### Expected behavior

It is expected that the Agent handles the utterance without throwing an error about being unable to map to the right tokenizer.

The issue is in `openai.py`, which aknowledges that gpt-3.5-turbo may change over time, and maps the model str to a specific snapshot: "gpt-3.5-turbo-0301". However, the logic does not consider that `model` may be some arbitrary handle containing `...gpt-3.5-turbo-...`, as is the case when you fine tune a model on OpenAI:

```
def _get_encoding_model(self) -> Tuple[str, tiktoken.Encoding]:
        tiktoken_ = _import_tiktoken()
        model = self.model_name
        if model == "gpt-3.5-turbo":
            # gpt-3.5-turbo may change over time.
            # Returning num tokens assuming gpt-3.5-turbo-0301.
            model = "gpt-3.5-turbo-0301"
```

When I alter the funtion like this, it works:
```
def _get_encoding_model(self) -> Tuple[str, tiktoken.Encoding]:
        tiktoken_ = _import_tiktoken()
        model = self.model_name
        if "gpt-3.5-turbo" in model:    <----------------------------
            # gpt-3.5-turbo may change over time.
            # Returning num tokens assuming gpt-3.5-turbo-0301.
            model = "gpt-3.5-turbo-0301"
```