Repository: xorbitsai/inference

Issue:
BUG: Langchain embed_documents() raises KeyError: 'model_format'
### Describe the bug
A clear and concise description of what the bug is.

### To Reproduce
To help us to reproduce this bug, please provide information below:
```
pdf-chatbot-local-llm-embeddings-app-1  | Traceback (most recent call last):
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
pdf-chatbot-local-llm-embeddings-app-1  |     exec(code, module.__dict__)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/app/app/main.py", line 74, in <module>
pdf-chatbot-local-llm-embeddings-app-1  |     main()
pdf-chatbot-local-llm-embeddings-app-1  |   File "/app/app/main.py", line 56, in main
pdf-chatbot-local-llm-embeddings-app-1  |     chatbot = init_chatbot(uploaded_file)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/app/app/main.py", line 38, in init_chatbot
pdf-chatbot-local-llm-embeddings-app-1  |     st.session_state["chatbot"] = ChatEngine(file_path)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/app/app/engine.py", line 111, in __init__
pdf-chatbot-local-llm-embeddings-app-1  |     vector_index = VectorStoreIndex(nodes, storage_context=storage_context, service_context=service_context)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py", line 46, in __init__
pdf-chatbot-local-llm-embeddings-app-1  |     super().__init__(
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/base.py", line 71, in __init__
pdf-chatbot-local-llm-embeddings-app-1  |     index_struct = self.build_index_from_nodes(nodes)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py", line 241, in build_index_from_nodes
pdf-chatbot-local-llm-embeddings-app-1  |     return self._build_index_from_nodes(nodes)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py", line 229, in _build_index_from_nodes
pdf-chatbot-local-llm-embeddings-app-1  |     self._add_nodes_to_index(
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py", line 201, in _add_nodes_to_index
pdf-chatbot-local-llm-embeddings-app-1  |     embedding_results = self._get_node_embedding_results(nodes, show_progress)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/indices/vector_store/base.py", line 111, in _get_node_embedding_results
pdf-chatbot-local-llm-embeddings-app-1  |     ) = self._service_context.embed_model.get_queued_text_embeddings(show_progress)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/embeddings/base.py", line 223, in get_queued_text_embeddings
pdf-chatbot-local-llm-embeddings-app-1  |     embeddings = self._get_text_embeddings(cur_batch_texts)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/llama_index/embeddings/langchain.py", line 68, in _get_text_embeddings
pdf-chatbot-local-llm-embeddings-app-1  |     return self._langchain_embedding.embed_documents(texts)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/langchain/embeddings/xinference.py", line 92, in embed_documents
pdf-chatbot-local-llm-embeddings-app-1  |     model = self.client.get_model(self.model_uid)
pdf-chatbot-local-llm-embeddings-app-1  |   File "/usr/local/lib/python3.9/site-packages/xinference/client.py", line 836, in get_model
pdf-chatbot-local-llm-embeddings-app-1  |     if desc["model_format"] == "ggmlv3" and "chatglm" in desc["model_name"]:
```

I create the LangchainEmbedding first
```python
from langchain.embeddings import XinferenceEmbeddings
from llama_index.embeddings import LangchainEmbedding

embedding = LangchainEmbedding(
   XinferenceEmbeddings(
      server_url=os.getenv("XINFERENCE_SERVER_ENDPOINT"),
      model_uid=os.getenv("XINFERENCE_EMBEDDING_MODEL_UID")
   )
)
```

Then I pass it to LLama index
```python
def get_service_context(callback_handlers):
    ...
    ServiceContext.from_defaults(
        embed_model=init_embedding_from_env(),
        callback_manager=callback_manager,
        llm=init_llm_from_env(),
        chunk_size=512,
        node_parser=node_parser
    )
```
### Expected behavior
A clear and concise description of what you expected to happen.

### Additional context
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/xinference/client.py b/xinference/client.py
--- a/xinference/client.py
+++ b/xinference/client.py
@@ -833,14 +833,19 @@ def get_model(self, model_uid: str) -> RESTfulModelHandle:
             )
         desc = response.json()
 
-        if desc["model_format"] == "ggmlv3" and "chatglm" in desc["model_name"]:
-            return RESTfulChatglmCppChatModelHandle(model_uid, self.base_url)
-        elif "chat" in desc["model_ability"]:
-            return RESTfulChatModelHandle(model_uid, self.base_url)
-        elif "generate" in desc["model_ability"]:
-            return RESTfulGenerateModelHandle(model_uid, self.base_url)
+        if desc["model_type"] == "LLM":
+            if desc["model_format"] == "ggmlv3" and "chatglm" in desc["model_name"]:
+                return RESTfulChatglmCppChatModelHandle(model_uid, self.base_url)
+            elif "chat" in desc["model_ability"]:
+                return RESTfulChatModelHandle(model_uid, self.base_url)
+            elif "generate" in desc["model_ability"]:
+                return RESTfulGenerateModelHandle(model_uid, self.base_url)
+            else:
+                raise ValueError(f"Unrecognized model ability: {desc['model_ability']}")
+        elif desc["model_type"] == "embedding":
+            return RESTfulEmbeddingModelHandle(model_uid, self.base_url)
         else:
-            raise ValueError(f"Unrecognized model ability: {desc['model_ability']}")
+            raise ValueError(f"Unknown model type:{desc['model_type']}")
 
     def describe_model(self, model_uid: str):
         """


Test patch:
diff --git a/xinference/tests/test_client.py b/xinference/tests/test_client.py
--- a/xinference/tests/test_client.py
+++ b/xinference/tests/test_client.py
@@ -20,6 +20,7 @@
     EmbeddingModelHandle,
     RESTfulChatModelHandle,
     RESTfulClient,
+    RESTfulEmbeddingModelHandle,
 )
 
 
@@ -234,6 +235,24 @@ def test_RESTful_client(setup):
     assert len(client.list_models()) == 0
 
 
+def test_RESTful_client_for_embedding(setup):
+    endpoint, _ = setup
+    client = RESTfulClient(endpoint)
+    assert len(client.list_models()) == 0
+
+    model_uid = client.launch_model(model_name="gte-base", model_type="embedding")
+    assert len(client.list_models()) == 1
+
+    model = client.get_model(model_uid=model_uid)
+    assert isinstance(model, RESTfulEmbeddingModelHandle)
+
+    completion = model.create_embedding("write a poem.")
+    assert len(completion["data"][0]["embedding"]) == 768
+
+    client.terminate_model(model_uid=model_uid)
+    assert len(client.list_models()) == 0
+
+
 def test_RESTful_client_custom_model(setup):
     endpoint, _ = setup
     client = RESTfulClient(endpoint)