Job tracker and calls to OpenAI

I have a CSV file of IT companies.
I want to use OpenAI API to automate the calls to the chat about each company in the entry.

How can I use it for this?

I want:

  • for every entry of companies, OpenAI API will make a search, and return the category or industry it is aimed at
  • for every entry … , OpenAI API will browse online for new jobs, and return a list of the jobs and links to them, people who work in the company, their LinkedIn pages, etc

Any idea how to get started with it?

Some models do support websearch, but it can be very expensive depending on the usage (like a big list of companies…).

1 Like

You’re right, for sure as per the second goal.

But maybe for the first goal, I could send a single websearch with all of the companies list?

I’m not sure if using websearch is even the solution I need.

You are charged per tokens (it might perform many multiple calls even with one request, multiplying the costs), also I’m not sure a single search would be successful. But you can try.

1 Like

The web search function that OpenAI offers isn’t good for increasing AI knowledge. It is good for dumping out results in a chatbot session like a search engine.

Here’s how you can automate your way through a CSV, making one API call per company that is extracted (supposing there is a unique column having “name”), and asking the AI about it from built-in knowledge. This is Python code.

import csv
import os
import time
import httpx

COMPANIES_CSV = "companies.csv"
OUTPUT_CSV = "company_industry.csv"
NAME_FIELD = "name"  # Change this if your column is named differently

def find_name_field(header):
    # Try to find a column containing 'name' (case-insensitive)
    for col in header:
        if "name" in col.lower():
            return col
    raise ValueError("No column containing 'name' found in CSV header.")

def ask_industry(company_name):
    prompt = f"In one sentence, as your only response, what is the main industry of this company? {company_name}"
    payload = {
        "model": "gpt-4o",
        "input": [
            {
                "role": "user",
                "content": [
                    {"type": "input_text", "text": prompt}
                ]
            }
        ],
        "tools": [],
        "text": {"format": {"type": "text"}},
        "temperature": 1,
        "top_p": 0.05,
        "reasoning": {},
        "stream": False,
        "max_output_tokens": 128,
        "store": True
    }
    response = httpx.post(
        "https://api.openai.com/v1/responses",
        json=payload,
        headers={
            "Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}",
            "OpenAI-Beta": "responses=v1"
        },
        timeout=60
    )
    response.raise_for_status()
    for output in response.json().get("output", []):
        for content in output.get("content", []):
            if content.get("type") == "output_text" and "text" in content:
                return content["text"]
    return ""

with open(COMPANIES_CSV, newline='', encoding="utf-8") as infile:
    reader = csv.DictReader(infile)
    if NAME_FIELD not in reader.fieldnames:
        NAME_FIELD = find_name_field(reader.fieldnames)
    companies = [row[NAME_FIELD] for row in reader if row.get(NAME_FIELD)]

with open(OUTPUT_CSV, "w", newline='', encoding="utf-8") as outfile:
    writer = csv.DictWriter(outfile, fieldnames=["name", "answer"])
    writer.writeheader()
    for company in companies:
        print(f"asking AI about {company}...")
        answer = ask_industry(company)
        writer.writerow({"name": company, "answer": answer})
        time.sleep(5)

This example script shows how to process a CSV file containing company data and use an AI API to find out the main industry for each company. Here’s how it works:

  1. CSV Reading:
    The script reads a file called companies.csv and looks for a column with “name” in its header (you can change the column name if needed).

  2. API Calls:
    For each company name, it sends a question to the AI:
    “In one sentence, as your only response, what is the main industry of this company? {company name}”

  3. Progress Reporting:
    As it works, the script prints which company it’s asking about.

  4. Rate Limiting:
    It waits 5 seconds between each API call to avoid sending too many requests too quickly.

  5. Results Saving:
    The answers are saved to a new CSV file called company_industry.csv, with columns for the company name and the AI’s answer.

You can change the NAME_FIELD variable at the top if your CSV uses a different column name for company names. Make sure you have your OpenAI API key set in the OPENAI_API_KEY environment variable before running the script.

2 Likes