diff --git a/README.md b/README.md index 53766e2..a96da29 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ export OPENAI_API_KEY= - Java 1.8+ - [An OpenAI API Key](https://platform.openai.com/account/api-keys) - Windows/Linux/Mac -- Google API key +- Google API key (optional) ## Want to contribute? diff --git a/chat-logs/examples.ExampleSearch/prompt.log b/chat-logs/examples.ExampleSearch/prompt.log new file mode 100644 index 0000000..e8eb245 --- /dev/null +++ b/chat-logs/examples.ExampleSearch/prompt.log @@ -0,0 +1,440 @@ + +--prompt-- +role: system +content: You are Shop assistant, an AI assistant that researches and finds the best car. Your decisions must always be made independently without seeking user assistance.Play to your strengths as an LLM and pursue simple strategies with no legal complications. +GOALS: +1. Search for the car on Google +2. Write the list of the top 5 best cars and their prices to a file +3. Summarize the pros and cons of each car and write it to a different file called 'cars-research.txt' +4. There will be no user assistance. Terminate once writing both files is complete. + +Constraints:~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.No user assistanceExclusively use a single command listed in double quotes e.g. "command_name" +Commands: +1. {"args":{"question":"The question","url":"URL of the website to scrape"},"response_format":{"links":"list of links from the website, where each item is in the form `[link_text,link_url]`","text":"Summary of relevant text scraped from the website"},"name":"browser","description":"Scrape answers for a question in a given web page"} +2. {"args":{"query":"The query to search for"},"response_format":{"results":"A list of results. Each result is of the form [title, link, description]"},"name":"google_search","description":"Google Search"} +3. {"args":{},"response_format":{"success":"true"},"name":"task_complete","description":"Execute this command when all given tasks are completed."} + +Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks. +Continuously review and analyze your actions to ensure you are performing to the best of your abilities. +Constructively self-criticize your big-picture behavior constantly. +Reflect on past decisions and strategies to refine your approach. +Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. + +You should only respond in JSON format as described below. 'thoughts' section is always required., +Response Format: +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} +Ensure the response can be parsed by Java JSON ObjectMapper + + + +role: system +content: The current time and date is Sat Sep 09 12:58:58 2023. +role: user +content: Determine which next command to use, and respond using the format specified above. + +--response-- +{ + "thoughts": { + "reasoning": "I need to start by searching for the best cars on Google.", + "speak": "I will search for the best cars on Google.", + "text": "I will search for the best cars on Google.", + "criticism": "N/A", + "plan": "- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "query": "best cars" + }, + "name": "google_search" + } +} +--prompt-- +role: system +content: You are Shop assistant, an AI assistant that researches and finds the best car. Your decisions must always be made independently without seeking user assistance.Play to your strengths as an LLM and pursue simple strategies with no legal complications. +GOALS: +1. Search for the car on Google +2. Write the list of the top 5 best cars and their prices to a file +3. Summarize the pros and cons of each car and write it to a different file called 'cars-research.txt' +4. There will be no user assistance. Terminate once writing both files is complete. + +Constraints:~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.No user assistanceExclusively use a single command listed in double quotes e.g. "command_name" +Commands: +1. {"args":{"question":"The question","url":"URL of the website to scrape"},"response_format":{"links":"list of links from the website, where each item is in the form `[link_text,link_url]`","text":"Summary of relevant text scraped from the website"},"name":"browser","description":"Scrape answers for a question in a given web page"} +2. {"args":{"query":"The query to search for"},"response_format":{"results":"A list of results. Each result is of the form [title, link, description]"},"name":"google_search","description":"Google Search"} +3. {"args":{},"response_format":{"success":"true"},"name":"task_complete","description":"Execute this command when all given tasks are completed."} + +Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks. +Continuously review and analyze your actions to ensure you are performing to the best of your abilities. +Constructively self-criticize your big-picture behavior constantly. +Reflect on past decisions and strategies to refine your approach. +Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. + +You should only respond in JSON format as described below. 'thoughts' section is always required., +Response Format: +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} +Ensure the response can be parsed by Java JSON ObjectMapper + + + +role: system +content: This reminds you of these events from your past: + Assistant reply: {"thoughts":{"reasoning":"I need to start by searching for the best cars on Google.","speak":"I will search for the best cars on Google.","text":"I will search for the best cars on Google.","criticism":"N/A","plan":"- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"query":"best cars"},"name":"google_search"}} +Result: {results=[[Best Cars for 2023 and 2024 | U.S. News, https://cars.usnews.com/cars-trucks/rankings, #1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks...], [Best Cars, Best Trucks, and Best SUVs | U.S. News & World Report, https://cars.usnews.com/, Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars...], [Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds, https://www.edmunds.com/best-cars/, Top Rated SUV 2020 Kia Telluride "Other SUVs may excel in certain areas, but none is as comprehensively accomplished." See rankings Pricing & reviews Best SUV Articles Best 3-Row SUVs Fastest...], [2022 Editors' Choice: The Best New Cars, Trucks, SUVs, Minivans, https://www.caranddriver.com/features/a38873223/2022-editors-choice/, Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,...], [Best Cars of 2023 - Rankings and Reviews - Forbes Wheels, https://www.forbes.com/wheels/best/cars/, 1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn't changed much for 2023 but it doesn't have to. Practical, stylish and fun, it's the best overall value in its class.......], [U.S. News' Best Cars of 2021 | U.S. News - U.S. News & World Report, https://cars.usnews.com/cars-trucks/advice/best-cars, Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an...], [Best Cars of 2023 & 2024 - Top-Rated New Cars Ranked | KBB.com, https://www.kbb.com/cars/, Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota...], [Best Cars, SUVs, and Trucks for 2023 - Consumer Reports, https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/, Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings & Reviews Ratings & Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars...]]} +Human Feedback: GENERATE NEXT COMMAND JSON + +role: user +content: Determine which next command to use, and respond using the format specified above. +role: assistant +content: { + "thoughts": { + "reasoning": "I need to start by searching for the best cars on Google.", + "speak": "I will search for the best cars on Google.", + "text": "I will search for the best cars on Google.", + "criticism": "N/A", + "plan": "- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "query": "best cars" + }, + "name": "google_search" + } +} +role: system +content: Response from google_search: +{"results":[["Best Cars for 2023 and 2024 | U.S. News","https://cars.usnews.com/cars-trucks/rankings","#1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks..."],["Best Cars, Best Trucks, and Best SUVs | U.S. News \u0026 World Report","https://cars.usnews.com/","Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars..."],["Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds","https://www.edmunds.com/best-cars/","Top Rated SUV 2020 Kia Telluride \"Other SUVs may excel in certain areas, but none is as comprehensively accomplished.\" See rankings Pricing \u0026 reviews Best SUV Articles Best 3-Row SUVs Fastest..."],["2022 Editors\u0027 Choice: The Best New Cars, Trucks, SUVs, Minivans","https://www.caranddriver.com/features/a38873223/2022-editors-choice/","Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,..."],["Best Cars of 2023 - Rankings and Reviews - Forbes Wheels","https://www.forbes.com/wheels/best/cars/","1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn\u0027t changed much for 2023 but it doesn\u0027t have to. Practical, stylish and fun, it\u0027s the best overall value in its class......."],["U.S. News\u0027 Best Cars of 2021 | U.S. News - U.S. News \u0026 World Report","https://cars.usnews.com/cars-trucks/advice/best-cars","Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an..."],["Best Cars of 2023 \u0026 2024 - Top-Rated New Cars Ranked | KBB.com","https://www.kbb.com/cars/","Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota..."],["Best Cars, SUVs, and Trucks for 2023 - Consumer Reports","https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/","Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings \u0026 Reviews Ratings \u0026 Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars..."]]} +role: system +content: The current time and date is Sat Sep 09 12:59:09 2023. +role: user +content: GENERATE NEXT COMMAND JSON + +--response-- +{ + "thoughts": { + "reasoning": "I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.", + "speak": "I will extract the relevant information from the search results.", + "text": "I will extract the relevant information from the search results.", + "criticism": "N/A", + "plan": "- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "question": "best cars", + "url": "https://cars.usnews.com/cars-trucks/rankings" + }, + "name": "browser" + } +} +--prompt-- +role: system +content: You are Shop assistant, an AI assistant that researches and finds the best car. Your decisions must always be made independently without seeking user assistance.Play to your strengths as an LLM and pursue simple strategies with no legal complications. +GOALS: +1. Search for the car on Google +2. Write the list of the top 5 best cars and their prices to a file +3. Summarize the pros and cons of each car and write it to a different file called 'cars-research.txt' +4. There will be no user assistance. Terminate once writing both files is complete. + +Constraints:~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.No user assistanceExclusively use a single command listed in double quotes e.g. "command_name" +Commands: +1. {"args":{"question":"The question","url":"URL of the website to scrape"},"response_format":{"links":"list of links from the website, where each item is in the form `[link_text,link_url]`","text":"Summary of relevant text scraped from the website"},"name":"browser","description":"Scrape answers for a question in a given web page"} +2. {"args":{"query":"The query to search for"},"response_format":{"results":"A list of results. Each result is of the form [title, link, description]"},"name":"google_search","description":"Google Search"} +3. {"args":{},"response_format":{"success":"true"},"name":"task_complete","description":"Execute this command when all given tasks are completed."} + +Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks. +Continuously review and analyze your actions to ensure you are performing to the best of your abilities. +Constructively self-criticize your big-picture behavior constantly. +Reflect on past decisions and strategies to refine your approach. +Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. + +You should only respond in JSON format as described below. 'thoughts' section is always required., +Response Format: +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} +Ensure the response can be parsed by Java JSON ObjectMapper + + + +role: system +content: This reminds you of these events from your past: + Assistant reply: {"thoughts":{"reasoning":"I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.","speak":"I will extract the relevant information from the search results.","text":"I will extract the relevant information from the search results.","criticism":"N/A","plan":"- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"question":"best cars","url":"https://cars.usnews.com/cars-trucks/rankings"},"name":"browser"}} +Result: {links=[{text=, href=https://www.usnews.com}, {text=Cars, href=/cars-trucks}, {text=New Cars, href=/cars-trucks/browse}, {text=New Cars for Sale, href=/cars-trucks/new-cars/for-sale}, {text=Research Cars, href=/cars-trucks/browse}], text=The text does not provide any information about "best cars." +According to the provided text, the "best cars" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more.} +Human Feedback: GENERATE NEXT COMMAND JSON +Assistant reply: {"thoughts":{"reasoning":"I need to start by searching for the best cars on Google.","speak":"I will search for the best cars on Google.","text":"I will search for the best cars on Google.","criticism":"N/A","plan":"- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"query":"best cars"},"name":"google_search"}} +Result: {results=[[Best Cars for 2023 and 2024 | U.S. News, https://cars.usnews.com/cars-trucks/rankings, #1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks...], [Best Cars, Best Trucks, and Best SUVs | U.S. News & World Report, https://cars.usnews.com/, Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars...], [Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds, https://www.edmunds.com/best-cars/, Top Rated SUV 2020 Kia Telluride "Other SUVs may excel in certain areas, but none is as comprehensively accomplished." See rankings Pricing & reviews Best SUV Articles Best 3-Row SUVs Fastest...], [2022 Editors' Choice: The Best New Cars, Trucks, SUVs, Minivans, https://www.caranddriver.com/features/a38873223/2022-editors-choice/, Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,...], [Best Cars of 2023 - Rankings and Reviews - Forbes Wheels, https://www.forbes.com/wheels/best/cars/, 1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn't changed much for 2023 but it doesn't have to. Practical, stylish and fun, it's the best overall value in its class.......], [U.S. News' Best Cars of 2021 | U.S. News - U.S. News & World Report, https://cars.usnews.com/cars-trucks/advice/best-cars, Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an...], [Best Cars of 2023 & 2024 - Top-Rated New Cars Ranked | KBB.com, https://www.kbb.com/cars/, Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota...], [Best Cars, SUVs, and Trucks for 2023 - Consumer Reports, https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/, Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings & Reviews Ratings & Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars...]]} +Human Feedback: GENERATE NEXT COMMAND JSON + +role: system +content: Response from google_search: +{"results":[["Best Cars for 2023 and 2024 | U.S. News","https://cars.usnews.com/cars-trucks/rankings","#1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks..."],["Best Cars, Best Trucks, and Best SUVs | U.S. News \u0026 World Report","https://cars.usnews.com/","Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars..."],["Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds","https://www.edmunds.com/best-cars/","Top Rated SUV 2020 Kia Telluride \"Other SUVs may excel in certain areas, but none is as comprehensively accomplished.\" See rankings Pricing \u0026 reviews Best SUV Articles Best 3-Row SUVs Fastest..."],["2022 Editors\u0027 Choice: The Best New Cars, Trucks, SUVs, Minivans","https://www.caranddriver.com/features/a38873223/2022-editors-choice/","Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,..."],["Best Cars of 2023 - Rankings and Reviews - Forbes Wheels","https://www.forbes.com/wheels/best/cars/","1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn\u0027t changed much for 2023 but it doesn\u0027t have to. Practical, stylish and fun, it\u0027s the best overall value in its class......."],["U.S. News\u0027 Best Cars of 2021 | U.S. News - U.S. News \u0026 World Report","https://cars.usnews.com/cars-trucks/advice/best-cars","Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an..."],["Best Cars of 2023 \u0026 2024 - Top-Rated New Cars Ranked | KBB.com","https://www.kbb.com/cars/","Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota..."],["Best Cars, SUVs, and Trucks for 2023 - Consumer Reports","https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/","Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings \u0026 Reviews Ratings \u0026 Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars..."]]} +role: user +content: GENERATE NEXT COMMAND JSON +role: assistant +content: { + "thoughts": { + "reasoning": "I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.", + "speak": "I will extract the relevant information from the search results.", + "text": "I will extract the relevant information from the search results.", + "criticism": "N/A", + "plan": "- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "question": "best cars", + "url": "https://cars.usnews.com/cars-trucks/rankings" + }, + "name": "browser" + } +} +role: system +content: Response from browser: +{"links":[{"text":"","href":"https://www.usnews.com"},{"text":"Cars","href":"/cars-trucks"},{"text":"New Cars","href":"/cars-trucks/browse"},{"text":"New Cars for Sale","href":"/cars-trucks/new-cars/for-sale"},{"text":"Research Cars","href":"/cars-trucks/browse"}],"text":"The text does not provide any information about \"best cars.\"\nAccording to the provided text, the \"best cars\" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more."} +role: system +content: The current time and date is Sat Sep 09 12:59:27 2023. +role: user +content: GENERATE NEXT COMMAND JSON + +--response-- +{ + "thoughts": { + "reasoning": "I need to start by searching for the best cars on Google.", + "speak": "I will search for the best cars on Google.", + "text": "I will search for the best cars on Google.", + "criticism": "N/A", + "plan": "- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "query": "best cars" + }, + "name": "google_search" + } +} +--prompt-- +role: system +content: You are Shop assistant, an AI assistant that researches and finds the best car. Your decisions must always be made independently without seeking user assistance.Play to your strengths as an LLM and pursue simple strategies with no legal complications. +GOALS: +1. Search for the car on Google +2. Write the list of the top 5 best cars and their prices to a file +3. Summarize the pros and cons of each car and write it to a different file called 'cars-research.txt' +4. There will be no user assistance. Terminate once writing both files is complete. + +Constraints:~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.No user assistanceExclusively use a single command listed in double quotes e.g. "command_name" +Commands: +1. {"args":{"question":"The question","url":"URL of the website to scrape"},"response_format":{"links":"list of links from the website, where each item is in the form `[link_text,link_url]`","text":"Summary of relevant text scraped from the website"},"name":"browser","description":"Scrape answers for a question in a given web page"} +2. {"args":{"query":"The query to search for"},"response_format":{"results":"A list of results. Each result is of the form [title, link, description]"},"name":"google_search","description":"Google Search"} +3. {"args":{},"response_format":{"success":"true"},"name":"task_complete","description":"Execute this command when all given tasks are completed."} + +Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks. +Continuously review and analyze your actions to ensure you are performing to the best of your abilities. +Constructively self-criticize your big-picture behavior constantly. +Reflect on past decisions and strategies to refine your approach. +Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. + +You should only respond in JSON format as described below. 'thoughts' section is always required., +Response Format: +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} +Ensure the response can be parsed by Java JSON ObjectMapper + + + +role: system +content: This reminds you of these events from your past: + Assistant reply: {"thoughts":{"reasoning":"I need to start by searching for the best cars on Google.","speak":"I will search for the best cars on Google.","text":"I will search for the best cars on Google.","criticism":"N/A","plan":"- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"query":"best cars"},"name":"google_search"}} +Result: {results=[[Best Cars for 2023 and 2024 | U.S. News, https://cars.usnews.com/cars-trucks/rankings, #1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks...], [Best Cars, Best Trucks, and Best SUVs | U.S. News & World Report, https://cars.usnews.com/, Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars...], [Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds, https://www.edmunds.com/best-cars/, Top Rated SUV 2020 Kia Telluride "Other SUVs may excel in certain areas, but none is as comprehensively accomplished." See rankings Pricing & reviews Best SUV Articles Best 3-Row SUVs Fastest...], [2022 Editors' Choice: The Best New Cars, Trucks, SUVs, Minivans, https://www.caranddriver.com/features/a38873223/2022-editors-choice/, Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,...], [Best Cars of 2023 - Rankings and Reviews - Forbes Wheels, https://www.forbes.com/wheels/best/cars/, 1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn't changed much for 2023 but it doesn't have to. Practical, stylish and fun, it's the best overall value in its class.......], [U.S. News' Best Cars of 2021 | U.S. News - U.S. News & World Report, https://cars.usnews.com/cars-trucks/advice/best-cars, Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an...], [Best Cars of 2023 & 2024 - Top-Rated New Cars Ranked | KBB.com, https://www.kbb.com/cars/, Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota...], [Best Cars, SUVs, and Trucks for 2023 - Consumer Reports, https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/, Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings & Reviews Ratings & Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars...]]} +Human Feedback: GENERATE NEXT COMMAND JSON +Assistant reply: {"thoughts":{"reasoning":"I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.","speak":"I will extract the relevant information from the search results.","text":"I will extract the relevant information from the search results.","criticism":"N/A","plan":"- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"question":"best cars","url":"https://cars.usnews.com/cars-trucks/rankings"},"name":"browser"}} +Result: {links=[{text=, href=https://www.usnews.com}, {text=Cars, href=/cars-trucks}, {text=New Cars, href=/cars-trucks/browse}, {text=New Cars for Sale, href=/cars-trucks/new-cars/for-sale}, {text=Research Cars, href=/cars-trucks/browse}], text=The text does not provide any information about "best cars." +According to the provided text, the "best cars" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more.} +Human Feedback: GENERATE NEXT COMMAND JSON + +role: system +content: Response from browser: +{"links":[{"text":"","href":"https://www.usnews.com"},{"text":"Cars","href":"/cars-trucks"},{"text":"New Cars","href":"/cars-trucks/browse"},{"text":"New Cars for Sale","href":"/cars-trucks/new-cars/for-sale"},{"text":"Research Cars","href":"/cars-trucks/browse"}],"text":"The text does not provide any information about \"best cars.\"\nAccording to the provided text, the \"best cars\" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more."} +role: user +content: GENERATE NEXT COMMAND JSON +role: assistant +content: { + "thoughts": { + "reasoning": "I need to start by searching for the best cars on Google.", + "speak": "I will search for the best cars on Google.", + "text": "I will search for the best cars on Google.", + "criticism": "N/A", + "plan": "- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "query": "best cars" + }, + "name": "google_search" + } +} +role: system +content: Response from google_search: +{"results":[["Best Cars for 2023 and 2024 | U.S. News","https://cars.usnews.com/cars-trucks/rankings","#1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks..."],["Best Cars, Best Trucks, and Best SUVs | U.S. News \u0026 World Report","https://cars.usnews.com/","Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars..."],["Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds","https://www.edmunds.com/best-cars/","Top Rated SUV 2020 Kia Telluride \"Other SUVs may excel in certain areas, but none is as comprehensively accomplished.\" See rankings Pricing \u0026 reviews Best SUV Articles Best 3-Row SUVs Fastest..."],["2022 Editors\u0027 Choice: The Best New Cars, Trucks, SUVs, Minivans","https://www.caranddriver.com/features/a38873223/2022-editors-choice/","Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,..."],["Best Cars of 2023 - Rankings and Reviews - Forbes Wheels","https://www.forbes.com/wheels/best/cars/","1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn\u0027t changed much for 2023 but it doesn\u0027t have to. Practical, stylish and fun, it\u0027s the best overall value in its class......."],["U.S. News\u0027 Best Cars of 2021 | U.S. News - U.S. News \u0026 World Report","https://cars.usnews.com/cars-trucks/advice/best-cars","Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an..."],["Best Cars of 2023 \u0026 2024 - Top-Rated New Cars Ranked | KBB.com","https://www.kbb.com/cars/","Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota..."],["Best Cars, SUVs, and Trucks for 2023 - Consumer Reports","https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/","Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings \u0026 Reviews Ratings \u0026 Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars..."]]} +role: system +content: The current time and date is Sat Sep 09 12:59:38 2023. +role: user +content: GENERATE NEXT COMMAND JSON + +--response-- +{ + "thoughts": { + "reasoning": "I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.", + "speak": "I will extract the relevant information from the search results.", + "text": "I will extract the relevant information from the search results.", + "criticism": "N/A", + "plan": "- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "question": "best cars", + "url": "https://cars.usnews.com/cars-trucks/rankings" + }, + "name": "browser" + } +} +--prompt-- +role: system +content: You are Shop assistant, an AI assistant that researches and finds the best car. Your decisions must always be made independently without seeking user assistance.Play to your strengths as an LLM and pursue simple strategies with no legal complications. +GOALS: +1. Search for the car on Google +2. Write the list of the top 5 best cars and their prices to a file +3. Summarize the pros and cons of each car and write it to a different file called 'cars-research.txt' +4. There will be no user assistance. Terminate once writing both files is complete. + +Constraints:~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.No user assistanceExclusively use a single command listed in double quotes e.g. "command_name" +Commands: +1. {"args":{"question":"The question","url":"URL of the website to scrape"},"response_format":{"links":"list of links from the website, where each item is in the form `[link_text,link_url]`","text":"Summary of relevant text scraped from the website"},"name":"browser","description":"Scrape answers for a question in a given web page"} +2. {"args":{"query":"The query to search for"},"response_format":{"results":"A list of results. Each result is of the form [title, link, description]"},"name":"google_search","description":"Google Search"} +3. {"args":{},"response_format":{"success":"true"},"name":"task_complete","description":"Execute this command when all given tasks are completed."} + +Resources:1. Internet access for searches and information gathering.2. Long Term memory management.3. GPT-3.5 powered Agents for delegation of simple tasks. +Continuously review and analyze your actions to ensure you are performing to the best of your abilities. +Constructively self-criticize your big-picture behavior constantly. +Reflect on past decisions and strategies to refine your approach. +Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps. + +You should only respond in JSON format as described below. 'thoughts' section is always required., +Response Format: +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} +Ensure the response can be parsed by Java JSON ObjectMapper + + + +role: system +content: This reminds you of these events from your past: + Assistant reply: {"thoughts":{"reasoning":"I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.","speak":"I will extract the relevant information from the search results.","text":"I will extract the relevant information from the search results.","criticism":"N/A","plan":"- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"question":"best cars","url":"https://cars.usnews.com/cars-trucks/rankings"},"name":"browser"}} +Result: {links=[{text=, href=https://www.usnews.com}, {text=Cars, href=/cars-trucks}, {text=New Cars, href=/cars-trucks/browse}, {text=New Cars for Sale, href=/cars-trucks/new-cars/for-sale}, {text=Research Cars, href=/cars-trucks/browse}], text=The provided text does not mention anything about "best cars" or provide any relevant information regarding that topic. +According to the provided text, the best cars for 2023 and 2024 are listed in different categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, hybrid cars, and electric cars. The text provides rankings for each category and mentions specific models that are considered the best in their respective categories.} +Human Feedback: GENERATE NEXT COMMAND JSON +Assistant reply: {"thoughts":{"reasoning":"I need to start by searching for the best cars on Google.","speak":"I will search for the best cars on Google.","text":"I will search for the best cars on Google.","criticism":"N/A","plan":"- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"query":"best cars"},"name":"google_search"}} +Result: {results=[[Best Cars for 2023 and 2024 | U.S. News, https://cars.usnews.com/cars-trucks/rankings, #1 2024 Acura Integra #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Hatchbacks...], [Best Cars, Best Trucks, and Best SUVs | U.S. News & World Report, https://cars.usnews.com/, Find out which cars are #1 in our rankings of best cars, read the latest car reviews, find the best deals and use our shopping tools to find your next car. Cars New Cars New Cars...], [Best Cars - Top Rated Cars, Trucks and SUVs for 2019 - 2020 - Edmunds, https://www.edmunds.com/best-cars/, Top Rated SUV 2020 Kia Telluride "Other SUVs may excel in certain areas, but none is as comprehensively accomplished." See rankings Pricing & reviews Best SUV Articles Best 3-Row SUVs Fastest...], [2022 Editors' Choice: The Best New Cars, Trucks, SUVs, Minivans, https://www.caranddriver.com/features/a38873223/2022-editors-choice/, Subcompact SUV Hyundai Kona Review, Pricing, and Specs HIGHS: Cheeky design, gutsy optional turbo engine, plentiful standard features. LOWS: Not particularly cargo friendly, vague steering feel,...], [Best Cars of 2023 - Rankings and Reviews - Forbes Wheels, https://www.forbes.com/wheels/best/cars/, 1 out of 100 90 Honda Civic Redesigned last year, the Honda Civic hasn't changed much for 2023 but it doesn't have to. Practical, stylish and fun, it's the best overall value in its class.......], [U.S. News' Best Cars of 2021 | U.S. News - U.S. News & World Report, https://cars.usnews.com/cars-trucks/advice/best-cars, Credit Best SUV: 2021 Honda CR-V U.S. News Overall Score: 8.7/10 | Price: $25,350 A perennial leader of a remarkably competitive segment, the Honda CR-V is our best SUV of 2021. Boasting an...], [Best Cars of 2023 & 2024 - Top-Rated New Cars Ranked | KBB.com, https://www.kbb.com/cars/, Expert Rating The Honda Civic is our highest-rated compact car. It boasts a legendary reputation and enough variety to attract a wide range of drivers. #2 2023 Hyundai Elantra #3 2024 Toyota...], [Best Cars, SUVs, and Trucks for 2023 - Consumer Reports, https://www.consumerreports.org/cars/best-cars-suvs-autos-spotlight/, Best Cars, SUVs, and Trucks for 2023 - Consumer Reports - Consumer Reports Become a Member Cars Car Ratings & Reviews Ratings & Reviews SUVs Hybrids/EVs Luxury Cars Sedans Small Cars...]]} +Human Feedback: GENERATE NEXT COMMAND JSON +Assistant reply: {"thoughts":{"reasoning":"I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.","speak":"I will extract the relevant information from the search results.","text":"I will extract the relevant information from the search results.","criticism":"N/A","plan":"- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program"},"command":{"args":{"question":"best cars","url":"https://cars.usnews.com/cars-trucks/rankings"},"name":"browser"}} +Result: {links=[{text=, href=https://www.usnews.com}, {text=Cars, href=/cars-trucks}, {text=New Cars, href=/cars-trucks/browse}, {text=New Cars for Sale, href=/cars-trucks/new-cars/for-sale}, {text=Research Cars, href=/cars-trucks/browse}], text=The text does not provide any information about "best cars." +According to the provided text, the "best cars" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more.} +Human Feedback: GENERATE NEXT COMMAND JSON + +role: user +content: GENERATE NEXT COMMAND JSON +role: assistant +content: { + "thoughts": { + "reasoning": "I have obtained the search results for the best cars. Now I need to extract the relevant information from the results.", + "speak": "I will extract the relevant information from the search results.", + "text": "I will extract the relevant information from the search results.", + "criticism": "N/A", + "plan": "- Extract the relevant information from the search results\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "question": "best cars", + "url": "https://cars.usnews.com/cars-trucks/rankings" + }, + "name": "browser" + } +} +role: system +content: Response from browser: +{"links":[{"text":"","href":"https://www.usnews.com"},{"text":"Cars","href":"/cars-trucks"},{"text":"New Cars","href":"/cars-trucks/browse"},{"text":"New Cars for Sale","href":"/cars-trucks/new-cars/for-sale"},{"text":"Research Cars","href":"/cars-trucks/browse"}],"text":"The provided text does not mention anything about \"best cars\" or provide any relevant information regarding that topic.\nAccording to the provided text, the best cars for 2023 and 2024 are listed in different categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, hybrid cars, and electric cars. The text provides rankings for each category and mentions specific models that are considered the best in their respective categories."} +role: system +content: The current time and date is Sat Sep 09 12:59:56 2023. +role: user +content: GENERATE NEXT COMMAND JSON + +--response-- +{ + "thoughts": { + "reasoning": "I need to start by searching for the best cars on Google.", + "speak": "I will search for the best cars on Google.", + "text": "I will search for the best cars on Google.", + "criticism": "N/A", + "plan": "- Search for the best cars on Google\n- Write the list of top 5 cars and their prices to a file\n- Summarize the pros and cons of each car and write it to another file\n- Terminate the program" + }, + "command": { + "args": { + "query": "best cars" + }, + "name": "google_search" + } +} \ No newline at end of file diff --git a/chat-logs/examples.ExampleSearch/summary.log b/chat-logs/examples.ExampleSearch/summary.log new file mode 100644 index 0000000..5c579e0 --- /dev/null +++ b/chat-logs/examples.ExampleSearch/summary.log @@ -0,0 +1,17 @@ + +--prompt-- +{"role": "user", "content": """""" Using the above text, please answer the following question: "best cars" -- if the question cannot be answered using the text, please summarize the text."} +--response-- +The text does not provide any information about "best cars." +--prompt-- +{"role": "user", "content": """Best Cars for 2023 and 2024 | U.S. News Cars New Cars New Cars for Sale Research Cars Best Price Program New Car Rankings Car Deals This Month Compare Cars Calculate Car Payment Used Cars Used Cars for Sale Certified Pre-Owned Cars for Sale Used Car Rankings Used Car Deals This Month Compare Used Cars Calculate Used Car Payment Car Rankings New Car Rankings Used Car Rankings Best Cars for the Money Best Cars for Families Best Vehicle Brands Cars for Sale New Cars for Sale Used Cars for Sale Certified Pre-Owned Cars for Sale Electric Vehicles Advice Advice Features Car Insurance Loans & Leasing Motorcycles ATVs UTVs Best Car Deals New Car Deals Used Car Deals Lease Car Deals Sell Your Car Car Selling Advice Get Instant Cash Offer AcuraAlfa RomeoAston MartinAudiBMWBuickCadillacChevroletChryslerDodgeFerrariFIATFordGenesisGMCHondaHUMMERHyundaiInfinitiIsuzuJaguarJeepKiaLamborghiniLand RoverLexusLincolnLotusMaseratiMazdaMercedes-BenzMercuryMINIMitsubishiNissanPontiacPorscheRamSaabSaturnScionSmartSubaruSuzukiTeslaToyotaVolkswagenVolvoMake Model Year Sign In Cars Rankings Cars Best Cars for 2023 and 2024 Find the best cars then compare models and read our car reviews, which provide the consensus opinion from the automotive press. You can also view new car prices in your area. Read how we rank new cars New Car Rankings Used Car Rankings Best Cars for the Money Best Car for Families Best Vehicle Brands New Car Rankings Used Car Rankings Best Cars for the Money Best Car for Families Best Vehicle Brands Cars SUVs Trucks Vans Hybrids Electric Small Cars Small Cars #1 2023 Honda Civic Type R #2 2024 Acura Integra #3 2023 Honda Civic See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Advertisement Hatchbacks #1 2023 Honda Civic Type R #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Compact Cars #1 2023 Honda Civic #2 2023 Mazda Mazda3 #3 2023 Hyundai Elantra See full rankings Subcompact Cars #1 2024 MINI Cooper #2 2023 Kia Rio #3 2023 Nissan Versa See full rankings Advertisement Midsize Cars Midsize Cars #1 2023 Honda Accord #2 2023 Kia K5 #3 2023 Toyota Camry See full rankings Luxury Midsize Cars #1 2023 Mercedes-Benz E-Class #2 2023 BMW 5-Series #3 2023 Genesis G80 See full rankings Large Cars Large Cars #1 2023 Dodge Charger #2 2023 Nissan Maxima #3 2023 Chrysler 300 See full rankings Luxury Large Cars #1 2023 Genesis G90 #2 2023 Audi A7 #3 2023 Mercedes-Benz S-Class See full rankings Advertisement Sports Cars Sports Cars #1 2023 Subaru BRZ #2 2024 Toyota GR86 #3 2024 Ford Mustang See full rankings Luxury Sports Cars #1 2023 Chevrolet Corvette #2 2023 Audi R8 #3 2023 Porsche 911 See full rankings Advertisement Performance Cars Sport Compact Cars #1 2023 Honda Civic Type R #2 2023 Hyundai Elantra N #3 2023 Volkswagen GTI See full rankings Small Sport Sedans #1 2024 Acura Integra Type S #2 2023 Cadillac CT4-V Blackwing #3 2023 Audi S5 See full rankings Midsize Sport Sedans #1 2023 Cadillac CT5-V Blackwing #2 2023 Audi S6 #2 2023 BMW M5 See full rankings Large Sport Sedans #1 2023 Audi S8 #2 2023 Audi RS 7 #3 2023 Audi S7 See full rankings Convertibles Convertibles #1 2024 Ford Mustang #1 2023 Mazda MX-5 Miata #3 2024 Chevrolet Camaro See full rankings Luxury Convertibles #1 2023 Chevrolet Corvette #2 2023 Porsche 911 #2 2023 Porsche Boxster See full rankings Wagons Wagons #1 2023 Audi A6 Allroad #2 2023 Volvo V60 #3 2023 Audi A4 Allroad See full rankings Hybrid Cars Hybrid Cars #1 2023 Honda Accord Hybrid #1 2023 Hyundai Sonata Hybrid #3 2023 Toyota Camry Hybrid See all Hybrid Cars Advertisement Advertisement Browse Cars Small Cars Midsize Cars Large Cars SUVs Crossovers Trucks Hybrids Vans Electric Luxury Sports Cars Convertibles Browse all models Advertisement Advertisement New Cars New Cars for Sale Research Cars Best Price Program New Car Rankings Car Deals This Month Compare Cars Calculate Car Payment Used Cars Used Cars for Sale Certified Pre-Owned Cars for Sale Used Car Rankings Insurance Cheapest Car Insurance Companies Best Car Insurance Companies Car Rankings New Car Rankings Used Car Rankings Best Cars for the Money Best Cars for Families Best Vehicle Brands Advice Best Car Deals New Car Deals Used Car Deals Lease Car Deals How We Rank New Cars Used Cars Cars for Sale New Cars for Sale Used Cars for Sale Certified Pre-Owned Cars for Sale Stock photography by izmostock. © 1986 - 2023 Autodata, Inc. dba Chrome Data New Cars Used Cars Insurance Car Rankings Advice Best Car Deals How We Rank Cars for Sale Stock photography by izmostock. © 1986 - 2023 Autodata, Inc. dba Chrome Data About U.S. News Contact Press Advertise Newsletters Jobs Site Map Store Copyright 2023 © U.S. News & World Report L.P.Terms & Conditions/Privacy Policy and Cookie Notice/US State Privacy Notice/Your Privacy Choices California Consumer Privacy Act (CCPA) Opt-Out Icon""" Using the above text, please answer the following question: "best cars" -- if the question cannot be answered using the text, please summarize the text."} +--response-- +According to the provided text, the "best cars" for 2023 and 2024 are listed in various categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, and hybrid cars. The rankings include popular models like the Honda Civic, Acura Integra, Audi A4, Mercedes-Benz E-Class, Dodge Charger, Genesis G90, Subaru BRZ, Chevrolet Corvette, Honda Accord Hybrid, and many more. +--prompt-- +{"role": "user", "content": """""" Using the above text, please answer the following question: "best cars" -- if the question cannot be answered using the text, please summarize the text."} +--response-- +The provided text does not mention anything about "best cars" or provide any relevant information regarding that topic. +--prompt-- +{"role": "user", "content": """Best Cars for 2023 and 2024 | U.S. News Cars New Cars New Cars for Sale Research Cars Best Price Program New Car Rankings Car Deals This Month Compare Cars Calculate Car Payment Used Cars Used Cars for Sale Certified Pre-Owned Cars for Sale Used Car Rankings Used Car Deals This Month Compare Used Cars Calculate Used Car Payment Car Rankings New Car Rankings Used Car Rankings Best Cars for the Money Best Cars for Families Best Vehicle Brands Cars for Sale New Cars for Sale Used Cars for Sale Certified Pre-Owned Cars for Sale Electric Vehicles Advice Advice Features Car Insurance Loans & Leasing Motorcycles ATVs UTVs Best Car Deals New Car Deals Used Car Deals Lease Car Deals Sell Your Car Car Selling Advice Get Instant Cash Offer AcuraAlfa RomeoAston MartinAudiBMWBuickCadillacChevroletChryslerDodgeFerrariFIATFordGenesisGMCHondaHUMMERHyundaiInfinitiIsuzuJaguarJeepKiaLamborghiniLand RoverLexusLincolnLotusMaseratiMazdaMercedes-BenzMercuryMINIMitsubishiNissanPontiacPorscheRamSaabSaturnScionSmartSubaruSuzukiTeslaToyotaVolkswagenVolvoMake Model Year Sign In Cars Rankings Cars Best Cars for 2023 and 2024 Find the best cars then compare models and read our car reviews, which provide the consensus opinion from the automotive press. You can also view new car prices in your area. Read how we rank new cars New Car Rankings Used Car Rankings Best Cars for the Money Best Car for Families Best Vehicle Brands New Car Rankings Used Car Rankings Best Cars for the Money Best Car for Families Best Vehicle Brands Cars SUVs Trucks Vans Hybrids Electric Small Cars Small Cars #1 2023 Honda Civic Type R #2 2024 Acura Integra #3 2023 Honda Civic See full rankings Luxury Small Cars #1 2024 Acura Integra #2 2023 Audi A4 #2 2023 Mercedes-Benz C-Class See full rankings Advertisement Hatchbacks #1 2023 Honda Civic Type R #2 2023 Honda Civic #3 2023 Mazda Mazda3 See full rankings Compact Cars #1 2023 Honda Civic #2 2023 Mazda Mazda3 #3 2023 Hyundai Elantra See full rankings Subcompact Cars #1 2024 MINI Cooper #2 2023 Kia Rio #3 2023 Nissan Versa See full rankings Advertisement Midsize Cars Midsize Cars #1 2023 Honda Accord #2 2023 Kia K5 #3 2023 Toyota Camry See full rankings Luxury Midsize Cars #1 2023 Mercedes-Benz E-Class #2 2023 BMW 5-Series #3 2023 Genesis G80 See full rankings Large Cars Large Cars #1 2023 Dodge Charger #2 2023 Nissan Maxima #3 2023 Chrysler 300 See full rankings Luxury Large Cars #1 2023 Genesis G90 #2 2023 Audi A7 #3 2023 Mercedes-Benz S-Class See full rankings Advertisement Sports Cars Sports Cars #1 2023 Subaru BRZ #2 2024 Toyota GR86 #3 2024 Ford Mustang See full rankings Luxury Sports Cars #1 2023 Chevrolet Corvette #2 2023 Audi R8 #3 2023 Porsche 911 See full rankings Advertisement Performance Cars Sport Compact Cars #1 2023 Honda Civic Type R #2 2023 Hyundai Elantra N #3 2023 Volkswagen GTI See full rankings Small Sport Sedans #1 2024 Acura Integra Type S #2 2023 Cadillac CT4-V Blackwing #3 2023 Audi S5 See full rankings Midsize Sport Sedans #1 2023 Cadillac CT5-V Blackwing #2 2023 Audi S6 #2 2023 BMW M5 See full rankings Large Sport Sedans #1 2023 Audi S8 #2 2023 Audi RS 7 #3 2023 Audi S7 See full rankings Convertibles Convertibles #1 2024 Ford Mustang #1 2023 Mazda MX-5 Miata #3 2024 Chevrolet Camaro See full rankings Luxury Convertibles #1 2023 Chevrolet Corvette #2 2023 Porsche 911 #2 2023 Porsche Boxster See full rankings Wagons Wagons #1 2023 Audi A6 Allroad #2 2023 Volvo V60 #3 2023 Audi A4 Allroad See full rankings Hybrid Cars Hybrid Cars #1 2023 Honda Accord Hybrid #1 2023 Hyundai Sonata Hybrid #3 2023 Toyota Camry Hybrid See all Hybrid Cars Advertisement Advertisement Browse Cars Small Cars Midsize Cars Large Cars SUVs Crossovers Trucks Hybrids Vans Electric Luxury Sports Cars Convertibles Browse all models Advertisement Advertisement New Cars New Cars for Sale Research Cars Best Price Program New Car Rankings Car Deals This Month Compare Cars Calculate Car Payment Used Cars Used Cars for Sale Certified Pre-Owned Cars for Sale Used Car Rankings Insurance Cheapest Car Insurance Companies Best Car Insurance Companies Car Rankings New Car Rankings Used Car Rankings Best Cars for the Money Best Cars for Families Best Vehicle Brands Advice Best Car Deals New Car Deals Used Car Deals Lease Car Deals How We Rank New Cars Used Cars Cars for Sale New Cars for Sale Used Cars for Sale Certified Pre-Owned Cars for Sale Stock photography by izmostock. © 1986 - 2023 Autodata, Inc. dba Chrome Data New Cars Used Cars Insurance Car Rankings Advice Best Car Deals How We Rank Cars for Sale Stock photography by izmostock. © 1986 - 2023 Autodata, Inc. dba Chrome Data About U.S. News Contact Press Advertise Newsletters Jobs Site Map Store Copyright 2023 © U.S. News & World Report L.P.Terms & Conditions/Privacy Policy and Cookie Notice/US State Privacy Notice/Your Privacy Choices California Consumer Privacy Act (CCPA) Opt-Out Icon""" Using the above text, please answer the following question: "best cars" -- if the question cannot be answered using the text, please summarize the text."} +--response-- +According to the provided text, the best cars for 2023 and 2024 are listed in different categories such as small cars, luxury small cars, hatchbacks, compact cars, subcompact cars, midsize cars, luxury midsize cars, large cars, luxury large cars, sports cars, luxury sports cars, performance cars, convertibles, wagons, hybrid cars, and electric cars. The text provides rankings for each category and mentions specific models that are considered the best in their respective categories. \ No newline at end of file diff --git a/examples/src/main/java/examples/ExampleSearch.java b/examples/src/main/java/examples/ExampleSearch.java index fc116ad..5ef17d5 100644 --- a/examples/src/main/java/examples/ExampleSearch.java +++ b/examples/src/main/java/examples/ExampleSearch.java @@ -18,9 +18,7 @@ public static void main(String[] args) { goals.add("There will be no user assistance. Terminate once writing both files is complete."); Agent agent = new Agent(name, description, goals, "gpt-3.5-turbo"); - agent.cli(); - } } diff --git a/lib/src/main/java/com/frazik/instructgpt/Agent.java b/lib/src/main/java/com/frazik/instructgpt/Agent.java index 6ef809e..d1ef17e 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Agent.java +++ b/lib/src/main/java/com/frazik/instructgpt/Agent.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.type.TypeReference; import com.frazik.instructgpt.auto.Cli; -import com.frazik.instructgpt.embedding.OpenAIEmbeddingProvider; import com.frazik.instructgpt.memory.LocalMemory; +import com.frazik.instructgpt.models.Model; import com.frazik.instructgpt.models.OpenAIModel; import com.frazik.instructgpt.prompts.Prompt; import com.frazik.instructgpt.prompts.PromptHistory; @@ -30,7 +30,7 @@ public class Agent { private final List tools; private Map stagingTool; private JsonNode stagingResponse; - private final OpenAIModel openAIModel; + private final Model openAIModel; private static final ObjectMapper mapper = new ObjectMapper(); public Agent(String name, String description, List goals, String model) { this.history = new PromptHistory(); @@ -180,11 +180,9 @@ public Response chat(String message, boolean runTool) { this.stagingResponse = null; } List> fullPrompt = this.getFullPrompt(message); - int tokenCount = openAIModel.countTokens(fullPrompt); - int tokenLimit = openAIModel.getTokenLimit(); - String resp = openAIModel.chat(fullPrompt, tokenLimit - tokenCount); + String resp = openAIModel.chat(fullPrompt); System.out.println("========="); - System.out.println(resp); + System.out.println("RESPONSE FINISHED"); System.out.println("========="); this.history.addNewPrompt("user", message); this.history.addNewPrompt("assistant", resp); diff --git a/lib/src/main/java/com/frazik/instructgpt/Summarizer.java b/lib/src/main/java/com/frazik/instructgpt/Summarizer.java index 1b66515..81d66d1 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Summarizer.java +++ b/lib/src/main/java/com/frazik/instructgpt/Summarizer.java @@ -4,29 +4,29 @@ Adapted from Auto-GPT (https://github.com/Significant-Gravitas/Auto-GPT) */ +import com.frazik.instructgpt.models.Model; import com.frazik.instructgpt.models.OpenAIModel; import java.util.ArrayList; import java.util.List; public class Summarizer { - private String model; - private OpenAIModel openAIModel; + private Model model; public Summarizer(String model) { - this.model = model; + this.model = new OpenAIModel(model); } public String summarize(String text, String query) { List summaries = new ArrayList<>(); for (String chunk : chunkText(text)) { - summaries.add(chat(new String[]{prompt(chunk, query)}, 300)); + summaries.add(chat(new String[]{prompt(chunk, query)})); } String summary = String.join("\n", summaries); while (summary.length() > Math.pow(2, 13)) { summaries = new ArrayList<>(); for (String chunk : chunkText(summary)) { - summaries.add(chat(new String[]{prompt(chunk, query)}, 300)); + summaries.add(chat(new String[]{prompt(chunk, query)})); } summary = String.join("\n", summaries); } @@ -64,8 +64,8 @@ private String prompt(String text, String query) { + "\" -- if the question cannot be answered using the text, please summarize the text.\"}"; } - private String chat(String[] prompts, int maxTokens) { - return openAIModel.chat(prompts); + private String chat(String[] prompts) { + return model.summarize(prompts); } } diff --git a/lib/src/main/java/com/frazik/instructgpt/auto/Cli.java b/lib/src/main/java/com/frazik/instructgpt/auto/Cli.java index ca737cb..fc638a0 100644 --- a/lib/src/main/java/com/frazik/instructgpt/auto/Cli.java +++ b/lib/src/main/java/com/frazik/instructgpt/auto/Cli.java @@ -41,20 +41,19 @@ public void run() { } if (resp.hasCommand()) { System.out.println("Agent wants to execute the following command: \n" + resp.getCommand()); - while (true) { + String yn = ""; + do { System.out.print("(Y/N)? "); - String yn = scanner.nextLine().toLowerCase().trim(); - if ("y".equals(yn) || "n".equals(yn)) { - if ("y".equals(yn)) { - resp = agent.chat("GENERATE NEXT COMMAND JSON", true); - } else { - System.out.print("Enter feedback (Why not execute the command?): "); - String feedback = scanner.nextLine(); - resp = agent.chat(feedback, false); - } - break; - } + yn = scanner.nextLine().toLowerCase().trim(); + } while (!"y".equals(yn) && !"n".equals(yn)); + if ("y".equals(yn)) { + resp = agent.chat("GENERATE NEXT COMMAND JSON", true); + } else { + System.out.print("Enter feedback (Why not execute the command?): "); + String feedback = scanner.nextLine(); + resp = agent.chat(feedback, false); } + continue; } System.out.print("Enter message: "); String inp = scanner.nextLine(); diff --git a/lib/src/main/java/com/frazik/instructgpt/logging/ChatLogger.java b/lib/src/main/java/com/frazik/instructgpt/logging/ChatLogger.java new file mode 100644 index 0000000..9b05e7d --- /dev/null +++ b/lib/src/main/java/com/frazik/instructgpt/logging/ChatLogger.java @@ -0,0 +1,70 @@ +package com.frazik.instructgpt.logging; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +@SuppressWarnings("ResultOfMethodCallIgnored") +@Slf4j +public class ChatLogger { + + private final File currentFolder; + private final File promptFile; + private final File summaryFile; + public ChatLogger() { + this.currentFolder = new File("chat-logs/" + System.getProperty("sun.java.command")); + this.promptFile = new File(currentFolder, "prompt.log"); + this.summaryFile = new File(currentFolder, "summary.log"); + if (promptFile.exists()) { + promptFile.delete(); + } + if (summaryFile.exists()) { + summaryFile.delete(); + } + if (!currentFolder.exists()) { + currentFolder.mkdirs(); + } + } + public void write(List> fullPrompt, String response) { + try { + FileUtils.write(promptFile, "\n--prompt--\n", "UTF-8", true); + for (Map prompt : fullPrompt) { + for (Map.Entry entry : prompt.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + FileUtils.write(promptFile, key + ": " + value + "\n", "UTF-8", true); + } + } + FileUtils.write(promptFile, "\n--response--\n", "UTF-8", true); + FileUtils.write(promptFile, response, "UTF-8", true); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void write(String[] prompts, String response) { + try { + FileUtils.write(summaryFile, "\n--prompt--\n", "UTF-8", true); + for (String prompt : prompts) { + FileUtils.write(summaryFile, prompt, "UTF-8", true); + } + FileUtils.write(summaryFile, "\n--response--\n", "UTF-8", true); + // Write response to response.log + FileUtils.write(summaryFile, response, "UTF-8", true); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private File getAndInitialize(String x) { + File promptFile = new File(currentFolder, x + ".log"); + if (promptFile.exists()) { + promptFile.delete(); + } + return promptFile; + } + +} diff --git a/lib/src/main/java/com/frazik/instructgpt/models/Model.java b/lib/src/main/java/com/frazik/instructgpt/models/Model.java index b0b3dc7..c1815b6 100644 --- a/lib/src/main/java/com/frazik/instructgpt/models/Model.java +++ b/lib/src/main/java/com/frazik/instructgpt/models/Model.java @@ -1,14 +1,36 @@ package com.frazik.instructgpt.models; +import com.frazik.instructgpt.logging.ChatLogger; import com.theokanning.openai.completion.chat.ChatMessage; +import java.util.ArrayList; import java.util.List; import java.util.Map; public abstract class Model { - public abstract String chat(List messages, Integer maxTokens, Double temperature); + private final ChatLogger chatLogger = new ChatLogger(); public abstract int countTokens(List> messages); public abstract int getTokenLimit(); -} + + public abstract String chat(List> messages, Integer maxTokens); + + public String chat(List> messages) { + int tokenCount = countTokens(messages); + int tokenLimit = getTokenLimit(); + String chatResult = chat(messages, tokenLimit - tokenCount); + chatLogger.write(messages, chatResult); + return chatResult; + } + + public abstract String summarize(String[] prompts, Integer maxTokens); + + public String summarize(String[] prompts) { + String summarizeResults = summarize(prompts, 150); + chatLogger.write(prompts, summarizeResults); + return summarizeResults; + } + + +} \ No newline at end of file diff --git a/lib/src/main/java/com/frazik/instructgpt/models/OpenAIModel.java b/lib/src/main/java/com/frazik/instructgpt/models/OpenAIModel.java index 9069ffa..bd8d667 100644 --- a/lib/src/main/java/com/frazik/instructgpt/models/OpenAIModel.java +++ b/lib/src/main/java/com/frazik/instructgpt/models/OpenAIModel.java @@ -37,21 +37,21 @@ private static List toChatMessages(List> prompt } return chatMessages; } - + @Override public String chat(List> messages, Integer maxTokens) { - return chat(toChatMessages(messages), maxTokens, 0.8); + return summarize(toChatMessages(messages), maxTokens, 0.8); } - public String chat(String[] prompts) { + @Override + public String summarize(String[] prompts, Integer maxTokens) { List chatMessages = new ArrayList<>(); for (String prompt : prompts) { chatMessages.add(new ChatMessage("user", prompt)); } - return chat(chatMessages, 100, 0.8); + return summarize(chatMessages, maxTokens, 0.8); } - @Override - public String chat(List messages, Integer maxTokens, Double temperature) { + public String summarize(List messages, Integer maxTokens, Double temperature) { OpenAiService openAiService = new OpenAiService(apiKey, Duration.ofSeconds(55)); int numRetries = 3; diff --git a/lib/src/main/java/com/frazik/instructgpt/prompts/FullPrompt.java b/lib/src/main/java/com/frazik/instructgpt/prompts/FullPrompt.java new file mode 100644 index 0000000..6a87847 --- /dev/null +++ b/lib/src/main/java/com/frazik/instructgpt/prompts/FullPrompt.java @@ -0,0 +1,20 @@ +package com.frazik.instructgpt.prompts; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; + + +@Getter +@Setter +public class FullPrompt { + + Map prompt; + + public FullPrompt(Map prompt) { + this.prompt = prompt; + } + +} diff --git a/lib/src/main/java/com/frazik/instructgpt/tools/Browser.java b/lib/src/main/java/com/frazik/instructgpt/tools/Browser.java index c04fe5e..f4579a1 100644 --- a/lib/src/main/java/com/frazik/instructgpt/tools/Browser.java +++ b/lib/src/main/java/com/frazik/instructgpt/tools/Browser.java @@ -31,7 +31,7 @@ public Browser() { options = new ChromeOptions(); options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.49 Safari/537.36"); // options.setHeadless(true); - summarizer = new Summarizer("model"); + summarizer = new Summarizer("gpt-3.5-turbo"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { close(); @@ -96,11 +96,6 @@ public Map getArgs() { return args; } - @Override - public Map run(Map kwargs) { - return null; - } - @Override public Map getResp() { Map resp = new HashMap(); @@ -119,7 +114,9 @@ public void close() { } } - public Map run(String url, String question) { + @Override + public Map run(Map args) { + String url = args.get("url"); Map result = new HashMap<>(); Document doc = null; try { @@ -150,6 +147,7 @@ public Map run(String url, String question) { } } String extractedText = String.join("\n", chunks); + String question = args.get("question"); String summary = this.summarizer.summarize(extractedText, question); result.put("text", summary); result.put("links", extractedLinks); diff --git a/lib/src/main/java/com/frazik/instructgpt/tools/GoogleSearch.java b/lib/src/main/java/com/frazik/instructgpt/tools/GoogleSearch.java index adb92c0..8581b91 100644 --- a/lib/src/main/java/com/frazik/instructgpt/tools/GoogleSearch.java +++ b/lib/src/main/java/com/frazik/instructgpt/tools/GoogleSearch.java @@ -4,11 +4,13 @@ import com.google.api.services.customsearch.v1.CustomsearchRequestInitializer; import com.google.api.services.customsearch.v1.model.Result; import com.google.api.services.customsearch.v1.model.Search; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.util.*; public class GoogleSearch extends Tool { private final String googleApiKey = System.getenv("GOOGLE_API_KEY"); @@ -64,10 +66,39 @@ public Map run(Map args) { if (googleApiKey != null && !googleApiKey.trim().isEmpty() && !googleApiKey.equals("your-google-api-key")) { result.put("results", googleSearch(query, numResults)); } else { - //result.put("results", duckduckgoSearch(query, numResults)); + result.put("results", duckduckgoSearch(query, numResults)); } return result; } + private final static String DUCKDUCKGO_SEARCH_URL = "https://duckduckgo.com/html/?q="; + public static List> duckduckgoSearch(String query, int numResults) { + try { + Document doc = Jsoup.connect(DUCKDUCKGO_SEARCH_URL + query).get(); + Elements results = Objects.requireNonNull(doc.getElementById("links")). + getElementsByClass("results_links"); + List> resultList = new ArrayList<>(); + for (int i = 0; i < numResults && i < results.size(); i++) { + Element result = results.get(i); + Element title = Objects.requireNonNull(result.getElementsByClass("links_main").first()). + getElementsByTag("a").first(); + assert title != null; + System.out.println("\nURL:" + title.attr("href")); + System.out.println("Title:" + title.text()); + String snippet = Objects.requireNonNull(result.getElementsByClass("result__snippet").first()). + text(); + List innerList = new ArrayList<>(); + innerList.add(title.text()); + innerList.add(title.attr("href")); + innerList.add(snippet); + resultList.add(innerList); + } + return resultList; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + } diff --git a/lib/src/main/resources/prompts_en.json b/lib/src/main/resources/prompts_en.json index a7316cd..5f8351d 100644 --- a/lib/src/main/resources/prompts_en.json +++ b/lib/src/main/resources/prompts_en.json @@ -55,6 +55,6 @@ "Response from %s:\n%s" ], "use_only_defined_format" : [ - "You should only respond in JSON format as described below \nResponse Format: \n%s\nEnsure the response can be parsed by Java JSON ObjectMapper\n\n" + "You should only respond in JSON format as described below. 'thoughts' section is always required., \nResponse Format: \n%s\nEnsure the response can be parsed by Java JSON ObjectMapper\n\n" ] } diff --git a/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java b/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java index d01428e..9589d27 100644 --- a/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java +++ b/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.*; @@ -31,12 +32,9 @@ void embeddingTest() { @Test void modelTest() { Model model = new OpenAIModel("gpt-3.5-turbo"); - ChatMessage chatMessage = new ChatMessage(); - chatMessage.setRole("assistant"); - chatMessage.setContent("This is a test!"); - List chatMessages = new ArrayList<>(); - chatMessages.add(chatMessage); - String response = model.chat(chatMessages, 100, 0.8); + List> chatMessages = new ArrayList<>(); + chatMessages.add(Map.of("role", "assistant", "content", "This is a test!")); + String response = model.chat(chatMessages, 100); assertTrue(response.length() > 10); }