Skip to content

Commit

Permalink
Add rest-api example (mem0ai#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmohanty11 authored Nov 3, 2023
1 parent a054f7b commit 8dd5cb9
Show file tree
Hide file tree
Showing 44 changed files with 1,217 additions and 118 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ docs/_build/
target/

# Jupyter Notebook
*.yaml

# IPython
profile_default/
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Book a [1-on-1 Session](https://cal.com/taranjeetio/ec) with Taranjeet, the foun
pip install --upgrade embedchain
```

To run Embedchain as a REST API server use,

```bash
docker run -d --name embedchain -p 8000:8000 embedchain/app:rest-api-latest
```

Navigate to http://0.0.0.0:8000/docs to interact with the API.

## 🔍 Demo

Try out embedchain in your browser:
Expand Down
2 changes: 1 addition & 1 deletion configs/anthropic.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
llm:
provider: anthropic
model: 'claude-instant-1'
config:
model: 'claude-instant-1'
temperature: 0.5
max_tokens: 1000
top_p: 1
Expand Down
2 changes: 1 addition & 1 deletion configs/azure_openai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ app:

llm:
provider: azure_openai
model: gpt-35-turbo
config:
model: gpt-35-turbo
deployment_name: your_llm_deployment_name
temperature: 0.5
max_tokens: 1000
Expand Down
2 changes: 1 addition & 1 deletion configs/chroma.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ app:

llm:
provider: openai
model: 'gpt-3.5-turbo'
config:
model: 'gpt-3.5-turbo'
temperature: 0.5
max_tokens: 1000
top_p: 1
Expand Down
2 changes: 1 addition & 1 deletion configs/cohere.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
llm:
provider: cohere
model: large
config:
model: large
temperature: 0.5
max_tokens: 1000
top_p: 1
2 changes: 1 addition & 1 deletion configs/full-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ app:

llm:
provider: openai
model: 'gpt-3.5-turbo'
config:
model: 'gpt-3.5-turbo'
temperature: 0.5
max_tokens: 1000
top_p: 1
Expand Down
2 changes: 1 addition & 1 deletion configs/huggingface.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
llm:
provider: huggingface
model: 'google/flan-t5-xxl'
config:
model: 'google/flan-t5-xxl'
temperature: 0.5
max_tokens: 1000
top_p: 0.5
Expand Down
2 changes: 1 addition & 1 deletion configs/llama2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
llm:
provider: llama2
model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
config:
model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
temperature: 0.5
max_tokens: 1000
top_p: 0.5
Expand Down
2 changes: 1 addition & 1 deletion configs/opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ app:

llm:
provider: openai
model: 'gpt-3.5-turbo'
config:
model: 'gpt-3.5-turbo'
temperature: 0.5
max_tokens: 1000
top_p: 1
Expand Down
2 changes: 1 addition & 1 deletion configs/vertexai.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
llm:
provider: vertexai
model: 'chat-bison'
config:
model: 'chat-bison'
temperature: 0.5
top_p: 0.5
3 changes: 3 additions & 0 deletions docs/api-reference/add-datasource-to-an-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /{app_id}/add
---
3 changes: 3 additions & 0 deletions docs/api-reference/chat-with-an-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /{app_id}/chat
---
3 changes: 3 additions & 0 deletions docs/api-reference/check-status.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /ping
---
3 changes: 3 additions & 0 deletions docs/api-reference/create-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /create
---
3 changes: 3 additions & 0 deletions docs/api-reference/delete-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /{app_id}/delete
---
3 changes: 3 additions & 0 deletions docs/api-reference/deploy-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /{app_id}/deploy
---
3 changes: 3 additions & 0 deletions docs/api-reference/get-all-apps.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /apps
---
3 changes: 3 additions & 0 deletions docs/api-reference/get-datasources-associated-with-app-id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /{app_id}/data
---
102 changes: 102 additions & 0 deletions docs/api-reference/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "🌍 Getting Started"
---

## Quick Start

To run Embedchain as a REST API server use,

```bash
docker run -d --name embedchain -p 8000:8000 embedchain/app:rest-api-latest
```

Open up your browser and navigate to http://0.0.0.0:8000/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 8000:8000 -e OPENAI_API_KEY=YOUR_API_KEY embedchain/app: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 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.
3 changes: 3 additions & 0 deletions docs/api-reference/query-an-app.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /{app_id}/query
---
93 changes: 0 additions & 93 deletions docs/examples/api_server.mdx

This file was deleted.

Loading

0 comments on commit 8dd5cb9

Please sign in to comment.