Nina commited on
Commit
fa7f0c5
1 Parent(s): a327c68

Add to secret manager api_key and system

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -6,16 +6,14 @@ import numpy as np
6
  import openai
7
  import os
8
 
 
9
  document_store = FAISSDocumentStore.load(
10
  index_path=f"./documents/climate_gpt.faiss",
11
  config_path=f"./documents/climate_gpt.json",
12
  )
13
 
14
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
15
- system_template = {
16
- "role": "system",
17
- "content": "You have been a climate change expert for 30 years. You answer questions about climate change in an educationnal and concise manner. Whenever possible your answers are backed up by facts and numbers from scientific reports.",
18
- }
19
 
20
  dense = EmbeddingRetriever(
21
  document_store=document_store,
@@ -78,12 +76,14 @@ def gen_conv(query: str, history=[system_template], ipcc=True):
78
  return gradio_format, messages, sources
79
 
80
 
81
- def set_openai_api_key(api_key):
82
  """Set the api key and return chain.
83
  If no api_key, then None is returned.
84
  """
85
- os.environ["OPENAI_API_KEY"] = api_key
86
- openai.api_key = api_key
 
 
87
  return f"You're all set: this is your api key: {openai.api_key}"
88
 
89
 
 
6
  import openai
7
  import os
8
 
9
+
10
  document_store = FAISSDocumentStore.load(
11
  index_path=f"./documents/climate_gpt.faiss",
12
  config_path=f"./documents/climate_gpt.json",
13
  )
14
 
15
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
16
+ system_template = {"role": os.environ["role"], "content": os.environ["content"]}
 
 
 
17
 
18
  dense = EmbeddingRetriever(
19
  document_store=document_store,
 
76
  return gradio_format, messages, sources
77
 
78
 
79
+ def set_openai_api_key(text):
80
  """Set the api key and return chain.
81
  If no api_key, then None is returned.
82
  """
83
+ if text and text.startswith("sk-") and len(text) > 50:
84
+ openai.api_key = text
85
+ else:
86
+ openai.api_key = os.environ["api_key"]
87
  return f"You're all set: this is your api key: {openai.api_key}"
88
 
89