cevheri commited on
Commit
8f52d3f
Β·
1 Parent(s): 8a47c1f

docs: update readme

Browse files
Files changed (2) hide show
  1. .env.sample β†’ .env.example +3 -1
  2. README.md +32 -20
.env.sample β†’ .env.example RENAMED
@@ -3,7 +3,6 @@ LOG_LEVEL=DEBUG
3
  AUTH_USERNAME=admin
4
  AUTH_PASSWORD=admin
5
 
6
- API_KEY="sk-admin=="
7
  BASE_URL="http://0.0.0.0:7860"
8
 
9
  # types: mongodb, embedded
@@ -15,3 +14,6 @@ DB_MONGO_URI=mongodb://localhost:27017
15
  # SECURITY configurations
16
  SECURITY_SECRET_KEY="1234"
17
  SECURITY_ENABLED=false
 
 
 
 
3
  AUTH_USERNAME=admin
4
  AUTH_PASSWORD=admin
5
 
 
6
  BASE_URL="http://0.0.0.0:7860"
7
 
8
  # types: mongodb, embedded
 
14
  # SECURITY configurations
15
  SECURITY_SECRET_KEY="1234"
16
  SECURITY_ENABLED=false
17
+ DEFAULT_USERNAME=admin
18
+
19
+ API_KEY="sk-admin=="
README.md CHANGED
@@ -23,12 +23,20 @@ A FastAPI based OpenAI compatible Chatbot API with Visualization.
23
 
24
  ## πŸš€ Features
25
 
26
- - OpenAI compatible API /v1/chat/completions
 
 
 
 
 
 
 
27
  - Complete mock implementation with USE_MOCK_API environment variable
28
  - Secure API key generation with HMAC signatures and API key authentication
29
  - In-memory storage for chat history and plots for mock implementation
30
  - MongoDB storage for chat history and plots for production
31
  - Support for all major OpenAI API endpoints
 
32
 
33
 
34
  ## πŸ“‹ Endpoints
@@ -48,17 +56,23 @@ A FastAPI based OpenAI compatible Chatbot API with Visualization.
48
  git clone https://github.com/lokumai/openai-openapi-template.git
49
  ```
50
 
51
- 2. Install dependencies:
 
 
 
 
 
 
52
  ```bash
53
  uv sync
54
  ```
55
 
56
- 3. Start MongoDB:
57
  ```bash
58
  docker compose -f docker/mongodb-docker-compose.yaml up -d
59
  ```
60
 
61
- 4. Run on your local machine:
62
  ```bash
63
 
64
  ./run.sh
@@ -73,10 +87,11 @@ uv run uvicorn main:app --host 0.0.0.0 --port 7860 --reload
73
  ### πŸ”‘ API Key Generation
74
 
75
  ```bash
76
- ./scripts/api_key_generator.sh <username> <secret_key>
77
  ```
78
 
79
- ```text
 
80
  API Key generated:
81
  Username: template
82
  API Key: sk-template-token
@@ -84,16 +99,24 @@ API Key: sk-template-token
84
  API Key saved to api_key.txt
85
  ```
86
 
 
 
 
 
 
 
 
 
87
  ### πŸ”‘ API Key Authentication
88
 
89
  ```bash
90
- curl -X POST "http://localhost:8000/v1/chat/completions" \
91
  -H "Authorization: Bearer sk-template-token" \
92
  -H "Content-Type: application/json" \
93
  -d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}]}'
94
  ```
95
 
96
- ## Embedded MongoDB for local machine development
97
 
98
  * `database_type` environment variable is set to `embedded`, the API will use embedded MongoDB for local machine development. Default is `mongodb`.
99
  * `mongodb_host` environment variable is set to `localhost`, the API will use localhost for MongoDB. Default is `localhost`.
@@ -101,7 +124,7 @@ curl -X POST "http://localhost:8000/v1/chat/completions" \
101
  * `mongodb_database` environment variable is set to `openai_openapi_template`, the API will use openai_openapi_template for MongoDB. Default is `openai_openapi_template`.
102
 
103
 
104
- ## Contributing
105
  When you make changes to the code, please run the following commands to ensure the code is running on your local machine and formatted and linted correctly.
106
 
107
  * Fork the repository
@@ -141,7 +164,6 @@ git fetch origin main
141
  git merge origin/main
142
  ```
143
 
144
-
145
  * Validate the code is running on your local machine
146
  ```bash
147
  uv run uvicorn app:app --reload
@@ -166,16 +188,6 @@ git push origin feature/new-feature
166
  gh pr create --base main --head feature/new-feature --title "Add new feature" --body "This PR adds a new feature to the project"
167
  ```
168
 
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
  ## Open Issue
180
  Mock Implementation:
181
  - [X] Implement Mock response for all endpoints
 
23
 
24
  ## πŸš€ Features
25
 
26
+ - OpenAI compatible API
27
+ - /v1/chat/completions
28
+ - /v1/chat/completions/{completion_id}
29
+ - /v1/chat/completions/{completion_id}/messages
30
+ - /v1/chat/completions/{completion_id}/messages/{message_id}/plots
31
+ - /v1/conversation
32
+ - /v1/conversation/{completion_id}
33
+
34
  - Complete mock implementation with USE_MOCK_API environment variable
35
  - Secure API key generation with HMAC signatures and API key authentication
36
  - In-memory storage for chat history and plots for mock implementation
37
  - MongoDB storage for chat history and plots for production
38
  - Support for all major OpenAI API endpoints
39
+ - Gradio UI for testing the chatbot : [http://127.0.0.1:7860/ui](http://127.0.0.1:7860/ui)
40
 
41
 
42
  ## πŸ“‹ Endpoints
 
56
  git clone https://github.com/lokumai/openai-openapi-template.git
57
  ```
58
 
59
+ 2. Create a .env file in the root directory and add the following variables:
60
+ ```bash
61
+ cp .env.example .env
62
+ ```
63
+ * Set your own values for the variables in the .env file.
64
+
65
+ 3. Install dependencies:
66
  ```bash
67
  uv sync
68
  ```
69
 
70
+ 4. Start MongoDB:
71
  ```bash
72
  docker compose -f docker/mongodb-docker-compose.yaml up -d
73
  ```
74
 
75
+ 5. Run API and Gradio UI on your local machine:
76
  ```bash
77
 
78
  ./run.sh
 
87
  ### πŸ”‘ API Key Generation
88
 
89
  ```bash
90
+ ./scripts/generate_api_key.sh <username> <secret_key>
91
  ```
92
 
93
+ * This will generate a API_KEY and save it to the api_key.txt file.
94
+ ```plaintext
95
  API Key generated:
96
  Username: template
97
  API Key: sk-template-token
 
99
  API Key saved to api_key.txt
100
  ```
101
 
102
+ ## πŸ”’ Security Configuration
103
+ There are various security configurations that can be set in the .env file for development and production environments.
104
+
105
+ - `SECURITY_ENABLED=True` or `False`, If security is enabled, the API will require an API_KEY to be provided in the request header.
106
+ - `SECURITY_DEFAULT_USERNAME=admin`, If security is disabled, the API will not require an API_KEY to be provided in the request header and will use this for current user.
107
+ - `SECURITY_SECRET_KEY=your-secret-key-here`, This is the secret key for the API_KEY generation. It is used to generate and verify the API_KEY for the user.
108
+ - `API_KEY`, If you want to use the Gradio UI, you can set the API_KEY in the .env file. GradioUI will use the API_KEY to make requests to the API. Especially `POST/chat/completions` endpoint.
109
+
110
  ### πŸ”‘ API Key Authentication
111
 
112
  ```bash
113
+ curl -X POST "http://localhost:7860/v1/chat/completions" \
114
  -H "Authorization: Bearer sk-template-token" \
115
  -H "Content-Type: application/json" \
116
  -d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}]}'
117
  ```
118
 
119
+ ## πŸ’Ύ Embedded MongoDB for local machine development
120
 
121
  * `database_type` environment variable is set to `embedded`, the API will use embedded MongoDB for local machine development. Default is `mongodb`.
122
  * `mongodb_host` environment variable is set to `localhost`, the API will use localhost for MongoDB. Default is `localhost`.
 
124
  * `mongodb_database` environment variable is set to `openai_openapi_template`, the API will use openai_openapi_template for MongoDB. Default is `openai_openapi_template`.
125
 
126
 
127
+ ## 🀝 Contributing Attention Please!!!
128
  When you make changes to the code, please run the following commands to ensure the code is running on your local machine and formatted and linted correctly.
129
 
130
  * Fork the repository
 
164
  git merge origin/main
165
  ```
166
 
 
167
  * Validate the code is running on your local machine
168
  ```bash
169
  uv run uvicorn app:app --reload
 
188
  gh pr create --base main --head feature/new-feature --title "Add new feature" --body "This PR adds a new feature to the project"
189
  ```
190
 
 
 
 
 
 
 
 
 
 
 
191
  ## Open Issue
192
  Mock Implementation:
193
  - [X] Implement Mock response for all endpoints