From e2546a653dc8f4240bb01b4e43607738f212a04d Mon Sep 17 00:00:00 2001 From: Sidharth Mohanty Date: Fri, 3 Nov 2023 22:10:48 +0530 Subject: [PATCH] [chore] fix rest api docs and other minor fixes (#902) --- docs/api-reference/chat-with-an-app.mdx | 3 - docs/api-reference/check-status.mdx | 3 - docs/api-reference/create-app.mdx | 3 - docs/api-reference/delete-app.mdx | 3 - docs/api-reference/get-all-apps.mdx | 3 - ...get-datasources-associated-with-app-id.mdx | 3 - docs/api-reference/getting-started.mdx | 102 ------------------ docs/api-reference/query-an-app.mdx | 3 - docs/mint.json | 22 ++-- examples/rest-api/main.py | 47 ++++---- examples/rest-api/requirements.txt | 7 +- examples/rest-api/utils.py | 2 +- 12 files changed, 42 insertions(+), 159 deletions(-) delete mode 100644 docs/api-reference/chat-with-an-app.mdx delete mode 100644 docs/api-reference/check-status.mdx delete mode 100644 docs/api-reference/create-app.mdx delete mode 100644 docs/api-reference/delete-app.mdx delete mode 100644 docs/api-reference/get-all-apps.mdx delete mode 100644 docs/api-reference/get-datasources-associated-with-app-id.mdx delete mode 100644 docs/api-reference/getting-started.mdx delete mode 100644 docs/api-reference/query-an-app.mdx diff --git a/docs/api-reference/chat-with-an-app.mdx b/docs/api-reference/chat-with-an-app.mdx deleted file mode 100644 index 2571bf71..00000000 --- a/docs/api-reference/chat-with-an-app.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: post /{app_id}/chat ---- \ No newline at end of file diff --git a/docs/api-reference/check-status.mdx b/docs/api-reference/check-status.mdx deleted file mode 100644 index bbad0317..00000000 --- a/docs/api-reference/check-status.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: get /ping ---- \ No newline at end of file diff --git a/docs/api-reference/create-app.mdx b/docs/api-reference/create-app.mdx deleted file mode 100644 index e18320a6..00000000 --- a/docs/api-reference/create-app.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: post /create ---- \ No newline at end of file diff --git a/docs/api-reference/delete-app.mdx b/docs/api-reference/delete-app.mdx deleted file mode 100644 index c81d2555..00000000 --- a/docs/api-reference/delete-app.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: delete /{app_id}/delete ---- \ No newline at end of file diff --git a/docs/api-reference/get-all-apps.mdx b/docs/api-reference/get-all-apps.mdx deleted file mode 100644 index 19881d05..00000000 --- a/docs/api-reference/get-all-apps.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: get /apps ---- \ No newline at end of file diff --git a/docs/api-reference/get-datasources-associated-with-app-id.mdx b/docs/api-reference/get-datasources-associated-with-app-id.mdx deleted file mode 100644 index c5eb6789..00000000 --- a/docs/api-reference/get-datasources-associated-with-app-id.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: get /{app_id}/data ---- \ No newline at end of file diff --git a/docs/api-reference/getting-started.mdx b/docs/api-reference/getting-started.mdx deleted file mode 100644 index 0c173bef..00000000 --- a/docs/api-reference/getting-started.mdx +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "🌍 Getting Started" ---- - -## Quickstart - -To run Embedchain as a REST API server use, - -```bash -docker run -d --name embedchain -p 8080:8080 embedchain/rest-api:latest -``` - -Open up your browser and navigate to http://0.0.0.0:8080/docs to interact with the API. There is a full-fledged Swagger docs playground with all the information -about the API endpoints. - -![Swagger Docs Screenshot](https://github.com/embedchain/embedchain/assets/73601258/299d81e5-a0df-407c-afc2-6fa2c4286844) - -## Creating your first App - -App requires an `app_id` to be created. The `app_id` is a unique identifier for your app. - -By default we will use the opensource **gpt4all** model to perform operations. You can also specify your own config by uploading a config YAML file. - -For example, create a `config.yaml` file (adjust according to your requirements): - -```yaml -app: - config: - id: "default-app" - -llm: - provider: openai - config: - model: "gpt-3.5-turbo" - temperature: 0.5 - max_tokens: 1000 - top_p: 1 - stream: false - template: | - Use the following pieces of context to answer the query at the end. - If you don't know the answer, just say that you don't know, don't try to make up an answer. - - $context - - Query: $query - - Helpful Answer: - -vectordb: - provider: chroma - config: - collection_name: "rest-api-app" - dir: db - allow_reset: true - -embedder: - provider: openai - config: - model: "text-embedding-ada-002" -``` - -To learn more about custom configurations, check out the [Custom configurations](https://docs.embedchain.ai/advanced/configuration). -To explore more examples of config YAMLs for Embedchain, visit [embedchain/configs](https://github.com/embedchain/embedchain/tree/main/configs). - -Now, you can upload this config file in the request body. - -**Note:** To use custom models, an **API key** might be required. Refer to the table below to determine the necessary API key for your provider. - -| Keys | Providers | -| -------------------------- | ------------------------------ | -| `OPENAI_API_KEY ` | OpenAI, Azure OpenAI, Jina etc | -| `OPENAI_API_TYPE` | Azure OpenAI | -| `OPENAI_API_BASE` | Azure OpenAI | -| `OPENAI_API_VERSION` | Azure OpenAI | -| `COHERE_API_KEY` | Cohere | -| `ANTHROPIC_API_KEY` | Anthropic | -| `JINACHAT_API_KEY` | Jina | -| `HUGGINGFACE_ACCESS_TOKEN` | Huggingface | -| `REPLICATE_API_TOKEN` | LLAMA2 | - -To provide them, you can simply run the docker command with the `-e` flag. - -For example, - -```bash -docker run -d --name embedchain -p 8080:8080 -e OPENAI_API_KEY=YOUR_API_KEY embedchain/rest-api:latest -``` - -Cool! This will create a new Embedchain App with the given `app_id`. - -## Deploying your App to Embedchain Platform - -This feature is very powerful as it allows the creation of a public API endpoint for your app, enabling queries from anywhere. This creates a _pipeline_ -for your app that can sync the data time to time and provide you with the best results. - -![My first Pipeline](https://github.com/embedchain/embedchain/assets/73601258/266a66e0-330e-4bb9-aa97-687d826cd3fa) - -To utilize this functionality, visit [app.embedchain.ai](app.embedchain.ai) and create an account. Subsequently, generate a new [API KEY](https://app.embedchain.ai/settings/keys/). - -![Create Embedchain API Key](https://github.com/embedchain/embedchain/assets/73601258/791e92cc-4a6f-4740-94c2-f11cce13e93b) - -Using this API key, you can deploy your app to the platform. diff --git a/docs/api-reference/query-an-app.mdx b/docs/api-reference/query-an-app.mdx deleted file mode 100644 index c72e3851..00000000 --- a/docs/api-reference/query-an-app.mdx +++ /dev/null @@ -1,3 +0,0 @@ ---- -openapi: post /{app_id}/query ---- \ No newline at end of file diff --git a/docs/mint.json b/docs/mint.json index 3ccd4bd0..e6458856 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -93,17 +93,17 @@ }, { "group": "REST API", - "pages": [ - "api-reference/getting-started", - "api-reference/check-status", - "api-reference/get-all-apps", - "api-reference/create-app", - "api-reference/query-an-app", - "api-reference/add-datasource-to-an-app", - "api-reference/get-datasources-associated-with-app-id", - "api-reference/deploy-app", - "api-reference/delete-app" - ] + "pages": [ + "rest-api/getting-started", + "rest-api/create", + "rest-api/get-all-apps", + "rest-api/add-data", + "rest-api/get-data", + "rest-api/query", + "rest-api/deploy", + "rest-api/delete", + "rest-api/check-status" + ] }, { "group": "Examples", diff --git a/examples/rest-api/main.py b/examples/rest-api/main.py index a1f0d842..70bb87fb 100644 --- a/examples/rest-api/main.py +++ b/examples/rest-api/main.py @@ -1,4 +1,5 @@ import os +import logging import yaml from fastapi import FastAPI, UploadFile, Depends, HTTPException from sqlalchemy.orm import Session @@ -85,6 +86,7 @@ async def create_app_using_default_config(app_id: str, config: UploadFile = None return DefaultResponse(response=f"App created successfully. App ID: {app_id}") except Exception as e: + logging.warn(str(e)) raise HTTPException(detail=f"Error creating app: {str(e)}", status_code=400) @@ -114,12 +116,13 @@ async def get_datasources_associated_with_app_id(app_id: str, db: Session = Depe response = app.get_data_sources() return {"results": response} except ValueError as ve: - if "OPENAI_API_KEY" in str(ve) or "OPENAI_ORGANIZATION" in str(ve): - raise HTTPException( - detail=generate_error_message_for_api_keys(ve), - status_code=400, - ) + logging.warn(str(ve)) + raise HTTPException( + detail=generate_error_message_for_api_keys(ve), + status_code=400, + ) except Exception as e: + logging.warn(str(e)) raise HTTPException(detail=f"Error occurred: {str(e)}", status_code=400) @@ -152,12 +155,13 @@ async def add_datasource_to_an_app(body: SourceApp, app_id: str, db: Session = D response = app.add(source=body.source, data_type=body.data_type) return DefaultResponse(response=response) except ValueError as ve: - if "OPENAI_API_KEY" in str(ve) or "OPENAI_ORGANIZATION" in str(ve): - raise HTTPException( - detail=generate_error_message_for_api_keys(ve), - status_code=400, - ) + logging.warn(str(ve)) + raise HTTPException( + detail=generate_error_message_for_api_keys(ve), + status_code=400, + ) except Exception as e: + logging.warn(str(e)) raise HTTPException(detail=f"Error occurred: {str(e)}", status_code=400) @@ -189,12 +193,13 @@ async def query_an_app(body: QueryApp, app_id: str, db: Session = Depends(get_db response = app.query(body.query) return DefaultResponse(response=response) except ValueError as ve: - if "OPENAI_API_KEY" in str(ve) or "OPENAI_ORGANIZATION" in str(ve): - raise HTTPException( - detail=generate_error_message_for_api_keys(ve), - status_code=400, - ) + logging.warn(str(ve)) + raise HTTPException( + detail=generate_error_message_for_api_keys(ve), + status_code=400, + ) except Exception as e: + logging.warn(str(e)) raise HTTPException(detail=f"Error occurred: {str(e)}", status_code=400) @@ -230,7 +235,6 @@ async def query_an_app(body: QueryApp, app_id: str, db: Session = Depends(get_db # response = app.chat(body.message) # return DefaultResponse(response=response) # except ValueError as ve: -# if "OPENAI_API_KEY" in str(ve) or "OPENAI_ORGANIZATION" in str(ve): # raise HTTPException( # detail=generate_error_message_for_api_keys(ve), # status_code=400, @@ -272,12 +276,13 @@ async def deploy_app(body: DeployAppRequest, app_id: str, db: Session = Depends( app.deploy() return DefaultResponse(response="App deployed successfully.") except ValueError as ve: - if "OPENAI_API_KEY" in str(ve) or "OPENAI_ORGANIZATION" in str(ve): - raise HTTPException( - detail=generate_error_message_for_api_keys(ve), - status_code=400, - ) + logging.warn(str(ve)) + raise HTTPException( + detail=generate_error_message_for_api_keys(ve), + status_code=400, + ) except Exception as e: + logging.warn(str(e)) raise HTTPException(detail=f"Error occurred: {str(e)}", status_code=400) diff --git a/examples/rest-api/requirements.txt b/examples/rest-api/requirements.txt index 9d2aa3fd..6150034c 100644 --- a/examples/rest-api/requirements.txt +++ b/examples/rest-api/requirements.txt @@ -1,5 +1,6 @@ fastapi==0.104.0 uvicorn==0.23.2 -embedchain==0.0.86 -embedchain[dataloaders]==0.0.86 -sqlalchemy==2.0.22 \ No newline at end of file +embedchain==0.0.90 +embedchain[streamlit, community, opensource, elasticsearch, opensearch, poe, discord, slack, whatsapp, weaviate, pinecone, qdrant, images, huggingface_hub, cohere, milvus, dataloaders, vertexai, llama2, gmail, json]==0.0.90 +sqlalchemy==2.0.22 +python-multipart==0.0.6 diff --git a/examples/rest-api/utils.py b/examples/rest-api/utils.py index 351355f2..c3ac235e 100644 --- a/examples/rest-api/utils.py +++ b/examples/rest-api/utils.py @@ -18,4 +18,4 @@ def generate_error_message_for_api_keys(error: ValueError) -> str: Example: `docker run -e {missing_keys[0]}=xxx embedchain/rest-api:latest` """ else: - return "Unknown error occurred." + return "Error: " + str(error)