api_server.mdx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ---
  2. title: '🌍 API Server'
  3. ---
  4. The API server example can be found [here](https://github.com/embedchain/embedchain/tree/main/examples/api_server).
  5. 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.
  6. ### 🐳 Docker Setup
  7. - Open variables.env, and edit it to add your 🔑 `OPENAI_API_KEY`.
  8. - To setup your api server using docker, run the following command inside this folder using your terminal.
  9. ```bash
  10. docker-compose up --build
  11. ```
  12. 📝 Note: The build command might take a while to install all the packages depending on your system resources.
  13. ### 🚀 Usage Instructions
  14. - Your api server is running on [http://localhost:5000/](http://localhost:5000/)
  15. - To use the api server, make an api call to the endpoints `/add`, `/query` and `/chat` using the json formats discussed below.
  16. - To add data sources to the bot (/add):
  17. ```json
  18. // Request
  19. {
  20. "data_type": "your_data_type_here",
  21. "url_or_text": "your_url_or_text_here"
  22. }
  23. // Response
  24. {
  25. "data": "Added data_type: url_or_text"
  26. }
  27. ```
  28. - To ask queries from the bot (/query):
  29. ```json
  30. // Request
  31. {
  32. "question": "your_question_here"
  33. }
  34. // Response
  35. {
  36. "data": "your_answer_here"
  37. }
  38. ```
  39. - To chat with the bot (/chat):
  40. ```json
  41. // Request
  42. {
  43. "question": "your_question_here"
  44. }
  45. // Response
  46. {
  47. "data": "your_answer_here"
  48. }
  49. ```
  50. ### 📡 Curl Call Formats
  51. - To add data sources to the bot (/add):
  52. ```bash
  53. curl -X POST \
  54. -H "Content-Type: application/json" \
  55. -d '{
  56. "data_type": "your_data_type_here",
  57. "url_or_text": "your_url_or_text_here"
  58. }' \
  59. http://localhost:5000/add
  60. ```
  61. - To ask queries from the bot (/query):
  62. ```bash
  63. curl -X POST \
  64. -H "Content-Type: application/json" \
  65. -d '{
  66. "question": "your_question_here"
  67. }' \
  68. http://localhost:5000/query
  69. ```
  70. - To chat with the bot (/chat):
  71. ```bash
  72. curl -X POST \
  73. -H "Content-Type: application/json" \
  74. -d '{
  75. "question": "your_question_here"
  76. }' \
  77. http://localhost:5000/chat
  78. ```
  79. 🎉 Happy Chatting! 🎉