Spaces:
Running
Running
Kang Suhyun
suhyun.kang
commited on
Commit
•
b695eaf
1
Parent(s):
d66dbee
[#30] Fetch the model list from the Secret Manager (#33)
Browse filesThe model list is now fetched from the Secret Manager.
It will allow us to add new models without changing the code.
Current list of models:
```json
{
"gpt-4": {},
"gpt-4-0125-preview": {},
"gpt-3.5-turbo": {},
"gemini-pro": {},
"yanolja/EEVE-Korean-Instruct-10.8B-v1.0": {
"provider": "openai",
"apiKey": "...",
"apiBase": "..."
}
}
```
Co-authored-by: suhyun.kang <suhyun.kang@yanolja.group>
- README.md +6 -2
- requirements.txt +5 -4
- response.py +24 -6
README.md
CHANGED
@@ -29,10 +29,14 @@ pinned: false
|
|
29 |
Set your OpenAI API key as an environment variable and start the application:
|
30 |
|
31 |
```shell
|
32 |
-
GOOGLE_CLOUD_PROJECT=<your project id>
|
|
|
|
|
|
|
|
|
33 |
```
|
34 |
|
35 |
-
Replace `<your project id>`, `<your crednetials path>`, and `<your key>` with your GCP project ID, the path to your GCP credentials file, and your OpenAI API key respectively.
|
36 |
|
37 |
> To run the app with [auto-reloading](https://www.gradio.app/guides/developing-faster-with-reload-mode), use `gradio app.py --demo-name app` instead of `python3 app.py`.
|
38 |
|
|
|
29 |
Set your OpenAI API key as an environment variable and start the application:
|
30 |
|
31 |
```shell
|
32 |
+
GOOGLE_CLOUD_PROJECT=<your project id> \
|
33 |
+
CREDENTIALS_PATH=<your crednetials path> \
|
34 |
+
MODELS_SECRET=<your secret> \
|
35 |
+
OPENAI_API_KEY=<your key> \
|
36 |
+
python3 app.py
|
37 |
```
|
38 |
|
39 |
+
Replace `<your project id>`, `<your crednetials path>`, `<your secret>`, and `<your key>` with your GCP project ID, the path to your GCP credentials file, the secret name for your models, and your OpenAI API key respectively.
|
40 |
|
41 |
> To run the app with [auto-reloading](https://www.gradio.app/guides/developing-faster-with-reload-mode), use `gradio app.py --demo-name app` instead of `python3 app.py`.
|
42 |
|
requirements.txt
CHANGED
@@ -27,11 +27,12 @@ google-api-core==2.16.2
|
|
27 |
google-api-python-client==2.116.0
|
28 |
google-auth==2.27.0
|
29 |
google-auth-httplib2==0.2.0
|
30 |
-
google-cloud-aiplatform==1.
|
31 |
-
google-cloud-bigquery==3.
|
32 |
google-cloud-core==2.4.1
|
33 |
google-cloud-firestore==2.14.0
|
34 |
-
google-cloud-resource-manager==1.12.
|
|
|
35 |
google-cloud-storage==2.14.0
|
36 |
google-crc32c==1.5.0
|
37 |
google-resumable-media==2.7.0
|
@@ -90,7 +91,7 @@ rpds-py==0.17.1
|
|
90 |
rsa==4.9
|
91 |
ruff==0.2.0
|
92 |
semantic-version==2.10.0
|
93 |
-
shapely==2.0.
|
94 |
shellingham==1.5.4
|
95 |
six==1.16.0
|
96 |
sniffio==1.3.0
|
|
|
27 |
google-api-python-client==2.116.0
|
28 |
google-auth==2.27.0
|
29 |
google-auth-httplib2==0.2.0
|
30 |
+
google-cloud-aiplatform==1.43.0
|
31 |
+
google-cloud-bigquery==3.19.0
|
32 |
google-cloud-core==2.4.1
|
33 |
google-cloud-firestore==2.14.0
|
34 |
+
google-cloud-resource-manager==1.12.3
|
35 |
+
google-cloud-secret-manager==2.18.3
|
36 |
google-cloud-storage==2.14.0
|
37 |
google-crc32c==1.5.0
|
38 |
google-resumable-media==2.7.0
|
|
|
91 |
rsa==4.9
|
92 |
ruff==0.2.0
|
93 |
semantic-version==2.10.0
|
94 |
+
shapely==2.0.3
|
95 |
shellingham==1.5.4
|
96 |
six==1.16.0
|
97 |
sniffio==1.3.0
|
response.py
CHANGED
@@ -3,15 +3,24 @@ This module contains functions for generating responses using LLMs.
|
|
3 |
"""
|
4 |
|
5 |
import enum
|
|
|
|
|
6 |
from random import sample
|
7 |
|
|
|
8 |
import gradio as gr
|
9 |
from litellm import completion
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
class Category(enum.Enum):
|
@@ -35,16 +44,25 @@ def get_responses(user_prompt, category, source_lang, target_lang):
|
|
35 |
not target_lang):
|
36 |
raise gr.Error("Please select source and target languages.")
|
37 |
|
38 |
-
models = sample(
|
39 |
instruction = get_instruction(category, source_lang, target_lang)
|
40 |
activated_vote_buttons = [gr.Button(interactive=True) for _ in range(3)]
|
41 |
deactivated_vote_buttons = [gr.Button(interactive=False) for _ in range(3)]
|
42 |
|
43 |
responses = []
|
44 |
for model in models:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
try:
|
46 |
# TODO(#1): Allow user to set configuration.
|
47 |
-
response = completion(model=
|
|
|
|
|
48 |
messages=[{
|
49 |
"content": instruction,
|
50 |
"role": "system"
|
|
|
3 |
"""
|
4 |
|
5 |
import enum
|
6 |
+
import json
|
7 |
+
import os
|
8 |
from random import sample
|
9 |
|
10 |
+
from google.cloud import secretmanager
|
11 |
import gradio as gr
|
12 |
from litellm import completion
|
13 |
|
14 |
+
GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT")
|
15 |
+
MODELS_SECRET = os.environ.get("MODELS_SECRET")
|
16 |
+
|
17 |
+
secretmanagerClient = secretmanager.SecretManagerServiceClient()
|
18 |
+
models_secret = secretmanagerClient.access_secret_version(
|
19 |
+
name=secretmanagerClient.secret_version_path(GOOGLE_CLOUD_PROJECT,
|
20 |
+
MODELS_SECRET, "latest"))
|
21 |
+
decoded_secret = models_secret.payload.data.decode("UTF-8")
|
22 |
+
|
23 |
+
supported_models = json.loads(decoded_secret)
|
24 |
|
25 |
|
26 |
class Category(enum.Enum):
|
|
|
44 |
not target_lang):
|
45 |
raise gr.Error("Please select source and target languages.")
|
46 |
|
47 |
+
models = sample(list(supported_models), 2)
|
48 |
instruction = get_instruction(category, source_lang, target_lang)
|
49 |
activated_vote_buttons = [gr.Button(interactive=True) for _ in range(3)]
|
50 |
deactivated_vote_buttons = [gr.Button(interactive=False) for _ in range(3)]
|
51 |
|
52 |
responses = []
|
53 |
for model in models:
|
54 |
+
model_config = supported_models[model]
|
55 |
+
|
56 |
+
model_name = model_config[
|
57 |
+
"provider"] + "/" + model if "provider" in model_config else model
|
58 |
+
api_key = model_config.get("apiKey", None)
|
59 |
+
api_base = model_config.get("apiBase", None)
|
60 |
+
|
61 |
try:
|
62 |
# TODO(#1): Allow user to set configuration.
|
63 |
+
response = completion(model=model_name,
|
64 |
+
api_key=api_key,
|
65 |
+
api_base=api_base,
|
66 |
messages=[{
|
67 |
"content": instruction,
|
68 |
"role": "system"
|