JinaChat Authentication
Labels: name: auto:bug

### System Info

langchain-0.0.229
python 3.10


### Who can help?

@delgermurun

### Information

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

### Related Components

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

### Reproduction

```python

import os
from langchain.chat_models import JinaChat
from langchain.schema import HumanMessage

os.environ["JINACHAT_API_KEY"] = "..."  # from https://cloud.jina.ai/settings/tokens
chat = JinaChat(temperature=0)

messages = [
    HumanMessage(
        content="Translate this sentence from English to French: I love you!"
    )
]
print(chat(messages))
```

### Expected behavior

Expected output: Je t'aime
Actual output: 
```python
---------------------------------------------------------------------------

AuthenticationError                       Traceback (most recent call last)

Cell In[7], line 10
      3 chat = JinaChat(temperature=0)
      5 messages = [
      6     HumanMessage(
      7         content="Translate this sentence from English to French: I love generative AI!"
      8     )
      9 ]
---> 10 chat(messages)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/base.py:349, in BaseChatModel.__call__(self, messages, stop, callbacks, **kwargs)
    342 def __call__(
    343     self,
    344     messages: List[BaseMessage],
   (...)
    347     **kwargs: Any,
    348 ) -> BaseMessage:
--> 349     generation = self.generate(
    350         [messages], stop=stop, callbacks=callbacks, **kwargs
    351     ).generations[0][0]
    352     if isinstance(generation, ChatGeneration):
    353         return generation.message

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/base.py:125, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, **kwargs)
    123         if run_managers:
    124             run_managers[i].on_llm_error(e)
--> 125         raise e
    126 flattened_outputs = [
    127     LLMResult(generations=[res.generations], llm_output=res.llm_output)
    128     for res in results
    129 ]
    130 llm_output = self._combine_llm_outputs([res.llm_output for res in results])

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/base.py:115, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, **kwargs)
    112 for i, m in enumerate(messages):
    113     try:
    114         results.append(
--> 115             self._generate_with_cache(
    116                 m,
    117                 stop=stop,
    118                 run_manager=run_managers[i] if run_managers else None,
    119                 **kwargs,
    120             )
    121         )
    122     except (KeyboardInterrupt, Exception) as e:
    123         if run_managers:

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/base.py:262, in BaseChatModel._generate_with_cache(self, messages, stop, run_manager, **kwargs)
    258     raise ValueError(
    259         "Asked to cache, but no cache found at `langchain.cache`."
    260     )
    261 if new_arg_supported:
--> 262     return self._generate(
    263         messages, stop=stop, run_manager=run_manager, **kwargs
    264     )
    265 else:
    266     return self._generate(messages, stop=stop, **kwargs)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/jinachat.py:288, in JinaChat._generate(self, messages, stop, run_manager, **kwargs)
    281     message = _convert_dict_to_message(
    282         {
    283             "content": inner_completion,
    284             "role": role,
    285         }
    286     )
    287     return ChatResult(generations=[ChatGeneration(message=message)])
--> 288 response = self.completion_with_retry(messages=message_dicts, **params)
    289 return self._create_chat_result(response)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/jinachat.py:244, in JinaChat.completion_with_retry(self, **kwargs)
    240 @retry_decorator
    241 def _completion_with_retry(**kwargs: Any) -> Any:
    242     return self.client.create(**kwargs)
--> 244 return _completion_with_retry(**kwargs)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/tenacity/__init__.py:289, in BaseRetrying.wraps.<locals>.wrapped_f(*args, **kw)
    287 @functools.wraps(f)
    288 def wrapped_f(*args: t.Any, **kw: t.Any) -> t.Any:
--> 289     return self(f, *args, **kw)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/tenacity/__init__.py:379, in Retrying.__call__(self, fn, *args, **kwargs)
    377 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs)
    378 while True:
--> 379     do = self.iter(retry_state=retry_state)
    380     if isinstance(do, DoAttempt):
    381         try:

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/tenacity/__init__.py:314, in BaseRetrying.iter(self, retry_state)
    312 is_explicit_retry = fut.failed and isinstance(fut.exception(), TryAgain)
    313 if not (is_explicit_retry or self.retry(retry_state)):
--> 314     return fut.result()
    316 if self.after is not None:
    317     self.after(retry_state)

File /opt/anaconda3/envs/langchain/lib/python3.10/concurrent/futures/_base.py:451, in Future.result(self, timeout)
    449     raise CancelledError()
    450 elif self._state == FINISHED:
--> 451     return self.__get_result()
    453 self._condition.wait(timeout)
    455 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File /opt/anaconda3/envs/langchain/lib/python3.10/concurrent/futures/_base.py:403, in Future.__get_result(self)
    401 if self._exception:
    402     try:
--> 403         raise self._exception
    404     finally:
    405         # Break a reference cycle with the exception in self._exception
    406         self = None

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/tenacity/__init__.py:382, in Retrying.__call__(self, fn, *args, **kwargs)
    380 if isinstance(do, DoAttempt):
    381     try:
--> 382         result = fn(*args, **kwargs)
    383     except BaseException:  # noqa: B902
    384         retry_state.set_exception(sys.exc_info())  # type: ignore[arg-type]

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/langchain/chat_models/jinachat.py:242, in JinaChat.completion_with_retry.<locals>._completion_with_retry(**kwargs)
    240 @retry_decorator
    241 def _completion_with_retry(**kwargs: Any) -> Any:
--> 242     return self.client.create(**kwargs)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/openai/api_resources/chat_completion.py:25, in ChatCompletion.create(cls, *args, **kwargs)
     23 while True:
     24     try:
---> 25         return super().create(*args, **kwargs)
     26     except TryAgain as e:
     27         if timeout is not None and time.time() > start + timeout:

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py:153, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)
    127 @classmethod
    128 def create(
    129     cls,
   (...)
    136     **params,
    137 ):
    138     (
    139         deployment_id,
    140         engine,
   (...)
    150         api_key, api_base, api_type, api_version, organization, **params
    151     )
--> 153     response, _, api_key = requestor.request(
    154         "post",
    155         url,
    156         params=params,
    157         headers=headers,
    158         stream=stream,
    159         request_id=request_id,
    160         request_timeout=request_timeout,
    161     )
    163     if stream:
    164         # must be an iterator
    165         assert not isinstance(response, OpenAIResponse)

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/openai/api_requestor.py:298, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout)
    277 def request(
    278     self,
    279     method,
   (...)
    286     request_timeout: Optional[Union[float, Tuple[float, float]]] = None,
    287 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]:
    288     result = self.request_raw(
    289         method.lower(),
    290         url,
   (...)
    296         request_timeout=request_timeout,
    297     )
--> 298     resp, got_stream = self._interpret_response(result, stream)
    299     return resp, got_stream, self.api_key

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/openai/api_requestor.py:700, in APIRequestor._interpret_response(self, result, stream)
    692     return (
    693         self._interpret_response_line(
    694             line, result.status_code, result.headers, stream=True
    695         )
    696         for line in parse_stream(result.iter_lines())
    697     ), True
    698 else:
    699     return (
--> 700         self._interpret_response_line(
    701             result.content.decode("utf-8"),
    702             result.status_code,
    703             result.headers,
    704             stream=False,
    705         ),
    706         False,
    707     )

File /opt/anaconda3/envs/langchain/lib/python3.10/site-packages/openai/api_requestor.py:763, in APIRequestor._interpret_response_line(self, rbody, rcode, rheaders, stream)
    761 stream_error = stream and "error" in resp.data
    762 if stream_error or not 200 <= rcode < 300:
--> 763     raise self.handle_error_response(
    764         rbody, rcode, resp.data, rheaders, stream_error=stream_error
    765     )
    766 return resp

AuthenticationError: Invalid token

```