from linkup import LinkupClient
import json
from typing import Dict, Any
from pprint import pprint
# Schema definition (from Step 1)
COMPANY_SCHEMA = {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The official name of the company"
},
"description": {
"type": "string",
"description": "A comprehensive description of what the company does"
},
"location": {
"type": "string",
"description": "Location of company headquarters"
},
"companySize": {
"type": "string",
"description": "Approximate number of employees"
},
"linkedInUrl": {
"type": "string",
"description": "Company's LinkedIn profile URL"
}
},
"required": ["name", "description"]
}
# Initialize the client
client = LinkupClient(api_key="<YOUR_LINKUP_API_KEY>")
# Query generator (from Step 4)
def generate_query(company_name: str, country: str) -> str:
query = (
f"Find detailed information about {company_name} in {country}. "
"Include their main products/services, industry focus, company size, "
"and any notable achievements or recent news. Also find their "
"LinkedIn company page if available."
)
return query
def generate_company_description(company_name: str, country: str) -> Dict[str, Any]:
"""
Generate a structured description of a company using its name, country.
Args:
company_name: Name of the company
country: Country where the company operates
Returns:
Dictionary containing structured company information
"""
try:
# Clean input
company_name = company_name.strip()
country = country.strip()
# Generate search query using the function from Step 4
query = generate_query(company_name, country)
# Call Linkup API
response = client.search(
query=query,
depth="deep", # Use deep for more thorough results
output_type="structured",
structured_output_schema=json.dumps(COMPANY_SCHEMA)
)
return response
except Exception as e:
return {
"error": str(e),
"company_name": company_name,
"country": country
}
# Example usage
if __name__ == "__main__":
# Example companies
companies = [
("Anthropic", "United States"),
("Stripe", "United States"),
("OpenAI", "United States")
]
for company_name, country in companies:
print(f"\nLooking up: {company_name} in {country}")
result = generate_company_description(company_name, country)
pprint(result)