Kang Suhyun commited on
Commit
17b1403
1 Parent(s): b272a27

[#54] Save all LLM responses regardless of user voting (#58)

Browse files

This change aims to ensure all LLM responses are saved, independent of user voting.

Responses are stored in both the `history` and the relevant `summarization` or `translation` tables. This facilitates easier access to battle data without needing to query the history table.

Files changed (1) hide show
  1. response.py +23 -1
response.py CHANGED
@@ -6,13 +6,16 @@ import enum
6
  import json
7
  import os
8
  from random import sample
 
9
 
 
10
  from google.cloud import secretmanager
11
  from google.oauth2 import service_account
12
  import gradio as gr
13
  from litellm import completion
14
 
15
  from credentials import get_credentials_json
 
16
 
17
  GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT")
18
  MODELS_SECRET = os.environ.get("MODELS_SECRET")
@@ -28,6 +31,23 @@ decoded_secret = models_secret.payload.data.decode("UTF-8")
28
  supported_models = json.loads(decoded_secret)
29
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  class Category(enum.Enum):
32
  SUMMARIZE = "Summarize"
33
  TRANSLATE = "Translate"
@@ -73,7 +93,9 @@ def get_responses(user_prompt, category, source_lang, target_lang):
73
  "content": user_prompt,
74
  "role": "user"
75
  }])
76
- responses.append(response.choices[0].message.content)
 
 
77
 
78
  # TODO(#1): Narrow down the exception type.
79
  except Exception as e: # pylint: disable=broad-except
 
6
  import json
7
  import os
8
  from random import sample
9
+ from uuid import uuid4
10
 
11
+ from firebase_admin import firestore
12
  from google.cloud import secretmanager
13
  from google.oauth2 import service_account
14
  import gradio as gr
15
  from litellm import completion
16
 
17
  from credentials import get_credentials_json
18
+ from leaderboard import db
19
 
20
  GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT")
21
  MODELS_SECRET = os.environ.get("MODELS_SECRET")
 
31
  supported_models = json.loads(decoded_secret)
32
 
33
 
34
+ def create_history(model_name: str, instruction: str, prompt: str,
35
+ response: str):
36
+ doc_id = uuid4().hex
37
+
38
+ doc = {
39
+ "id": doc_id,
40
+ "model": model_name,
41
+ "instruction": instruction,
42
+ "prompt": prompt,
43
+ "response": response,
44
+ "timestamp": firestore.SERVER_TIMESTAMP
45
+ }
46
+
47
+ doc_ref = db.collection("arena-history").document(doc_id)
48
+ doc_ref.set(doc)
49
+
50
+
51
  class Category(enum.Enum):
52
  SUMMARIZE = "Summarize"
53
  TRANSLATE = "Translate"
 
93
  "content": user_prompt,
94
  "role": "user"
95
  }])
96
+ content = response.choices[0].message.content
97
+ create_history(model, instruction, user_prompt, content)
98
+ responses.append(content)
99
 
100
  # TODO(#1): Narrow down the exception type.
101
  except Exception as e: # pylint: disable=broad-except