■ set_verbose 함수를 사용하는 방법을 보여준다.
※ verbose 플래그를 설정하면 입력과 출력이 좀 더 읽기 쉬운 형식으로 인쇄되고 특정 원시 출력(예 : LLM 호출의 토큰 사용 통계) 로깅을 건너뛰므로 애플리케이션 논리에 집중할 수 있다.
※ OPENAI_API_KEY 및 TAVILY_API_KEY 환경 변수 값은 .env 파일에 정의한다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from dotenv import load_dotenv from langchain_openai import ChatOpenAI from langchain_community.tools.tavily_search import TavilySearchResults from langchain_core.prompts import ChatPromptTemplate from langchain.agents import create_tool_calling_agent from langchain.globals import set_verbose from langchain.agents import AgentExecutor load_dotenv() chatOpenAI = ChatOpenAI(model = "gpt-3.5-turbo-0125") toolList = [TavilySearchResults(max_results = 1)] chatPromptTemplate = ChatPromptTemplate.from_messages( [ ("system" , "You are a helpful assistant."), ("placeholder", "{chat_history}" ), ("human" , "{input}" ), ("placeholder", "{agent_scratchpad}" ) ] ) agentRunnableSequence = create_tool_calling_agent(chatOpenAI, toolList, chatPromptTemplate) set_verbose(True) agentExecutor = AgentExecutor(agent = agentRunnableSequence, tools = toolList) responseDictionary = agentExecutor.invoke({"input" : "Who directed the 2023 film Oppenheimer and what is their age in days?"}) print(responseDictionary) |
▶ 실행 결과
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
> Entering new AgentExecutor chain... Invoking: `tavily_search_results_json` with `{'query': 'Oppenheimer 2023 film director'}` [{'url': 'https://en.wikipedia.org/wiki/Oppenheimer_(film)', 'content': 'The film continued to hold well in the following weeks, making $32 million and $29.1 million in its fifth and sixth weekends.[174][175] As of September 10, 2023, the highest grossing territories were the United Kingdom ($72\xa0million), Germany ($46.9\xa0million), China ($46.8 million), France ($40.1 million) and Australia ($25.9\xa0million).[176]\nCritical response\nThe film received critical acclaim.[a] Critics praised Oppenheimer primarily for its screenplay, the performances of the cast (particularly Murphy and Downey), and the visuals;[b] it was frequently cited as one of Nolan\'s best films,[191][192][183] and of 2023, although some criticism was aimed towards the writing of the female characters.[187] Hindustan Times reported that the film was also hailed as one of the best films of the 21st century.[193] He also chose to alternate between scenes in color and black-and-white to convey the story from both subjective and objective perspectives, respectively,[68] with most of Oppenheimer\'s view shown via the former, while the latter depicts a "more objective view of his story from a different character\'s point of view".[69][67] Wanting to make the film as subjective as possible, the production team decided to include visions of Oppenheimer\'s conceptions of the quantum world and waves of energy.[70] Nolan noted that Oppenheimer never publicly apologized for his role in the atomic bombings of Hiroshima and Nagasaki, but still desired to portray Oppenheimer as feeling genuine guilt for his actions, believing this to be accurate.[71]\nI think of any character I\'ve dealt with, Oppenheimer is by far the most ambiguous and paradoxical. The production team was able to obtain government permission to film at White Sands Missile Range, but only at highly inconvenient hours, and therefore chose to film the scene elsewhere in the New Mexico desert.[2][95]\nThe production filmed the Trinity test scenes in Belen, New Mexico, with Murphy climbing a 100-foot steel tower, a replica of the original site used in the Manhattan Project, in rough weather.[2][95]\nA special set was built in which gasoline, propane, aluminum powder, and magnesium were used to create the explosive effect.[54] Although they used miniatures for the practical effect, the film\'s special effects supervisor Scott R. Fisher referred to them as "big-atures", since the special effects team had tried to build the models as physically large as possible. He felt that "while our relationship with that [nuclear] fear has ebbed and flowed with time, the threat itself never actually went away", and felt the 2022 Russian invasion of Ukraine had caused a resurgence of nuclear anxiety.[54] Nolan had also penned a script for a biopic of Howard Hughes approximately during the time of production of Martin Scorsese\'s The Aviator (2004), which had given him insight on how to write a script regarding a person\'s life.[53] Emily Blunt described the Oppenheimer script as "emotional" and resembling that of a thriller, while also remarking that Nolan had "Trojan-Horsed a biopic into a thriller".[72]\nCasting\nOppenheimer marks the sixth collaboration between Nolan and Murphy, and the first starring Murphy as the lead. [for Oppenheimer] in his approach to trying to deal with the consequences of what he\'d been involved with", while also underscoring that it is a "huge shift in perception about the reality of Oppenheimer\'s perception".[53] He wanted to execute a quick tonal shift after the atomic bombings of Hiroshima and Nagasaki, desiring to go from the "highest triumphalism, the highest high, to the lowest low in the shortest amount of screen time possible".[66] For the ending, Nolan chose to make it intentionally vague to be open to interpretation and refrained from being didactic or conveying specific messages in his work.'}] Invoking: `tavily_search_results_json` with `{'query': 'Christopher Nolan age'}` responded: The 2023 film "Oppenheimer" was directed by Christopher Nolan. Let me find out his age in days for you. [{'url': 'https://en.wikipedia.org/wiki/Christopher_Nolan', 'content': 'In early 2003, Nolan approached Warner Bros. with the idea of making a new Batman film, based on the character\'s origin story.[58] Nolan was fascinated by the notion of grounding it in a more realistic world than a comic-book fantasy.[59] He relied heavily on traditional stunts and miniature effects during filming, with minimal use of computer-generated imagery (CGI).[60] Batman Begins (2005), the biggest project Nolan had undertaken to that point,[61] was released to critical acclaim and commercial success.[62][63] Starring Christian Bale as Bruce Wayne / Batman—along with Michael Caine, Gary Oldman, Morgan Freeman and Liam Neeson—Batman Begins revived the franchise.[64][65] Batman Begins was 2005\'s ninth-highest-grossing film and was praised for its psychological depth and contemporary relevance;[63][66] it is cited as one of the most influential films of the 2000s.[67] Film author Ian Nathan wrote that within five years of his career, Nolan "[went] from unknown to indie darling to gaining creative control over one of the biggest properties in Hollywood, and (perhaps unwittingly) fomenting the genre that would redefine the entire industry".[68]\nNolan directed, co-wrote and produced The Prestige (2006), an adaptation of the Christopher Priest novel about two rival 19th-century magicians.[69] He directed, wrote and edited the short film Larceny (1996),[19] which was filmed over a weekend in black and white with limited equipment and a small cast and crew.[12][20] Funded by Nolan and shot with the UCL Union Film society\'s equipment, it appeared at the Cambridge Film Festival in 1996 and is considered one of UCL\'s best shorts.[21] For unknown reasons, the film has since been removed from public view.[19] Nolan filmed a third short, Doodlebug (1997), about a man seemingly chasing an insect with his shoe, only to discover that it is a miniature of himself.[14][22] Nolan and Thomas first attempted to make a feature in the mid-1990s with Larry Mahoney, which they scrapped.[23] During this period in his career, Nolan had little to no success getting his projects off the ground, facing several rejections; he added, "[T]here\'s a very limited pool of finance in the UK. Philosophy professor David Kyle Johnson wrote that "Inception became a classic almost as soon as it was projected on silver screens", praising its exploration of philosophical ideas, including leap of faith and allegory of the cave.[97] The film grossed over $836\xa0million worldwide.[98] Nominated for eight Academy Awards—including Best Picture and Best Original Screenplay—it won Best Cinematography, Best Sound Mixing, Best Sound Editing and Best Visual Effects.[99] Nolan was nominated for a BAFTA Award and a Golden Globe Award for Best Director, among other accolades.[40]\nAround the release of The Dark Knight Rises (2012), Nolan\'s third and final Batman film, Joseph Bevan of the British Film Institute wrote a profile on him: "In the space of just over a decade, Christopher Nolan has shot from promising British indie director to undisputed master of a new brand of intelligent escapism. He further wrote that Nolan\'s body of work reflect "a heterogeneity of conditions of products" extending from low-budget films to lucrative blockbusters, "a wide range of genres and settings" and "a diversity of styles that trumpet his versatility".[193]\nDavid Bordwell, a film theorist, wrote that Nolan has been able to blend his "experimental impulses" with the demands of mainstream entertainment, describing his oeuvre as "experiments with cinematic time by means of techniques of subjective viewpoint and crosscutting".[194] Nolan\'s use of practical, in-camera effects, miniatures and models, as well as shooting on celluloid film, has been highly influential in early 21st century cinema.[195][196] IndieWire wrote in 2019 that, Nolan "kept a viable alternate model of big-budget filmmaking alive", in an era where blockbuster filmmaking has become "a largely computer-generated art form".[196] Initially reluctant to make a sequel, he agreed after Warner Bros. repeatedly insisted.[78] Nolan wanted to expand on the noir quality of the first film by broadening the canvas and taking on "the dynamic of a story of the city, a large crime story\xa0... where you\'re looking at the police, the justice system, the vigilante, the poor people, the rich people, the criminals".[79] Continuing to minimalise the use of CGI, Nolan employed high-resolution IMAX cameras, making it the first major motion picture to use this technology.[80][81]'}] Invoking: `tavily_search_results_json` with `{'query': 'Christopher Nolan date of birth'}` responded: The 2023 film "Oppenheimer" was directed by Christopher Nolan. Let me find out his age in days for you. [{'url': 'https://en.wikipedia.org/wiki/Christopher_Nolan', 'content': 'In early 2003, Nolan approached Warner Bros. with the idea of making a new Batman film, based on the character\'s origin story.[58] Nolan was fascinated by the notion of grounding it in a more realistic world than a comic-book fantasy.[59] He relied heavily on traditional stunts and miniature effects during filming, with minimal use of computer-generated imagery (CGI).[60] Batman Begins (2005), the biggest project Nolan had undertaken to that point,[61] was released to critical acclaim and commercial success.[62][63] Starring Christian Bale as Bruce Wayne / Batman—along with Michael Caine, Gary Oldman, Morgan Freeman and Liam Neeson—Batman Begins revived the franchise.[64][65] Batman Begins was 2005\'s ninth-highest-grossing film and was praised for its psychological depth and contemporary relevance;[63][66] it is cited as one of the most influential films of the 2000s.[67] Film author Ian Nathan wrote that within five years of his career, Nolan "[went] from unknown to indie darling to gaining creative control over one of the biggest properties in Hollywood, and (perhaps unwittingly) fomenting the genre that would redefine the entire industry".[68]\nNolan directed, co-wrote and produced The Prestige (2006), an adaptation of the Christopher Priest novel about two rival 19th-century magicians.[69] He directed, wrote and edited the short film Larceny (1996),[19] which was filmed over a weekend in black and white with limited equipment and a small cast and crew.[12][20] Funded by Nolan and shot with the UCL Union Film society\'s equipment, it appeared at the Cambridge Film Festival in 1996 and is considered one of UCL\'s best shorts.[21] For unknown reasons, the film has since been removed from public view.[19] Nolan filmed a third short, Doodlebug (1997), about a man seemingly chasing an insect with his shoe, only to discover that it is a miniature of himself.[14][22] Nolan and Thomas first attempted to make a feature in the mid-1990s with Larry Mahoney, which they scrapped.[23] During this period in his career, Nolan had little to no success getting his projects off the ground, facing several rejections; he added, "[T]here\'s a very limited pool of finance in the UK. Philosophy professor David Kyle Johnson wrote that "Inception became a classic almost as soon as it was projected on silver screens", praising its exploration of philosophical ideas, including leap of faith and allegory of the cave.[97] The film grossed over $836\xa0million worldwide.[98] Nominated for eight Academy Awards—including Best Picture and Best Original Screenplay—it won Best Cinematography, Best Sound Mixing, Best Sound Editing and Best Visual Effects.[99] Nolan was nominated for a BAFTA Award and a Golden Globe Award for Best Director, among other accolades.[40]\nAround the release of The Dark Knight Rises (2012), Nolan\'s third and final Batman film, Joseph Bevan of the British Film Institute wrote a profile on him: "In the space of just over a decade, Christopher Nolan has shot from promising British indie director to undisputed master of a new brand of intelligent escapism. He further wrote that Nolan\'s body of work reflect "a heterogeneity of conditions of products" extending from low-budget films to lucrative blockbusters, "a wide range of genres and settings" and "a diversity of styles that trumpet his versatility".[193]\nDavid Bordwell, a film theorist, wrote that Nolan has been able to blend his "experimental impulses" with the demands of mainstream entertainment, describing his oeuvre as "experiments with cinematic time by means of techniques of subjective viewpoint and crosscutting".[194] Nolan\'s use of practical, in-camera effects, miniatures and models, as well as shooting on celluloid film, has been highly influential in early 21st century cinema.[195][196] IndieWire wrote in 2019 that, Nolan "kept a viable alternate model of big-budget filmmaking alive", in an era where blockbuster filmmaking has become "a largely computer-generated art form".[196] Initially reluctant to make a sequel, he agreed after Warner Bros. repeatedly insisted.[78] Nolan wanted to expand on the noir quality of the first film by broadening the canvas and taking on "the dynamic of a story of the city, a large crime story\xa0... where you\'re looking at the police, the justice system, the vigilante, the poor people, the rich people, the criminals".[79] Continuing to minimalise the use of CGI, Nolan employed high-resolution IMAX cameras, making it the first major motion picture to use this technology.[80][81]'}] Invoking: `tavily_search_results_json` with `{'query': 'days between July 30, 1970 and today'}` responded: Christopher Nolan was born on July 30, 1970. Now, I will calculate his age in days. [{'url': 'https://www.timeanddate.com/date/duration.html', 'content': 'Date Calculators. Time and Date Duration - Calculate duration, with both date and time included. Date Calculator - Add or subtract days, months, years. Weekday Calculator - What day is this date? Birthday Calculator - Find when you are 1 billion seconds old. Week Number Calculator - Find the week number for any date.'}]Christopher Nolan is approximately 19,729 days old. > Finished chain. {'input': 'Who directed the 2023 film Oppenheimer and what is their age in days?', 'output': 'Christopher Nolan is approximately 19,729 days old.'} """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
aiohttp==3.9.5 aiosignal==1.3.1 annotated-types==0.7.0 anyio==4.4.0 async-timeout==4.0.3 attrs==23.2.0 certifi==2024.6.2 charset-normalizer==3.3.2 dataclasses-json==0.6.7 distro==1.9.0 exceptiongroup==1.2.1 frozenlist==1.4.1 greenlet==3.0.3 h11==0.14.0 httpcore==1.0.5 httpx==0.27.0 idna==3.7 jsonpatch==1.33 jsonpointer==3.0.0 langchain==0.2.5 langchain-community==0.2.5 langchain-core==0.2.9 langchain-openai==0.1.8 langchain-text-splitters==0.2.1 langsmith==0.1.80 marshmallow==3.21.3 multidict==6.0.5 mypy-extensions==1.0.0 numpy==1.26.4 openai==1.34.0 orjson==3.10.5 packaging==24.1 pydantic==2.7.4 pydantic_core==2.18.4 python-dotenv==1.0.1 PyYAML==6.0.1 regex==2024.5.15 requests==2.32.3 sniffio==1.3.1 SQLAlchemy==2.0.31 tavily-python==0.3.3 tenacity==8.4.1 tiktoken==0.7.0 tqdm==4.66.4 typing-inspect==0.9.0 typing_extensions==4.12.2 urllib3==2.2.2 yarl==1.9.4 |
※ pip install python-dotenv langchain langchain-community langchain-openai tavily-python 명령을 실행했다.