본문 바로가기
강의록~스터디/LangChain

[2주차] Ice Breaker app 만들기 (1)

by annmunju 2024. 1. 2.
유저의 링크드인 정보를 바탕으로 아이스 브레이크 질문을 생성해주는 페이지 생성

 

1.  Scraping

a. 링크드인 정보 샘플 생성 : 테스트 앱이므로 샘플로만 제작 (API 사용시 비용 발생)

1) Proxycurl 사이트 -> Linkedin API 키를 얻을 수 있는 페이지로 접속 https://nubela.co/proxycurl/linkedin

 

Enrich your B2B data with Proxycurl's premium APIs

Enrich LinkedIn profiles, get contact information, get venture funding data, and list jobs with Proxycurl's premium data enrichment APIs.

nubela.co

2) 하단에 API 키를 생성 후 토큰 확인

3) 문서에 작성된 파이썬 코드 혹은 Shell 문법 확인 (복사) https://nubela.co/proxycurl/docs?python#people-api

 

Complete API documentation for Proxycurl's B2B data enrichment APIs.

 

nubela.co

4) 파이썬 혹은 Shell에서 실행

import requests

api_key = 'YOUR_API_KEY'
headers = {'Authorization': 'Bearer ' + api_key}
api_endpoint = 'https://nubela.co/proxycurl/api/v2/linkedin'
params = {
    'twitter_profile_url': 'https://twitter.com/johnrmarty/',
    'facebook_profile_url': 'https://facebook.com/johnrmarty/',
    'linkedin_profile_url': 'https://linkedin.com/in/johnrmarty/',
    'extra': 'include',
    'github_profile_id': 'include',
    'facebook_profile_id': 'include',
    'twitter_profile_id': 'include',
    'personal_contact_number': 'include',
    'personal_email': 'include',
    'inferred_salary': 'include',
    'skills': 'include',
    'use_cache': 'if-present',
    'fallback_to_cache': 'on-error',
}
response = requests.get(api_endpoint,
                        params=params,
                        headers=headers)

5) response 된 결과 json을 파일로 생성 (혹은 github gist로 생성 -> 해당 링크를 request get 해서 데이터 불러올 수 있음)

 

b. 해당 데이터를 정리하는 함수 작성

import json

def load_linkedin_profile(): # 저장된 샘플 json 불러오기
    with open('src/sample.json', 'r') as f:
        sample_linkedin = json.load(f)
    
    return sample_linkedin

def scrape_linkedin_profile():#linkedin_profile_url:str): # 정리 후 반환
    sample_raw = load_linkedin_profile()
    
    data = {
        k: v
        for k, v in sample_raw.items()
        if v not in ([], "", "", None)
            and k not in ["people_also_viewed", "certifications"]
    }

    if data.get("groups"):
        for group_dict in data.get("groups"):
            group_dict.pop("profile_pic_url")

    return data

 

2. Agents Theory

Chain of Thought https://arxiv.org/pdf/2201.11903.pdf

 

3. Tools, AgentType & initialize_agent

- Agent 설정을 위한 파라미터

- Tools : 에이전트가 접근 가능한 도구 (API 등)
- AgentType : https://python.langchain.com/docs/modules/agents/agent_types/

 

728x90