123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- ---
- title: '🌍 API Server'
- ---
- The API server example can be found [here](https://github.com/embedchain/embedchain/tree/main/examples/api_server).
- It is a Flask based server that integrates the `embedchain` package, offering endpoints to add, query, and chat to engage in conversations with a chatbot using JSON requests.
- ### 🐳 Docker Setup
- - Open variables.env, and edit it to add your 🔑 `OPENAI_API_KEY`.
- - To setup your api server using docker, run the following command inside this folder using your terminal.
- ```bash
- docker-compose up --build
- ```
- 📝 Note: The build command might take a while to install all the packages depending on your system resources.
- ### 🚀 Usage Instructions
- - Your api server is running on [http://localhost:5000/](http://localhost:5000/)
- - To use the api server, make an api call to the endpoints `/add`, `/query` and `/chat` using the json formats discussed below.
- - To add data sources to the bot (/add):
- ```json
- // Request
- {
- "data_type": "your_data_type_here",
- "url_or_text": "your_url_or_text_here"
- }
- // Response
- {
- "data": "Added data_type: url_or_text"
- }
- ```
- - To ask queries from the bot (/query):
- ```json
- // Request
- {
- "question": "your_question_here"
- }
- // Response
- {
- "data": "your_answer_here"
- }
- ```
- - To chat with the bot (/chat):
- ```json
- // Request
- {
- "question": "your_question_here"
- }
- // Response
- {
- "data": "your_answer_here"
- }
- ```
- ### 📡 Curl Call Formats
- - To add data sources to the bot (/add):
- ```bash
- curl -X POST \
- -H "Content-Type: application/json" \
- -d '{
- "data_type": "your_data_type_here",
- "url_or_text": "your_url_or_text_here"
- }' \
- http://localhost:5000/add
- ```
- - To ask queries from the bot (/query):
- ```bash
- curl -X POST \
- -H "Content-Type: application/json" \
- -d '{
- "question": "your_question_here"
- }' \
- http://localhost:5000/query
- ```
- - To chat with the bot (/chat):
- ```bash
- curl -X POST \
- -H "Content-Type: application/json" \
- -d '{
- "question": "your_question_here"
- }' \
- http://localhost:5000/chat
- ```
- 🎉 Happy Chatting! 🎉
|