Spaces:
Paused
Paused
hanoch.rahimi@gmail
commited on
Commit
·
749a763
1
Parent(s):
9376584
use also env variables
Browse files- app.py +2 -2
- openai_utils.py +9 -12
- utils.py +24 -4
app.py
CHANGED
@@ -33,7 +33,7 @@ COUNTRIES_FN="data/countries.csv"
|
|
33 |
country_geo = pd.read_csv(COUNTRIES_FN)
|
34 |
|
35 |
st.session_state.index = utils.init_pinecone()
|
36 |
-
st.session_state.
|
37 |
|
38 |
carddict = {
|
39 |
"name": [],
|
@@ -165,7 +165,7 @@ def run_query(query, report_type, top_k , regions, countries, is_debug, index_na
|
|
165 |
#descriptions = "\n".join([f"Description of company \"{res['name']}\": {res['data']['Summary']}.\n" for res in results[:20] if 'Summary' in res['data']])
|
166 |
|
167 |
m_text = oai.call_openai(query, engine=openai_model, temp=0, top_p=1.0)
|
168 |
-
results = st.session_state.
|
169 |
m_text
|
170 |
st.session_state.messages.append({"role": "user", "content": query})
|
171 |
st.session_state.messages.append({"role": "system", "content": m_text})
|
|
|
33 |
country_geo = pd.read_csv(COUNTRIES_FN)
|
34 |
|
35 |
st.session_state.index = utils.init_pinecone()
|
36 |
+
st.session_state.db_search_results = []
|
37 |
|
38 |
carddict = {
|
39 |
"name": [],
|
|
|
165 |
#descriptions = "\n".join([f"Description of company \"{res['name']}\": {res['data']['Summary']}.\n" for res in results[:20] if 'Summary' in res['data']])
|
166 |
|
167 |
m_text = oai.call_openai(query, engine=openai_model, temp=0, top_p=1.0)
|
168 |
+
results = st.session_state.db_search_results
|
169 |
m_text
|
170 |
st.session_state.messages.append({"role": "user", "content": query})
|
171 |
st.session_state.messages.append({"role": "system", "content": m_text})
|
openai_utils.py
CHANGED
@@ -8,18 +8,11 @@ import streamlit as st
|
|
8 |
|
9 |
import utils
|
10 |
|
11 |
-
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"] # app.pinecone.io
|
12 |
-
OPENAI_ORGANIZATION_ID = st.secrets["OPENAI_ORGANIZATION_ID"]
|
13 |
-
|
14 |
-
|
15 |
-
headers = {"Content-Type": "application/json",
|
16 |
-
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
17 |
-
}
|
18 |
|
19 |
SEED = 42
|
20 |
|
21 |
def get_client():
|
22 |
-
return openai.OpenAI(api_key = OPENAI_API_KEY,organization=OPENAI_ORGANIZATION_ID)
|
23 |
|
24 |
def getListOfCompanies(query, filters = {}):
|
25 |
country_filters = filters['country'] if 'country' in filters else st.session_state.country
|
@@ -72,10 +65,14 @@ def wait_for_response(thread, run):
|
|
72 |
if tool_call.function.name =="getListOfCompanies":
|
73 |
try:
|
74 |
args = json.loads(tool_call.function.arguments)
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
except Exception as e:
|
80 |
print(f"Error calling tools, {str(e)}")
|
81 |
traceback.print_exc()
|
|
|
8 |
|
9 |
import utils
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
SEED = 42
|
13 |
|
14 |
def get_client():
|
15 |
+
return openai.OpenAI(api_key = utils.OPENAI_API_KEY,organization=utils.OPENAI_ORGANIZATION_ID)
|
16 |
|
17 |
def getListOfCompanies(query, filters = {}):
|
18 |
country_filters = filters['country'] if 'country' in filters else st.session_state.country
|
|
|
65 |
if tool_call.function.name =="getListOfCompanies":
|
66 |
try:
|
67 |
args = json.loads(tool_call.function.arguments)
|
68 |
+
res = ''
|
69 |
+
if 'query' in args:
|
70 |
+
print(f"Processing tool_call {tool_call.id}. Calling 'getListOfCompanies with args: {args}" )
|
71 |
+
search_filters = json.loads(args['filters']) if 'filters' in args else []
|
72 |
+
res = getListOfCompanies(args['query'], search_filters)
|
73 |
+
|
74 |
+
|
75 |
+
outputs[tool_call.id] = res
|
76 |
except Exception as e:
|
77 |
print(f"Error calling tools, {str(e)}")
|
78 |
traceback.print_exc()
|
utils.py
CHANGED
@@ -1,11 +1,34 @@
|
|
1 |
import json
|
2 |
|
3 |
import pandas as pd
|
|
|
|
|
|
|
|
|
4 |
import pinecone
|
5 |
import psycopg2
|
6 |
from psycopg2 import extras
|
7 |
import streamlit as st
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# def create_connection():
|
11 |
# host = st.secrets["RAIZED_DB_HOST"]
|
@@ -24,9 +47,6 @@ import openai
|
|
24 |
|
25 |
## Pinecone
|
26 |
|
27 |
-
PINECONE_KEY = st.secrets["PINECONE_API_KEY"] # app.pinecone.io
|
28 |
-
PINE_CONE_ENVIRONMENT = st.secrets["PINE_CONE_ENVIRONMENT"] # app.pinecone.io
|
29 |
-
|
30 |
@st.cache_resource
|
31 |
def init_pinecone():
|
32 |
pinecone.init(api_key=PINECONE_KEY, environment=PINE_CONE_ENVIRONMENT) # get a free api key from app.pinecone.io
|
|
|
1 |
import json
|
2 |
|
3 |
import pandas as pd
|
4 |
+
import os
|
5 |
+
|
6 |
+
# from google.cloud import secretmanager
|
7 |
+
import openai
|
8 |
import pinecone
|
9 |
import psycopg2
|
10 |
from psycopg2 import extras
|
11 |
import streamlit as st
|
12 |
+
|
13 |
+
|
14 |
+
# gcp_client = secretmanager.SecretManagerServiceClient()
|
15 |
+
# response = gcp_client.access_secret_version(request={"name": version.name})
|
16 |
+
|
17 |
+
def get_variable(name):
|
18 |
+
return os.getenv(name, st.secrets[name])
|
19 |
+
|
20 |
+
OPENAI_API_KEY = get_variable("OPENAI_API_KEY") # app.pinecone.io
|
21 |
+
OPENAI_ORGANIZATION_ID = get_variable("OPENAI_ORGANIZATION_ID")
|
22 |
+
|
23 |
+
PINECONE_KEY = get_variable("PINECONE_API_KEY") # app.pinecone.io
|
24 |
+
PINE_CONE_ENVIRONMENT = get_variable("PINE_CONE_ENVIRONMENT") # app.pinecone.io
|
25 |
+
|
26 |
+
# OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"] # app.pinecone.io
|
27 |
+
# OPENAI_ORGANIZATION_ID = st.secrets["OPENAI_ORGANIZATION_ID"]
|
28 |
+
|
29 |
+
# PINECONE_KEY = st.secrets["PINECONE_API_KEY"] # app.pinecone.io
|
30 |
+
# PINE_CONE_ENVIRONMENT = st.secrets["PINE_CONE_ENVIRONMENT"] # app.pinecone.io
|
31 |
+
|
32 |
|
33 |
# def create_connection():
|
34 |
# host = st.secrets["RAIZED_DB_HOST"]
|
|
|
47 |
|
48 |
## Pinecone
|
49 |
|
|
|
|
|
|
|
50 |
@st.cache_resource
|
51 |
def init_pinecone():
|
52 |
pinecone.init(api_key=PINECONE_KEY, environment=PINE_CONE_ENVIRONMENT) # get a free api key from app.pinecone.io
|