Spaces:
Running
Running
hanoch.rahimi@gmail
commited on
Commit
·
e54b3e0
1
Parent(s):
6a2ae7a
Added conversation
Browse files- app.py +7 -0
- openai_utils.py +28 -0
- semsearch.pyproj +1 -0
- utils.py +27 -3
app.py
CHANGED
@@ -4,6 +4,7 @@ from langchain.chains import RetrievalQA
|
|
4 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
5 |
from langchain.prompts import PromptTemplate
|
6 |
from langchain.vectorstores import Pinecone
|
|
|
7 |
import openai
|
8 |
import pinecone
|
9 |
import streamlit as st
|
@@ -42,8 +43,14 @@ def init_models():
|
|
42 |
#reader = pipeline(tokenizer=model_name, model=model_name, task='question-answering')
|
43 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
44 |
#vectorstore = Pinecone(st.session_state.index, embed.embed_query, text_field)
|
|
|
|
|
|
|
|
|
|
|
45 |
return retriever, tokenizer#, vectorstore
|
46 |
|
|
|
47 |
retriever, tokenizer = init_models()
|
48 |
#st.session_state.messages = [{"role":"system", "content":"You are an assistant who helps users find startups to invest in."}]
|
49 |
|
|
|
4 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
5 |
from langchain.prompts import PromptTemplate
|
6 |
from langchain.vectorstores import Pinecone
|
7 |
+
from streamlit.runtime.state import session_state
|
8 |
import openai
|
9 |
import pinecone
|
10 |
import streamlit as st
|
|
|
43 |
#reader = pipeline(tokenizer=model_name, model=model_name, task='question-answering')
|
44 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
45 |
#vectorstore = Pinecone(st.session_state.index, embed.embed_query, text_field)
|
46 |
+
st.session_state.openai_client = openai.OpenAI(api_key = OPENAI_API_KEY,organization='org-EEpryZYLlh0mZJOGxVko32qP')
|
47 |
+
# client.beta.assistants.create(
|
48 |
+
# instructions=utils.assistant_instructions,
|
49 |
+
# model="gpt-4-1106-preview",
|
50 |
+
# tools=[{"type": "code_interpreter"}])
|
51 |
return retriever, tokenizer#, vectorstore
|
52 |
|
53 |
+
|
54 |
retriever, tokenizer = init_models()
|
55 |
#st.session_state.messages = [{"role":"system", "content":"You are an assistant who helps users find startups to invest in."}]
|
56 |
|
openai_utils.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
def send_message(role, content):
|
6 |
+
message = st.session_state.openai_client.beta.threads.messages.create(
|
7 |
+
thread_id=st.session_state.assistant_thread.id,
|
8 |
+
role=role,
|
9 |
+
content=content
|
10 |
+
)
|
11 |
+
|
12 |
+
def start_conversation():
|
13 |
+
st.session_state.assistant_thread = st.session_state.openai_client.beta.threads.create()
|
14 |
+
|
15 |
+
|
16 |
+
def run_assistant():
|
17 |
+
run = st.session_state.openai_client.beta.threads.runs.create(
|
18 |
+
thread_id=st.session_state.assistant_thread.id,
|
19 |
+
assistant_id=st.session_state.assistant.id,
|
20 |
+
)
|
21 |
+
while run.status == "queued" or run.status == "in_progress":
|
22 |
+
run = st.session_state.openai_client.beta.threads.runs.retrieve(
|
23 |
+
thread_id=st.session_state.assistant_thread.id,
|
24 |
+
run_id=run.id,
|
25 |
+
)
|
26 |
+
time.sleep(0.5)
|
27 |
+
return run
|
28 |
+
|
semsearch.pyproj
CHANGED
@@ -38,6 +38,7 @@
|
|
38 |
</ItemGroup>
|
39 |
<ItemGroup>
|
40 |
<Compile Include="app.py" />
|
|
|
41 |
<Compile Include="utils.py" />
|
42 |
</ItemGroup>
|
43 |
<ItemGroup>
|
|
|
38 |
</ItemGroup>
|
39 |
<ItemGroup>
|
40 |
<Compile Include="app.py" />
|
41 |
+
<Compile Include="openai_utils.py" />
|
42 |
<Compile Include="utils.py" />
|
43 |
</ItemGroup>
|
44 |
<ItemGroup>
|
utils.py
CHANGED
@@ -21,17 +21,18 @@ import openai
|
|
21 |
|
22 |
def call_openai(prompt, engine="gpt-3.5-turbo", temp=0, top_p=1.0, max_tokens=4048):
|
23 |
try:
|
24 |
-
response =
|
25 |
model=engine,
|
26 |
messages=st.session_state.messages,
|
27 |
temperature=temp,
|
28 |
max_tokens=max_tokens
|
29 |
)
|
30 |
print(f"Open AI response\n {response}")
|
31 |
-
text = response.choices[0].message
|
32 |
st.session_state.messages.append({"role": "system", "content": text})
|
33 |
return text
|
34 |
-
except
|
|
|
35 |
print(f"An error occurred: {str(e)}")
|
36 |
return "Failed to generate a response."
|
37 |
|
@@ -80,6 +81,29 @@ def get_prompt(title):
|
|
80 |
# print(f"Results getting {title}")
|
81 |
# return res
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# default_prompt = """
|
84 |
# summarize the outcome of this search. The context is a list of company names followed by the company's description and a relevance score to the user query.
|
85 |
# the report should mention the most important companies and how they compare to each other and contain the following sections:
|
|
|
21 |
|
22 |
def call_openai(prompt, engine="gpt-3.5-turbo", temp=0, top_p=1.0, max_tokens=4048):
|
23 |
try:
|
24 |
+
response = st.session_state.openai_client.chat.completions.create(
|
25 |
model=engine,
|
26 |
messages=st.session_state.messages,
|
27 |
temperature=temp,
|
28 |
max_tokens=max_tokens
|
29 |
)
|
30 |
print(f"Open AI response\n {response}")
|
31 |
+
text = response.choices[0].message.content.strip()
|
32 |
st.session_state.messages.append({"role": "system", "content": text})
|
33 |
return text
|
34 |
+
except Exception as e:
|
35 |
+
#except openai.error.OpenAIError as e:
|
36 |
print(f"An error occurred: {str(e)}")
|
37 |
return "Failed to generate a response."
|
38 |
|
|
|
81 |
# print(f"Results getting {title}")
|
82 |
# return res
|
83 |
|
84 |
+
|
85 |
+
assistant_instructions = """Start like this:
|
86 |
+
Please find here a list of startups that match the criteria you gave me (right now make a list up, later we will retrieve the list in a step before this).
|
87 |
+
|
88 |
+
I like you to present a list view with the option to open up a more detailed view per startup including the location of the startup, the founders and the founding year.
|
89 |
+
|
90 |
+
Ask the user to select startups that are of interest for them (just indicate the numbers).
|
91 |
+
|
92 |
+
Also invite users to think of other criteria that could help them qualify the startups further such as
|
93 |
+
1) founder and team characteristics:
|
94 |
+
- serial entrepreneurs in the team
|
95 |
+
- strong tech capabilities in the team
|
96 |
+
- female founders or younger / older founders in the team
|
97 |
+
- founders who graduated from top 100 universities
|
98 |
+
|
99 |
+
ask the user if they would like to use those criteria for filtering (with the downside of seeing potentially very few startups) or rather apply it for ranking the companies (with the downside that there will be a lot of companies at the bottom of the list that are not a match at all).
|
100 |
+
|
101 |
+
Invite users to name other criteria even if we are currently not able to provide such features. Ideally, they are possible to extract from a company's website or public founder profiles on social media.
|
102 |
+
|
103 |
+
Output a json that specifies the filter criteria important to a user with the output variable.
|
104 |
+
Also name the ranking criteria and suggest how to combine them to best meet the user's preferences.
|
105 |
+
"""
|
106 |
+
|
107 |
# default_prompt = """
|
108 |
# summarize the outcome of this search. The context is a list of company names followed by the company's description and a relevance score to the user query.
|
109 |
# the report should mention the most important companies and how they compare to each other and contain the following sections:
|