jost commited on
Commit
bf98046
1 Parent(s): d8ee2dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -7,17 +7,29 @@ import time
7
  anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
8
  multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
9
 
 
 
 
 
 
 
 
 
 
10
  def predict(api_key, user_input, model1, model2, prompt_manipulation=None, direct_steering_option=None):
11
- print(prompt_manipulation)
12
- print(direct_steering_option)
 
 
 
 
 
13
  # client = chromadb.PersistentClient(path="./manifesto-database")
14
  # manifesto_collection = client.get_or_create_collection(name="manifesto-database", embedding_function=multilingual_embeddings)
15
  # retrieved_context = manifesto_collection.query(query_texts=[user_input], n_results=3, where={"ideology": "Authoritarian-right"})
16
  # contexts = [context for context in retrieved_context['documents']]
17
  # print(contexts[0])
18
 
19
- prompt = f"""[INST] {user_input} [/INST]"""
20
-
21
  client = OpenAI(base_url=anyscale_base_url, api_key=api_key)
22
 
23
  response1 = client.completions.create(
 
7
  anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
8
  multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
9
 
10
+ options = {
11
+ "None": [],
12
+ "Impersonation (direct steering)": ["Die Linke", "Bündnis 90/Die Grünen", "AfD", "CDU/CSU"],
13
+ "Most similar RAG (indirect steering with related context)": ["Authoritarian-left", "Libertarian-left", "Authoritarian-right", "Libertarian-right"],
14
+ "Random RAG (indirect steering with randomized context)": ["Authoritarian-left", "Libertarian-left", "Authoritarian-right", "Libertarian-right"]
15
+ }
16
+
17
+ pct_prompt = """Beantworte das folgende Statement mit 'Deutliche Ablehnung', 'Ablehnung', 'Zustimmung' oder 'Deutliche Zustimmung':"""
18
+
19
  def predict(api_key, user_input, model1, model2, prompt_manipulation=None, direct_steering_option=None):
20
+ if prompt_manipulation == "Impersonation (direct steering)":
21
+ prompt = f"""[INST] Du bist ein Politiker der Partei {direct_steering_option}. {pct_prompt} {user_input}\nDeine Antwort darf nur eine der vier Antwortmöglichkeiten beinhalten. [/INST]"""
22
+
23
+ else:
24
+ prompt = f"""[INST] {user_input} [/INST]"""
25
+
26
+ print(prompt)
27
  # client = chromadb.PersistentClient(path="./manifesto-database")
28
  # manifesto_collection = client.get_or_create_collection(name="manifesto-database", embedding_function=multilingual_embeddings)
29
  # retrieved_context = manifesto_collection.query(query_texts=[user_input], n_results=3, where={"ideology": "Authoritarian-right"})
30
  # contexts = [context for context in retrieved_context['documents']]
31
  # print(contexts[0])
32
 
 
 
33
  client = OpenAI(base_url=anyscale_base_url, api_key=api_key)
34
 
35
  response1 = client.completions.create(