api_server.mdx 2.0 KB

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