Spaces:
Running
Running
Updating org search API calls
Browse files- tools/org_seach.py +13 -5
tools/org_seach.py
CHANGED
@@ -7,7 +7,7 @@ from langchain.output_parsers.openai_tools import JsonOutputToolsParser
|
|
7 |
from langchain_openai.chat_models import ChatOpenAI
|
8 |
from langchain_core.runnables import RunnableSequence
|
9 |
from langchain_core.prompts import ChatPromptTemplate
|
10 |
-
from pydantic import BaseModel
|
11 |
|
12 |
try:
|
13 |
from common.org_search_component import OrgSearch
|
@@ -18,7 +18,8 @@ search = OrgSearch()
|
|
18 |
|
19 |
|
20 |
class OrganizationNames(BaseModel):
|
21 |
-
|
|
|
22 |
|
23 |
|
24 |
def extract_org_links_from_chatbot(chatbot_output: str):
|
@@ -34,7 +35,10 @@ def extract_org_links_from_chatbot(chatbot_output: str):
|
|
34 |
Raises:
|
35 |
ValueError: If parsing fails or if an unexpected output format is received.
|
36 |
"""
|
37 |
-
prompt = """Extract only the names of officially recognized organizations, foundations, and government entities
|
|
|
|
|
|
|
38 |
|
39 |
input text below:
|
40 |
|
@@ -121,7 +125,7 @@ def generate_org_link_dict(org_names_list: list):
|
|
121 |
for org in org_names_list:
|
122 |
try:
|
123 |
# Attempt to retrieve organization data
|
124 |
-
response = search(org)
|
125 |
|
126 |
# Check if there is a valid response and if names are similar
|
127 |
if response and is_similar(org, response[0].get("names", "")):
|
@@ -171,7 +175,11 @@ def embed_org_links_in_text(input_text: str, org_link_dict: dict):
|
|
171 |
)
|
172 |
|
173 |
# Append Candid information message at the end
|
174 |
-
input_text +=
|
|
|
|
|
|
|
|
|
175 |
|
176 |
except TypeError as e:
|
177 |
print(f"TypeError encountered: {e}")
|
|
|
7 |
from langchain_openai.chat_models import ChatOpenAI
|
8 |
from langchain_core.runnables import RunnableSequence
|
9 |
from langchain_core.prompts import ChatPromptTemplate
|
10 |
+
from pydantic import BaseModel, Field
|
11 |
|
12 |
try:
|
13 |
from common.org_search_component import OrgSearch
|
|
|
18 |
|
19 |
|
20 |
class OrganizationNames(BaseModel):
|
21 |
+
"""List of names of social-sector organizations, such as nonprofits and foundations."""
|
22 |
+
orgnames: List[str] = Field(description="List of organization names")
|
23 |
|
24 |
|
25 |
def extract_org_links_from_chatbot(chatbot_output: str):
|
|
|
35 |
Raises:
|
36 |
ValueError: If parsing fails or if an unexpected output format is received.
|
37 |
"""
|
38 |
+
prompt = """Extract only the names of officially recognized organizations, foundations, and government entities
|
39 |
+
from the text below. Do not include any entries that contain descriptions, regional identifiers, or explanations
|
40 |
+
within parentheses or following the name. Strictly exclude databases, resources, crowdfunding platforms, and general
|
41 |
+
terms. Provide the output only in the specified JSON format.
|
42 |
|
43 |
input text below:
|
44 |
|
|
|
125 |
for org in org_names_list:
|
126 |
try:
|
127 |
# Attempt to retrieve organization data
|
128 |
+
response = search(org, name_only=True)
|
129 |
|
130 |
# Check if there is a valid response and if names are similar
|
131 |
if response and is_similar(org, response[0].get("names", "")):
|
|
|
175 |
)
|
176 |
|
177 |
# Append Candid information message at the end
|
178 |
+
input_text += (
|
179 |
+
"<p class='candid-app-link'> "
|
180 |
+
"Visit <a href=https://app.candid.org/ target='_blank' rel='noreferrer' class='candid-org-link'>Candid</a> "
|
181 |
+
"to get nonprofit information you need.</p>"
|
182 |
+
)
|
183 |
|
184 |
except TypeError as e:
|
185 |
print(f"TypeError encountered: {e}")
|