From 66eb1dcfc5d5b791d7c8718bb4752c93e44b160d Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sat, 8 Apr 2023 12:39:03 +0700 Subject: [PATCH 01/34] Add exec_shell command --- scripts/commands.py | 4 +++- scripts/data/prompt.txt | 3 ++- scripts/execute_code.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/commands.py b/scripts/commands.py index fc10d1d0..187ad6c4 100644 --- a/scripts/commands.py +++ b/scripts/commands.py @@ -7,7 +7,7 @@ import speak from config import Config import ai_functions as ai from file_operations import read_file, write_to_file, append_to_file, delete_file, search_files -from execute_code import execute_python_file +from execute_code import execute_python_file, exec_shell from json_parser import fix_and_parse_json from duckduckgo_search import ddg from googleapiclient.discovery import build @@ -102,6 +102,8 @@ def execute_command(command_name, arguments): return ai.write_tests(arguments["code"], arguments.get("focus")) elif command_name == "execute_python_file": # Add this command return execute_python_file(arguments["file"]) + elif command_name == "exec_shell": # Add this command + return exec_shell(arguments["command_line"]) elif command_name == "task_complete": shutdown() else: diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txt index 28797d9e..e7d0cd82 100644 --- a/scripts/data/prompt.txt +++ b/scripts/data/prompt.txt @@ -22,7 +22,8 @@ COMMANDS: 16. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" 17. Write Tests: "write_tests", args: "code": "", "focus": "" 18. Execute Python File: "execute_python_file", args: "file": "" -19. Task Complete (Shutdown): "task_complete", args: "reason": "" +19. Execute Shell Command: "exec_shell", args: "command_line": "" +20. Task Complete (Shutdown): "task_complete", args: "reason": "" RESOURCES: diff --git a/scripts/execute_code.py b/scripts/execute_code.py index 614ef6fc..5d4f7236 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -1,5 +1,6 @@ import docker import os +import subprocess def execute_python_file(file): @@ -45,3 +46,17 @@ def execute_python_file(file): except Exception as e: return f"Error: {str(e)}" + + + +def exec_shell(command_line): + + args = command_line.split() + + result = subprocess.run(args, capture_output=True) + + output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; + + # print(f"Shell execution complete. Output: {output}") + + return output From 7867c8dc3445b97d684893a64f49cd0eb0270563 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sun, 9 Apr 2023 18:43:20 +0700 Subject: [PATCH 02/34] Update prompt (advise GPT to use only shell commands that terminate) --- scripts/data/prompt.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txt index e7d0cd82..5b139586 100644 --- a/scripts/data/prompt.txt +++ b/scripts/data/prompt.txt @@ -22,7 +22,7 @@ COMMANDS: 16. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" 17. Write Tests: "write_tests", args: "code": "", "focus": "" 18. Execute Python File: "execute_python_file", args: "file": "" -19. Execute Shell Command: "exec_shell", args: "command_line": "" +19. Execute Shell Command: "exec_shell", args: "command_line": "". Remember only to use commands that terminate, interactive tools like vim are not supported! 20. Task Complete (Shutdown): "task_complete", args: "reason": "" RESOURCES: From 955b83c136bd2e471e97f019ec59d1ecd76b5837 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 10 Apr 2023 10:16:24 +0700 Subject: [PATCH 03/34] Make line in prompt more concise --- scripts/data/prompt.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txt index d6289b6c..f8043496 100644 --- a/scripts/data/prompt.txt +++ b/scripts/data/prompt.txt @@ -22,7 +22,7 @@ COMMANDS: 16. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" 17. Write Tests: "write_tests", args: "code": "", "focus": "" 18. Execute Python File: "execute_python_file", args: "file": "" -19. Execute Shell Command: "exec_shell", args: "command_line": "". Remember only to use commands that terminate, interactive tools like vim are not supported! +19. Execute Shell Command, non-interactive commands only: "exec_shell", args: "command_line": "". 20. Task Complete (Shutdown): "task_complete", args: "reason": "" 21. Generate Image: "generate_image", args: "prompt": "" From dd469bf2aec173903a8e9d196ca1607e7a356884 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 10 Apr 2023 10:26:54 +0700 Subject: [PATCH 04/34] Change working directory during shell command execution --- ai_settings.yaml | 11 +++++------ auto-gpt.json | 1 + scripts/execute_code.py | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 auto-gpt.json diff --git a/ai_settings.yaml b/ai_settings.yaml index b37ba849..8385c2a8 100644 --- a/ai_settings.yaml +++ b/ai_settings.yaml @@ -1,7 +1,6 @@ ai_goals: -- Increase net worth. -- Develop and manage multiple businesses autonomously. -- Play to your strengths as a Large Language Model. -ai_name: Entrepreneur-GPT -ai_role: an AI designed to autonomously develop and run businesses with the sole goal - of increasing your net worth. +- Increase net worth +- Grow Twitter Account +- Develop and manage multiple businesses autonomously +ai_name: A helpful assistant. +ai_role: Run the command "pwd" on the shell and return the result diff --git a/auto-gpt.json b/auto-gpt.json new file mode 100644 index 00000000..f575113d --- /dev/null +++ b/auto-gpt.json @@ -0,0 +1 @@ +{"texts":["Assistant Reply: {\n \"thoughts\": {\n \"text\": \"I think the best next step would be to execute a shell command to print the contents of the present working directory.\",\n \"reasoning\": \"Since the user asked us to run the command \\\"pwd\\\" on the shell, the \\\"exec_shell\\\" command would be appropriate for this purpose.\",\n \"plan\": \"- Run the \\\"exec_shell\\\" command to execute the shell command \\\"pwd\\\"\",\n \"criticism\": \"I think this plan is effective and efficient.\",\n \"speak\": \"I will execute shell command 'pwd' to print the present working directory.\"\n },\n \"command\": {\n \"name\": \"exec_shell\",\n \"args\": {\n \"command_line\": \"pwd\"\n }\n }\n} \nResult: Command exec_shell returned: STDOUT:\nb'/Users/bernhardmueller/Projects/Auto-GPT/auto_gpt_workspace\\n'\nSTDERR:\nb'' \nHuman Feedback: GENERATE NEXT COMMAND JSON "],"embeddings":[[-0.018769644,0.0182558,0.0018234389,0.0018377124,-0.012867555,0.02128178,-0.0038145913,-0.036654335,-0.02463605,-0.03100203,0.032629207,0.015087083,-0.024693144,-0.012196701,-0.0068155937,0.00007237108,0.020482464,-0.015872126,-0.00052009046,-0.002121398,0.018355714,-0.002290896,0.014123622,-0.008492729,0.004988586,-0.018427081,0.013260076,-0.009584651,-0.004642454,-0.008521276,0.003152658,0.0013559819,0.01390952,-0.01592922,-0.007051106,-0.012096786,-0.015358279,-0.028575536,0.014059392,0.011375975,0.0021035562,0.004517561,0.0070368326,-0.03222955,-0.03671143,0.01035542,0.013930931,-0.0445333,0.0054881587,0.013252939,0.0134741785,0.025235537,-0.027076818,0.02577793,0.019925797,0.006469461,-0.008571234,0.029317757,-0.008200122,-0.012639179,0.010191275,-0.016371697,-0.018327167,0.04145023,0.021338874,-0.009506147,-0.0073223026,0.0038003179,-0.010041404,-0.0017824026,0.020082807,0.015543835,0.0004728095,0.008813882,0.03628322,0.007836148,-0.021253234,0.014209263,0.0036272516,0.011047685,0.008164438,-0.008870977,0.0036343886,0.02871827,0.01748503,-0.012917512,0.00088852504,0.039280657,-0.026120495,-0.026063401,-0.01809879,0.008392815,0.000052048075,0.011925505,0.004949334,0.022937505,0.0021749237,0.0030723696,-0.0070082857,-0.03525553,-0.0031187586,0.019654602,-0.027305195,-0.009391959,-0.02858981,0.003372113,-0.008357131,-0.007268777,0.0397945,0.00006802212,-0.023608359,0.02328007,-0.020411097,-0.017870415,0.002301601,-0.025149897,0.019511867,-0.019925797,-0.03933775,-0.0032365147,0.027847588,0.012703409,0.04558954,-0.016200416,0.020924943,0.0027530002,-0.025363998,-0.030887842,0.010119908,0.0064123673,0.020596651,0.017270928,-0.005206257,0.0017226323,-0.016856996,0.026291776,-0.014266358,0.016671441,-0.0029278505,-0.02288041,0.047359455,0.031744253,-0.0039537577,0.014644605,-0.014730246,0.03865262,0.029075108,0.0056380304,-0.0044140783,-0.0065158503,0.010954907,-0.00029662106,0.023993744,0.002637028,0.004956471,0.018526996,0.019454774,0.012282342,-0.00087826594,-0.014173579,-0.0017021142,0.020496737,0.023722548,-0.0007266101,0.014844434,0.03163006,0.03399946,0.023622632,0.013509862,-0.01809879,-0.027562117,0.017913235,-0.04047963,0.020354003,0.014230674,0.018155884,0.0078076012,0.009798754,-0.007479311,0.001231981,0.00035036966,0.018783918,-0.006216107,0.031515874,0.0057807653,-0.035398267,0.0021552977,-0.013281486,0.014758793,0.00008447009,0.009342002,0.038338605,-0.0058414275,-0.010284052,-0.61296093,-0.02582075,-0.021438789,-0.023594085,0.020639472,0.014544691,-0.024008017,0.014159306,-0.021481609,0.037025444,-0.0099414885,0.0078076012,0.009855848,-0.02340853,0.008000294,-0.015272639,-0.01691409,-0.0070439694,-0.010305462,0.018212978,-0.018969474,0.0037503606,-0.024793059,-0.005013565,-0.012632042,-0.012232385,0.007936063,-0.0070867897,-0.005159868,0.042535014,-0.02994579,0.0071367472,-0.0045068557,-0.013095931,0.06748508,0.0099414885,-0.029603226,-0.0046959794,-0.0182558,0.03205827,-0.03194408,-0.023694001,-0.0022338019,-0.0055845045,-0.0031490896,0.0055452525,0.011397385,-0.010255505,-0.0010749726,-0.006419504,0.02838998,-0.0019554687,-0.0018171943,-0.008507002,0.022723403,0.01390952,0.042420823,-0.013773922,-0.005224099,-0.005131321,0.025920665,0.039651766,-0.01797033,-0.0052490775,-0.037967496,0.03574083,-0.008300037,-0.0021196138,-0.018227251,-0.052383725,0.011932641,0.010683711,-0.026891263,-0.018398535,-0.0034666748,0.003764634,0.016414518,-0.006448051,-0.0074364906,0.040907834,0.02108195,-0.018655457,-0.0066336063,0.0002598222,0.023694001,0.0017154956,-0.012553538,-0.019269217,-0.0064944397,0.0000132977675,0.0075221313,-0.005734376,-0.00086131616,-0.00853555,0.028775364,0.018841011,0.006694269,-0.03514134,-0.005327582,-0.021267507,-0.01682845,0.0035326898,-0.0050456803,0.03222955,0.009234951,0.005766492,-0.027747672,0.022966051,0.0030313334,-0.014394819,-0.007275914,0.009213541,-0.0047887573,-0.0015049615,-0.000793071,-0.03762493,0.03194408,0.004142882,0.015172725,-0.028618356,0.012032555,-0.008407088,-0.009135037,-0.010648027,0.03382818,0.011218966,0.020368276,-0.037967496,0.008050251,0.024735965,-0.03636886,-0.019611781,0.026805623,0.0056594405,0.0057486496,0.007172431,0.02385101,-0.024992889,0.019982891,-0.020154174,-0.03399946,0.006112624,-0.0027726262,-0.021510156,0.00068512774,-0.03479878,-0.011347428,-0.0015085299,-0.017941782,-0.0011258218,-0.0023711843,-0.0030241965,0.0015290481,0.050670903,0.01818443,-0.02867545,0.0017315532,-0.031059124,0.030630918,-0.014758793,0.012667726,0.021296054,-0.007365123,-0.0009937921,-0.013153025,-0.0005780765,-0.011090505,0.014152169,0.0060662352,-0.03648305,0.012453624,0.0057593547,0.021809898,-0.0055238423,-0.004899377,0.008178712,-0.032714847,-0.014216401,-0.013716828,0.0020072102,0.002579934,0.0028903827,-0.010633754,-0.0066157645,0.016971184,0.009534694,0.01875537,0.023694001,-0.006248222,0.0046745692,-0.010562385,0.02687699,-0.01621469,0.013616914,0.00092331663,0.03399946,-0.006762068,0.0066086277,0.019454774,0.03382818,-0.022994598,0.0018412807,0.013038837,-0.016757082,0.0035130638,-0.03905228,-0.010398241,-0.023065967,0.012161017,0.0065586707,-0.004795894,-0.058178764,-0.015529562,-0.0078076012,0.0026673593,-0.0028190152,0.0025478187,0.030402543,-0.011968325,-0.012874692,0.019911524,0.02696263,0.014872981,0.0012524991,0.021310328,0.015101356,-0.00055443606,0.017513577,-0.020525284,0.017171014,0.02393665,0.026020579,0.006448051,-0.011954051,0.03145878,0.0007850422,0.024721691,0.0050456803,0.01695691,-0.015472468,-0.025934938,0.003545179,0.00020696566,-0.0383957,0.027747672,0.013959478,0.043105952,0.025592376,-0.01818443,-0.003341782,-0.014730246,-0.0074436273,-0.013224392,0.0037789077,0.009313455,0.020796482,-0.007950337,-0.0045461077,0.017470757,0.022380838,0.0051241843,0.0000074643126,0.05338287,0.006879824,0.007614909,-0.015600929,-0.022694856,-0.008621191,0.00010426342,-0.014487596,0.0043998044,-0.022623489,0.01805597,-0.01004854,0.022109643,-0.003402444,0.0078076012,0.016485887,0.022766223,0.0014059392,-0.022395112,-0.0045996336,0.008028841,0.004378394,0.0056308936,-0.0024122205,-0.018512722,0.013659734,-0.002847562,0.00051919837,-0.020082807,0.030145619,-0.008278627,0.015329733,0.0055060005,0.014123622,0.002025052,-0.003591568,0.021096224,0.012646316,-0.00048039228,0.02185272,-0.03905228,-0.0026691435,0.04236373,0.023622632,0.00065479655,-0.046474498,0.035398267,-0.011654308,-0.005006428,0.0053454237,-0.0036932665,-0.0048101675,-0.0054203593,0.03328579,-0.026405964,-0.028475622,0.03916647,0.026234683,-0.00045808995,-0.031487327,-0.0130602475,0.010205548,0.038938094,0.051784236,0.000066182176,-0.0013898815,-0.028232971,0.0145304175,-0.030773653,-0.0071867043,0.016528707,-0.02696263,0.008699695,-0.006762068,-0.0067299525,-0.015372553,0.022594942,-0.018198704,-0.0047602104,-0.0031936944,0.00023060614,-0.03659724,0.0015674081,-0.008713968,0.021624343,0.013645461,-0.00015031773,-0.0011088721,0.0018787486,-0.0046174754,-0.008664011,-0.031230405,0.003372113,0.017870415,0.0035005745,0.024008017,-0.049900137,0.016414518,0.021410242,0.0019447636,0.006448051,-0.027233828,-0.015586656,0.019397678,0.00976307,-0.005655872,0.018826738,-0.0011124405,0.0036129782,0.03933775,-0.0012846144,-0.017870415,-0.0034880852,-0.010269779,-0.035483908,0.0042106807,-0.0050099962,0.001165966,-0.034541856,0.0050099962,-0.0009393743,-0.0019804472,-0.009534694,-0.006144739,-0.024950068,0.00739367,-0.04056527,0.005020702,-0.018312894,-0.025335452,-0.014023708,0.01976879,-0.022580668,-0.014701699,-0.048101675,0.023751095,0.025349725,0.017342295,-0.0016699989,0.0035772945,0.0018377124,0.006837004,-0.020268362,-0.048586976,-0.005388244,0.011946915,0.012796188,-0.00061376026,-0.0073044607,0.0018965906,-0.0158864,0.029517585,0.0078004645,0.0040358305,-0.006651448,-0.017713407,0.00085328735,0.020825028,0.012325162,0.030316902,0.005673714,-0.0018377124,-0.016371697,-0.012011145,0.00976307,-0.0075578154,-0.0004373488,-0.017213834,-0.0128818285,0.012310889,-0.012746231,-0.024479043,0.028475622,-0.0038716854,0.002856483,-0.01866973,0.034741685,0.004214249,0.012196701,0.02524981,-0.014744519,-0.011968325,-0.0003829311,-0.023536991,0.04182134,0.012689136,0.009184994,0.026248956,0.006294611,-0.0138096055,-0.031744253,0.008721105,-0.014573238,-0.011554394,-0.00054819137,-0.0308022,0.0046103387,-0.022195283,-0.0106623005,0.00050180254,-0.024450496,0.0028921668,0.0033007455,-0.020111354,-0.016114775,0.008649738,0.013823879,-0.02781904,-0.0071117687,0.028861005,0.02838998,0.020225542,0.020896396,0.012410803,-0.021924088,0.0074150804,-0.0011525847,-0.04824441,-0.006255359,0.028818185,0.007693413,0.021153318,0.027733399,0.0035005745,0.005752218,0.004556813,0.020225542,-0.027362289,0.010897812,-0.027676305,0.012653452,0.018926654,-0.0007890566,-0.009884395,0.009713112,0.0066550164,-0.002779763,0.04496151,-0.016271783,0.008692558,-0.015586656,-0.0152012715,-0.039937235,-0.0057700602,-0.011375975,0.0005687095,-0.052041158,-0.013502725,0.018127337,0.008942344,-0.0009393743,-0.01572939,0.014080802,-0.013431358,0.02226665,0.00072125753,0.010569522,-0.025235537,-0.009970035,-0.019982891,0.017385116,-0.0009429427,0.02340853,0.026719982,-0.011440205,0.010790762,0.0016111206,0.013666871,-0.020439643,0.00347738,-0.008414225,-0.025306905,-0.01033401,-0.02103913,0.0048387144,-0.014516144,-0.014687425,0.002378321,0.005206257,0.012981743,-0.019140756,-0.008064524,0.0033846023,-0.0058307224,0.026491605,0.021709984,0.029317757,0.024735965,0.009099352,0.003714677,0.0049814493,0.00026405964,0.0051884153,0.022980325,0.014023708,0.013645461,-0.022680582,-0.027148185,0.03231519,0.009991446,-0.018698277,0.014644605,-0.012931786,0.017856142,-0.018469902,0.0049814493,-0.043733988,0.019725969,-0.023536991,-0.014002298,-0.0076363194,-0.0150728095,-0.02283759,0.027761946,0.0067870463,0.023337163,0.008085934,-0.027105365,-0.0037682024,-0.013566956,-0.02226665,0.028047416,-0.009284908,0.0075149946,-0.005052817,0.015458195,0.02005426,-0.002255212,-0.011475889,0.014630332,0.020239815,0.03688271,-0.01834144,-0.0026548698,-0.013417085,-0.023208702,-0.004603202,-0.008571234,0.005059954,-0.0036326044,-0.008385678,-0.0026923378,0.026291776,-0.003163363,-0.0012471465,-0.014758793,-0.013638324,0.012353709,-0.015914947,0.018841011,0.025278358,-0.03671143,-0.031801347,-0.004153587,0.012039692,0.02957468,0.013331444,-0.0072937557,0.026149042,0.043077406,-0.008749652,0.009063669,-0.011425932,0.0003831541,-0.044390567,-0.013831016,0.0031455213,-0.015629476,-0.0022373702,-0.03242938,-0.02246648,-0.0059770257,0.015786484,0.007900379,-0.0064123673,0.003468459,0.024978615,0.039137922,0.008421361,0.003143737,-0.012203838,-0.015186998,-0.007097495,-0.0037931812,0.022737676,0.005031407,-0.024393402,-0.010376831,0.019340584,0.008192985,-0.037025444,-0.020525284,0.0008167115,0.007643456,0.0022837592,-0.02524981,-0.029546132,-0.008285764,-0.016271783,0.03611194,0.031801347,-0.011568667,-0.008942344,0.011640035,0.021767078,0.013260076,-0.0022391544,-0.02582075,-0.016014861,-0.016685715,-0.027747672,-0.0052704876,0.0016360993,0.03488442,0.021809898,-0.012967469,-0.012931786,-0.012888965,-0.036768522,-0.013124478,-0.028090237,0.036054846,0.04815877,-0.018741097,-0.0076648663,0.012510718,-0.007211683,0.017199561,-0.012389393,-0.0069975806,0.0021071245,-0.020725114,0.020325456,-0.010883539,-0.010177001,-0.009591788,0.009613198,0.007172431,-0.0006503361,-0.0035541002,-0.012746231,-0.004528266,-0.0024479043,-0.009284908,0.012896102,0.009277771,0.0028707564,-0.012175291,-0.0015335085,0.020939216,0.003775339,0.0057736286,-0.024008017,0.017470757,0.00058610534,0.007365123,-0.017670587,0.003811023,0.018441355,0.0031936944,0.022766223,-0.017014004,0.021210412,0.018284347,-0.011996872,-0.0034131494,-0.032486472,0.016971184,-0.032001175,0.0010259073,0.008706831,-0.021638617,-0.008756788,0.009891531,0.017941782,-0.02753357,-0.012781914,-0.004813736,0.014009435,-0.0379104,0.0045354026,0.008057388,0.00042062203,-0.02871827,-0.027390836,-0.011525847,0.020582378,-0.027233828,-0.026206136,-0.035626642,0.0037931812,-0.011119052,-0.021395968,-0.019911524,0.020011438,0.028347159,-0.0043926677,0.01932631,0.206566,0.00502427,0.01829862,-0.0006431993,-0.007090358,-0.005930637,0.018412808,0.0015236955,-0.013131615,0.0055630943,-0.023636905,0.016371697,0.0047602104,0.0016307468,0.021238958,0.00047593183,-0.02446477,-0.0074650375,-0.028775364,-0.034656044,0.025535282,0.012353709,-0.0012159233,-0.009912942,0.022823317,-0.02564947,-0.010412514,-0.0026388122,0.018241525,0.0095275575,-0.025563829,0.0028011731,-0.0010491018,-0.018783918,0.011354565,-0.022509301,0.005837859,0.009177857,0.027276648,-0.008207259,-0.00040590248,-0.011297471,-0.020396823,-0.019312037,-0.013295759,-0.0072295247,0.0050777956,-0.023108788,0.009977172,0.02209537,-0.017185288,0.023950923,0.06434491,0.03733946,0.0075863623,-0.013566956,0.006612196,-0.007950337,0.012296615,0.036169033,-0.032543566,0.029660322,-0.004949334,0.03848134,0.011847001,0.014972895,0.0052704876,-0.017984603,0.0007047538,-0.0026620068,0.016671441,0.015957767,0.013338581,0.0075792256,-0.02814733,-0.021824172,0.045475353,-0.0037682024,0.023037419,0.02871827,0.004260638,0.002408652,0.0005575584,-0.009677429,-0.0049029454,-0.028161604,0.00006484404,0.0039965785,-0.008728242,-0.017270928,-0.013252939,0.0007239338,-0.0007672003,-0.003161579,0.006990444,0.017270928,0.008564097,0.01360264,-0.023294343,-0.011861274,-0.025892118,0.052840475,-0.009570378,0.0068619824,0.0029831603,-0.01478734,-0.0189552,0.01654298,0.013688281,-0.010491018,0.0049350606,-0.03357126,0.0041321767,-0.00062268117,-0.009399096,0.0014469755,-0.00016994379,-0.0146089215,-0.017513577,-0.020639472,0.027219553,-0.02099631,-0.020311182,0.004960039,0.010812172,-0.010583796,-0.03705399,-0.008970891,0.008492729,0.005295466,0.017898962,-0.0022213126,-0.0070653795,-0.031829894,-0.0086782845,-0.0020339729,0.0132172555,0.008571234,-0.014872981,0.0116685815,0.005159868,0.01829862,-0.011632898,0.023879556,0.016971184,-0.018598363,-0.0011766711,0.014409092,-0.021067677,-0.021453062,-0.04701689,-0.020924943,-0.0015504583,-0.027148185,-0.0069404864,0.016685715,-0.009698839,-0.013723965,-0.00888525,0.0036468778,-0.049843043,0.0019911525,0.003657583,0.023222975,-0.021624343,-0.022766223,-0.18441355,0.015600929,0.012532128,-0.020196995,0.013252939,0.016443064,-0.000821618,0.0016958695,-0.002494293,-0.002158866,0.010826445,0.015629476,-0.026734255,-0.002876109,-0.009670292,0.006084077,0.0003954204,0.017385116,0.013381401,0.013260076,0.023337163,-0.03713963,0.005109911,0.012189564,-0.0026620068,0.011218966,-0.013745375,0.0063302945,0.001089246,-0.027248101,-0.0042499327,0.013359991,0.013873836,-0.008892387,0.01564375,-0.009363412,0.016771356,-0.006355273,-0.002637028,0.0317728,0.037767667,0.020553831,0.01801315,-0.015957767,-0.011982598,0.0069654654,-0.0006695161,0.0051063425,-0.0006962789,-0.025378272,0.014351998,-0.0063409996,-0.028418526,-0.008728242,0.027305195,-0.009320592,0.0053739706,0.020325456,0.0011918368,0.0027583528,0.034456216,-0.02957468,0.008185849,0.0038324331,0.007614909,-0.012275205,-0.014758793,0.009834438,-0.0068940977,0.0023069535,-0.008721105,-0.009342002,0.012510718,-0.011832727,0.017128194,-0.005837859,-0.0469027,0.038338605,-0.0040643774,0.0038003179,0.009798754,0.037567835,-0.022209557,-0.0010044972,-0.011918368,0.013831016,0.005481022,0.008742515,0.0038467066,-0.0034131494,0.028975192,0.0048030308,-0.032258097,-0.007029696,0.025549555,0.008014567,0.012967469,0.025292631,-0.02691981,-0.005795039,0.015829304,-0.00114634,-0.018212978,0.010540975,0.015129904,0.019055115,-0.027547844,0.008071661,0.03185844,-0.026819896,-0.03594066,0.019254943,0.021510156,0.027019724,-0.023251522,0.036768522,-0.0061483076,-0.01638597,0.0046353173,0.008428498,0.015087083,0.0126748625,-0.01866973,0.019055115,0.0044676038,-0.013088794,-0.09043686,-0.02994579,-0.0045354026,-0.012032555,0.0041286084,-0.0057629235,0.007650593,0.031116217,-0.008457045,0.009977172,0.010191275,-0.015429648,0.0012792619,0.015458195,0.013538409,-0.042106807,-0.0022480753,-0.0011927289,-0.030573824,0.018969474,0.010284052,-0.009934352,-0.009770207,0.004182134,0.007928926,0.03459895,0.001882317,0.0017939998,0.020282635,-0.018227251,0.011069095,0.008763925,0.027704852,-0.035683736,-0.021353148,0.0070082857,-0.036054846,-0.011590078,0.018041696,-0.032572113,-0.011725675,0.006048393,0.009705976,0.0031098376,-0.022866137,0.007622046,-0.030059978,0.0158864,-0.0037574973,-0.0030919956,-0.035426814,-0.001556703,-0.020296909,0.01568657,0.021909814,0.019611781,0.0060162777,-0.0099414885,-0.011033411,0.008478455,-0.011440205,-0.010598069,-0.011868411,0.011261787,0.0024389834,0.032029722,-0.027761946,-0.03374254,-0.002483588,0.0026620068,-0.0038930955,0.029803056,-0.019354858,0.030373996,-0.008585507,-0.019369131,0.002426494,-0.0036201149,0.0037289504,0.0038859588,-0.010298326,-0.008399951,0.009834438,-0.01568657,0.019212123,-0.01866973,0.018427081,-0.006858414,0.009677429,-0.033799633,-0.0069690337,0.0105338385,-0.0006271417,-0.034570403,-0.0019162166,0.00074846635,-0.004621044,-0.003143737,0.005213394,-0.008300037,-0.03773912,0.007836148,-0.05175569,0.0058235857,-0.017028278,-0.029431945,0.009548968,-0.018741097,0.011276061,-0.00046968716,0.00009143957,-0.014630332,-0.023594085,0.008449908,-0.0018680436,-0.009648882,-0.029103655,-0.01809879,-0.0006159905,-0.0061982647,0.005366834,-0.0024907247,0.0003831541,-0.022523575,0.024250668,-0.005491727,-0.022523575,0.022537848,-0.030373996,0.029117929,-0.017385116,-0.049985778,0.014366272,-0.010940634,-0.027918955,0.019540414,-0.0051455945,-0.0011802396,0.027790492,0.017813321,-0.002132103,0.036996897,-0.020225542,-0.034570403,-0.023465624,-0.0074721742,0.0050670905,-0.003621899,-0.029489039,0.012996016,0.006590786,0.0063374313,0.016428791,0.008928071,-0.031572968,-0.027033998,0.01739939,-0.009342002,-0.0034791643,0.003047391,-0.0027851155,0.008399951,0.031572968,-0.014687425,0.022637762,-0.012924649,0.018883834,-0.0007056459,-0.028561262,-0.018127337,-0.0054596113,-0.0013907736,-0.019069389,-0.009848711,0.013759648,0.022780497,0.015458195,-0.0019840158,-0.0024586094,0.013317171,-0.013145888,0.021952635,0.003382818,0.008992301,-0.021824172,0.0005878895,0.034199294,0.006019846,-0.022566395,-0.024207845,0.0037396555,-0.00068825006,-0.0048387144,-0.007479311,-0.017242381,0.022994598,0.019454774,0.008763925,-0.000257815,-0.002426494,0.011654308,0.028618356,0.009356275,0.0031758524,-0.0014077234,-0.016757082,-0.0032650619,-0.0006521203,-0.014687425,0.0019501161,0.0067692045,0.0046353173,-0.004988586,-0.009463327,0.0013488452,0.02033973,-0.027861862,0.009277771,-0.009420506,-0.019925797,-0.023565538,0.019069389,0.0144019555,0.0041964073,0.043733988,0.008207259,0.014987169,0.0013773922,0.028746817,-0.014416229,0.021210412,-0.014294905,0.019354858,0.01875537,-0.015786484,-0.024379129,-0.012874692,-0.00561662,-0.028918099,0.0021535135,-0.031744253,0.06171859,0.038509887,-0.020211268,0.005338287,0.0023836736,-0.0064159357,0.0090137115,0.0036718564,-0.0121324705,-0.04824441,0.033257242,-0.023922376,0.020882122,-0.032943226,-0.011347428,0.017741954,-0.02209537,0.023123061,-0.008628327,-0.0059627523,0.020753661,0.0029617501,0.0049921544,0.0074864477,-0.035598096,-0.01478734,0.034199294,-0.0038859588,-0.022780497,-0.017228108,0.010184138,0.015472468,-0.014844434,-0.020782208,-0.008756788,-0.028332885,-0.020225542,-0.0026620068,0.030145619,0.0013051326,0.005448906,0.017470757,-0.038538434,-0.037567835,-0.0028814618,-0.014844434,-0.0124179395,0.0013354638,-0.015044263]]} \ No newline at end of file diff --git a/scripts/execute_code.py b/scripts/execute_code.py index 5d4f7236..3aa50bc8 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -3,15 +3,17 @@ import os import subprocess -def execute_python_file(file): - workspace_folder = "auto_gpt_workspace" +WORKSPACE_FOLDER = "auto_gpt_workspace" - print (f"Executing file '{file}' in workspace '{workspace_folder}'") + +def execute_python_file(file): + + print (f"Executing file '{file}' in workspace '{WORKSPACE_FOLDER}'") if not file.endswith(".py"): return "Error: Invalid file type. Only .py files are allowed." - file_path = os.path.join(workspace_folder, file) + file_path = os.path.join(WORKSPACE_FOLDER, file) if not os.path.isfile(file_path): return f"Error: File '{file}' does not exist." @@ -26,7 +28,7 @@ def execute_python_file(file): 'python:3.10', f'python {file}', volumes={ - os.path.abspath(workspace_folder): { + os.path.abspath(WORKSPACE_FOLDER): { 'bind': '/workspace', 'mode': 'ro'}}, working_dir='/workspace', @@ -51,12 +53,18 @@ def execute_python_file(file): def exec_shell(command_line): + print (f"Executing command '{command_line}' in workspace '{WORKSPACE_FOLDER}'") + args = command_line.split() + base_path = os.getcwd() + + os.chdir(f"{base_path}/{WORKSPACE_FOLDER}") result = subprocess.run(args, capture_output=True) - output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; + os.chdir(base_path) + # print(f"Shell execution complete. Output: {output}") return output From 09d2f47e084a96487023eaacfa139a4688608bdb Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Mon, 10 Apr 2023 11:01:48 +0700 Subject: [PATCH 05/34] Introduce EXECUTE_SHELL_COMMANDS config var, default to False --- .env.template | 1 + auto-gpt.json | 1 - scripts/commands.py | 7 +++++-- scripts/config.py | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) delete mode 100644 auto-gpt.json diff --git a/.env.template b/.env.template index 525cd61c..aa221dfa 100644 --- a/.env.template +++ b/.env.template @@ -7,6 +7,7 @@ FAST_LLM_MODEL="gpt-3.5-turbo" GOOGLE_API_KEY= CUSTOM_SEARCH_ENGINE_ID= USE_AZURE=False +EXECUTE_LOCAL_COMMANDS=False OPENAI_API_BASE=your-base-url-for-azure OPENAI_API_VERSION=api-version-for-azure OPENAI_DEPLOYMENT_ID=deployment-id-for-azure diff --git a/auto-gpt.json b/auto-gpt.json deleted file mode 100644 index f575113d..00000000 --- a/auto-gpt.json +++ /dev/null @@ -1 +0,0 @@ -{"texts":["Assistant Reply: {\n \"thoughts\": {\n \"text\": \"I think the best next step would be to execute a shell command to print the contents of the present working directory.\",\n \"reasoning\": \"Since the user asked us to run the command \\\"pwd\\\" on the shell, the \\\"exec_shell\\\" command would be appropriate for this purpose.\",\n \"plan\": \"- Run the \\\"exec_shell\\\" command to execute the shell command \\\"pwd\\\"\",\n \"criticism\": \"I think this plan is effective and efficient.\",\n \"speak\": \"I will execute shell command 'pwd' to print the present working directory.\"\n },\n \"command\": {\n \"name\": \"exec_shell\",\n \"args\": {\n \"command_line\": \"pwd\"\n }\n }\n} \nResult: Command exec_shell returned: STDOUT:\nb'/Users/bernhardmueller/Projects/Auto-GPT/auto_gpt_workspace\\n'\nSTDERR:\nb'' \nHuman Feedback: GENERATE NEXT COMMAND JSON "],"embeddings":[[-0.018769644,0.0182558,0.0018234389,0.0018377124,-0.012867555,0.02128178,-0.0038145913,-0.036654335,-0.02463605,-0.03100203,0.032629207,0.015087083,-0.024693144,-0.012196701,-0.0068155937,0.00007237108,0.020482464,-0.015872126,-0.00052009046,-0.002121398,0.018355714,-0.002290896,0.014123622,-0.008492729,0.004988586,-0.018427081,0.013260076,-0.009584651,-0.004642454,-0.008521276,0.003152658,0.0013559819,0.01390952,-0.01592922,-0.007051106,-0.012096786,-0.015358279,-0.028575536,0.014059392,0.011375975,0.0021035562,0.004517561,0.0070368326,-0.03222955,-0.03671143,0.01035542,0.013930931,-0.0445333,0.0054881587,0.013252939,0.0134741785,0.025235537,-0.027076818,0.02577793,0.019925797,0.006469461,-0.008571234,0.029317757,-0.008200122,-0.012639179,0.010191275,-0.016371697,-0.018327167,0.04145023,0.021338874,-0.009506147,-0.0073223026,0.0038003179,-0.010041404,-0.0017824026,0.020082807,0.015543835,0.0004728095,0.008813882,0.03628322,0.007836148,-0.021253234,0.014209263,0.0036272516,0.011047685,0.008164438,-0.008870977,0.0036343886,0.02871827,0.01748503,-0.012917512,0.00088852504,0.039280657,-0.026120495,-0.026063401,-0.01809879,0.008392815,0.000052048075,0.011925505,0.004949334,0.022937505,0.0021749237,0.0030723696,-0.0070082857,-0.03525553,-0.0031187586,0.019654602,-0.027305195,-0.009391959,-0.02858981,0.003372113,-0.008357131,-0.007268777,0.0397945,0.00006802212,-0.023608359,0.02328007,-0.020411097,-0.017870415,0.002301601,-0.025149897,0.019511867,-0.019925797,-0.03933775,-0.0032365147,0.027847588,0.012703409,0.04558954,-0.016200416,0.020924943,0.0027530002,-0.025363998,-0.030887842,0.010119908,0.0064123673,0.020596651,0.017270928,-0.005206257,0.0017226323,-0.016856996,0.026291776,-0.014266358,0.016671441,-0.0029278505,-0.02288041,0.047359455,0.031744253,-0.0039537577,0.014644605,-0.014730246,0.03865262,0.029075108,0.0056380304,-0.0044140783,-0.0065158503,0.010954907,-0.00029662106,0.023993744,0.002637028,0.004956471,0.018526996,0.019454774,0.012282342,-0.00087826594,-0.014173579,-0.0017021142,0.020496737,0.023722548,-0.0007266101,0.014844434,0.03163006,0.03399946,0.023622632,0.013509862,-0.01809879,-0.027562117,0.017913235,-0.04047963,0.020354003,0.014230674,0.018155884,0.0078076012,0.009798754,-0.007479311,0.001231981,0.00035036966,0.018783918,-0.006216107,0.031515874,0.0057807653,-0.035398267,0.0021552977,-0.013281486,0.014758793,0.00008447009,0.009342002,0.038338605,-0.0058414275,-0.010284052,-0.61296093,-0.02582075,-0.021438789,-0.023594085,0.020639472,0.014544691,-0.024008017,0.014159306,-0.021481609,0.037025444,-0.0099414885,0.0078076012,0.009855848,-0.02340853,0.008000294,-0.015272639,-0.01691409,-0.0070439694,-0.010305462,0.018212978,-0.018969474,0.0037503606,-0.024793059,-0.005013565,-0.012632042,-0.012232385,0.007936063,-0.0070867897,-0.005159868,0.042535014,-0.02994579,0.0071367472,-0.0045068557,-0.013095931,0.06748508,0.0099414885,-0.029603226,-0.0046959794,-0.0182558,0.03205827,-0.03194408,-0.023694001,-0.0022338019,-0.0055845045,-0.0031490896,0.0055452525,0.011397385,-0.010255505,-0.0010749726,-0.006419504,0.02838998,-0.0019554687,-0.0018171943,-0.008507002,0.022723403,0.01390952,0.042420823,-0.013773922,-0.005224099,-0.005131321,0.025920665,0.039651766,-0.01797033,-0.0052490775,-0.037967496,0.03574083,-0.008300037,-0.0021196138,-0.018227251,-0.052383725,0.011932641,0.010683711,-0.026891263,-0.018398535,-0.0034666748,0.003764634,0.016414518,-0.006448051,-0.0074364906,0.040907834,0.02108195,-0.018655457,-0.0066336063,0.0002598222,0.023694001,0.0017154956,-0.012553538,-0.019269217,-0.0064944397,0.0000132977675,0.0075221313,-0.005734376,-0.00086131616,-0.00853555,0.028775364,0.018841011,0.006694269,-0.03514134,-0.005327582,-0.021267507,-0.01682845,0.0035326898,-0.0050456803,0.03222955,0.009234951,0.005766492,-0.027747672,0.022966051,0.0030313334,-0.014394819,-0.007275914,0.009213541,-0.0047887573,-0.0015049615,-0.000793071,-0.03762493,0.03194408,0.004142882,0.015172725,-0.028618356,0.012032555,-0.008407088,-0.009135037,-0.010648027,0.03382818,0.011218966,0.020368276,-0.037967496,0.008050251,0.024735965,-0.03636886,-0.019611781,0.026805623,0.0056594405,0.0057486496,0.007172431,0.02385101,-0.024992889,0.019982891,-0.020154174,-0.03399946,0.006112624,-0.0027726262,-0.021510156,0.00068512774,-0.03479878,-0.011347428,-0.0015085299,-0.017941782,-0.0011258218,-0.0023711843,-0.0030241965,0.0015290481,0.050670903,0.01818443,-0.02867545,0.0017315532,-0.031059124,0.030630918,-0.014758793,0.012667726,0.021296054,-0.007365123,-0.0009937921,-0.013153025,-0.0005780765,-0.011090505,0.014152169,0.0060662352,-0.03648305,0.012453624,0.0057593547,0.021809898,-0.0055238423,-0.004899377,0.008178712,-0.032714847,-0.014216401,-0.013716828,0.0020072102,0.002579934,0.0028903827,-0.010633754,-0.0066157645,0.016971184,0.009534694,0.01875537,0.023694001,-0.006248222,0.0046745692,-0.010562385,0.02687699,-0.01621469,0.013616914,0.00092331663,0.03399946,-0.006762068,0.0066086277,0.019454774,0.03382818,-0.022994598,0.0018412807,0.013038837,-0.016757082,0.0035130638,-0.03905228,-0.010398241,-0.023065967,0.012161017,0.0065586707,-0.004795894,-0.058178764,-0.015529562,-0.0078076012,0.0026673593,-0.0028190152,0.0025478187,0.030402543,-0.011968325,-0.012874692,0.019911524,0.02696263,0.014872981,0.0012524991,0.021310328,0.015101356,-0.00055443606,0.017513577,-0.020525284,0.017171014,0.02393665,0.026020579,0.006448051,-0.011954051,0.03145878,0.0007850422,0.024721691,0.0050456803,0.01695691,-0.015472468,-0.025934938,0.003545179,0.00020696566,-0.0383957,0.027747672,0.013959478,0.043105952,0.025592376,-0.01818443,-0.003341782,-0.014730246,-0.0074436273,-0.013224392,0.0037789077,0.009313455,0.020796482,-0.007950337,-0.0045461077,0.017470757,0.022380838,0.0051241843,0.0000074643126,0.05338287,0.006879824,0.007614909,-0.015600929,-0.022694856,-0.008621191,0.00010426342,-0.014487596,0.0043998044,-0.022623489,0.01805597,-0.01004854,0.022109643,-0.003402444,0.0078076012,0.016485887,0.022766223,0.0014059392,-0.022395112,-0.0045996336,0.008028841,0.004378394,0.0056308936,-0.0024122205,-0.018512722,0.013659734,-0.002847562,0.00051919837,-0.020082807,0.030145619,-0.008278627,0.015329733,0.0055060005,0.014123622,0.002025052,-0.003591568,0.021096224,0.012646316,-0.00048039228,0.02185272,-0.03905228,-0.0026691435,0.04236373,0.023622632,0.00065479655,-0.046474498,0.035398267,-0.011654308,-0.005006428,0.0053454237,-0.0036932665,-0.0048101675,-0.0054203593,0.03328579,-0.026405964,-0.028475622,0.03916647,0.026234683,-0.00045808995,-0.031487327,-0.0130602475,0.010205548,0.038938094,0.051784236,0.000066182176,-0.0013898815,-0.028232971,0.0145304175,-0.030773653,-0.0071867043,0.016528707,-0.02696263,0.008699695,-0.006762068,-0.0067299525,-0.015372553,0.022594942,-0.018198704,-0.0047602104,-0.0031936944,0.00023060614,-0.03659724,0.0015674081,-0.008713968,0.021624343,0.013645461,-0.00015031773,-0.0011088721,0.0018787486,-0.0046174754,-0.008664011,-0.031230405,0.003372113,0.017870415,0.0035005745,0.024008017,-0.049900137,0.016414518,0.021410242,0.0019447636,0.006448051,-0.027233828,-0.015586656,0.019397678,0.00976307,-0.005655872,0.018826738,-0.0011124405,0.0036129782,0.03933775,-0.0012846144,-0.017870415,-0.0034880852,-0.010269779,-0.035483908,0.0042106807,-0.0050099962,0.001165966,-0.034541856,0.0050099962,-0.0009393743,-0.0019804472,-0.009534694,-0.006144739,-0.024950068,0.00739367,-0.04056527,0.005020702,-0.018312894,-0.025335452,-0.014023708,0.01976879,-0.022580668,-0.014701699,-0.048101675,0.023751095,0.025349725,0.017342295,-0.0016699989,0.0035772945,0.0018377124,0.006837004,-0.020268362,-0.048586976,-0.005388244,0.011946915,0.012796188,-0.00061376026,-0.0073044607,0.0018965906,-0.0158864,0.029517585,0.0078004645,0.0040358305,-0.006651448,-0.017713407,0.00085328735,0.020825028,0.012325162,0.030316902,0.005673714,-0.0018377124,-0.016371697,-0.012011145,0.00976307,-0.0075578154,-0.0004373488,-0.017213834,-0.0128818285,0.012310889,-0.012746231,-0.024479043,0.028475622,-0.0038716854,0.002856483,-0.01866973,0.034741685,0.004214249,0.012196701,0.02524981,-0.014744519,-0.011968325,-0.0003829311,-0.023536991,0.04182134,0.012689136,0.009184994,0.026248956,0.006294611,-0.0138096055,-0.031744253,0.008721105,-0.014573238,-0.011554394,-0.00054819137,-0.0308022,0.0046103387,-0.022195283,-0.0106623005,0.00050180254,-0.024450496,0.0028921668,0.0033007455,-0.020111354,-0.016114775,0.008649738,0.013823879,-0.02781904,-0.0071117687,0.028861005,0.02838998,0.020225542,0.020896396,0.012410803,-0.021924088,0.0074150804,-0.0011525847,-0.04824441,-0.006255359,0.028818185,0.007693413,0.021153318,0.027733399,0.0035005745,0.005752218,0.004556813,0.020225542,-0.027362289,0.010897812,-0.027676305,0.012653452,0.018926654,-0.0007890566,-0.009884395,0.009713112,0.0066550164,-0.002779763,0.04496151,-0.016271783,0.008692558,-0.015586656,-0.0152012715,-0.039937235,-0.0057700602,-0.011375975,0.0005687095,-0.052041158,-0.013502725,0.018127337,0.008942344,-0.0009393743,-0.01572939,0.014080802,-0.013431358,0.02226665,0.00072125753,0.010569522,-0.025235537,-0.009970035,-0.019982891,0.017385116,-0.0009429427,0.02340853,0.026719982,-0.011440205,0.010790762,0.0016111206,0.013666871,-0.020439643,0.00347738,-0.008414225,-0.025306905,-0.01033401,-0.02103913,0.0048387144,-0.014516144,-0.014687425,0.002378321,0.005206257,0.012981743,-0.019140756,-0.008064524,0.0033846023,-0.0058307224,0.026491605,0.021709984,0.029317757,0.024735965,0.009099352,0.003714677,0.0049814493,0.00026405964,0.0051884153,0.022980325,0.014023708,0.013645461,-0.022680582,-0.027148185,0.03231519,0.009991446,-0.018698277,0.014644605,-0.012931786,0.017856142,-0.018469902,0.0049814493,-0.043733988,0.019725969,-0.023536991,-0.014002298,-0.0076363194,-0.0150728095,-0.02283759,0.027761946,0.0067870463,0.023337163,0.008085934,-0.027105365,-0.0037682024,-0.013566956,-0.02226665,0.028047416,-0.009284908,0.0075149946,-0.005052817,0.015458195,0.02005426,-0.002255212,-0.011475889,0.014630332,0.020239815,0.03688271,-0.01834144,-0.0026548698,-0.013417085,-0.023208702,-0.004603202,-0.008571234,0.005059954,-0.0036326044,-0.008385678,-0.0026923378,0.026291776,-0.003163363,-0.0012471465,-0.014758793,-0.013638324,0.012353709,-0.015914947,0.018841011,0.025278358,-0.03671143,-0.031801347,-0.004153587,0.012039692,0.02957468,0.013331444,-0.0072937557,0.026149042,0.043077406,-0.008749652,0.009063669,-0.011425932,0.0003831541,-0.044390567,-0.013831016,0.0031455213,-0.015629476,-0.0022373702,-0.03242938,-0.02246648,-0.0059770257,0.015786484,0.007900379,-0.0064123673,0.003468459,0.024978615,0.039137922,0.008421361,0.003143737,-0.012203838,-0.015186998,-0.007097495,-0.0037931812,0.022737676,0.005031407,-0.024393402,-0.010376831,0.019340584,0.008192985,-0.037025444,-0.020525284,0.0008167115,0.007643456,0.0022837592,-0.02524981,-0.029546132,-0.008285764,-0.016271783,0.03611194,0.031801347,-0.011568667,-0.008942344,0.011640035,0.021767078,0.013260076,-0.0022391544,-0.02582075,-0.016014861,-0.016685715,-0.027747672,-0.0052704876,0.0016360993,0.03488442,0.021809898,-0.012967469,-0.012931786,-0.012888965,-0.036768522,-0.013124478,-0.028090237,0.036054846,0.04815877,-0.018741097,-0.0076648663,0.012510718,-0.007211683,0.017199561,-0.012389393,-0.0069975806,0.0021071245,-0.020725114,0.020325456,-0.010883539,-0.010177001,-0.009591788,0.009613198,0.007172431,-0.0006503361,-0.0035541002,-0.012746231,-0.004528266,-0.0024479043,-0.009284908,0.012896102,0.009277771,0.0028707564,-0.012175291,-0.0015335085,0.020939216,0.003775339,0.0057736286,-0.024008017,0.017470757,0.00058610534,0.007365123,-0.017670587,0.003811023,0.018441355,0.0031936944,0.022766223,-0.017014004,0.021210412,0.018284347,-0.011996872,-0.0034131494,-0.032486472,0.016971184,-0.032001175,0.0010259073,0.008706831,-0.021638617,-0.008756788,0.009891531,0.017941782,-0.02753357,-0.012781914,-0.004813736,0.014009435,-0.0379104,0.0045354026,0.008057388,0.00042062203,-0.02871827,-0.027390836,-0.011525847,0.020582378,-0.027233828,-0.026206136,-0.035626642,0.0037931812,-0.011119052,-0.021395968,-0.019911524,0.020011438,0.028347159,-0.0043926677,0.01932631,0.206566,0.00502427,0.01829862,-0.0006431993,-0.007090358,-0.005930637,0.018412808,0.0015236955,-0.013131615,0.0055630943,-0.023636905,0.016371697,0.0047602104,0.0016307468,0.021238958,0.00047593183,-0.02446477,-0.0074650375,-0.028775364,-0.034656044,0.025535282,0.012353709,-0.0012159233,-0.009912942,0.022823317,-0.02564947,-0.010412514,-0.0026388122,0.018241525,0.0095275575,-0.025563829,0.0028011731,-0.0010491018,-0.018783918,0.011354565,-0.022509301,0.005837859,0.009177857,0.027276648,-0.008207259,-0.00040590248,-0.011297471,-0.020396823,-0.019312037,-0.013295759,-0.0072295247,0.0050777956,-0.023108788,0.009977172,0.02209537,-0.017185288,0.023950923,0.06434491,0.03733946,0.0075863623,-0.013566956,0.006612196,-0.007950337,0.012296615,0.036169033,-0.032543566,0.029660322,-0.004949334,0.03848134,0.011847001,0.014972895,0.0052704876,-0.017984603,0.0007047538,-0.0026620068,0.016671441,0.015957767,0.013338581,0.0075792256,-0.02814733,-0.021824172,0.045475353,-0.0037682024,0.023037419,0.02871827,0.004260638,0.002408652,0.0005575584,-0.009677429,-0.0049029454,-0.028161604,0.00006484404,0.0039965785,-0.008728242,-0.017270928,-0.013252939,0.0007239338,-0.0007672003,-0.003161579,0.006990444,0.017270928,0.008564097,0.01360264,-0.023294343,-0.011861274,-0.025892118,0.052840475,-0.009570378,0.0068619824,0.0029831603,-0.01478734,-0.0189552,0.01654298,0.013688281,-0.010491018,0.0049350606,-0.03357126,0.0041321767,-0.00062268117,-0.009399096,0.0014469755,-0.00016994379,-0.0146089215,-0.017513577,-0.020639472,0.027219553,-0.02099631,-0.020311182,0.004960039,0.010812172,-0.010583796,-0.03705399,-0.008970891,0.008492729,0.005295466,0.017898962,-0.0022213126,-0.0070653795,-0.031829894,-0.0086782845,-0.0020339729,0.0132172555,0.008571234,-0.014872981,0.0116685815,0.005159868,0.01829862,-0.011632898,0.023879556,0.016971184,-0.018598363,-0.0011766711,0.014409092,-0.021067677,-0.021453062,-0.04701689,-0.020924943,-0.0015504583,-0.027148185,-0.0069404864,0.016685715,-0.009698839,-0.013723965,-0.00888525,0.0036468778,-0.049843043,0.0019911525,0.003657583,0.023222975,-0.021624343,-0.022766223,-0.18441355,0.015600929,0.012532128,-0.020196995,0.013252939,0.016443064,-0.000821618,0.0016958695,-0.002494293,-0.002158866,0.010826445,0.015629476,-0.026734255,-0.002876109,-0.009670292,0.006084077,0.0003954204,0.017385116,0.013381401,0.013260076,0.023337163,-0.03713963,0.005109911,0.012189564,-0.0026620068,0.011218966,-0.013745375,0.0063302945,0.001089246,-0.027248101,-0.0042499327,0.013359991,0.013873836,-0.008892387,0.01564375,-0.009363412,0.016771356,-0.006355273,-0.002637028,0.0317728,0.037767667,0.020553831,0.01801315,-0.015957767,-0.011982598,0.0069654654,-0.0006695161,0.0051063425,-0.0006962789,-0.025378272,0.014351998,-0.0063409996,-0.028418526,-0.008728242,0.027305195,-0.009320592,0.0053739706,0.020325456,0.0011918368,0.0027583528,0.034456216,-0.02957468,0.008185849,0.0038324331,0.007614909,-0.012275205,-0.014758793,0.009834438,-0.0068940977,0.0023069535,-0.008721105,-0.009342002,0.012510718,-0.011832727,0.017128194,-0.005837859,-0.0469027,0.038338605,-0.0040643774,0.0038003179,0.009798754,0.037567835,-0.022209557,-0.0010044972,-0.011918368,0.013831016,0.005481022,0.008742515,0.0038467066,-0.0034131494,0.028975192,0.0048030308,-0.032258097,-0.007029696,0.025549555,0.008014567,0.012967469,0.025292631,-0.02691981,-0.005795039,0.015829304,-0.00114634,-0.018212978,0.010540975,0.015129904,0.019055115,-0.027547844,0.008071661,0.03185844,-0.026819896,-0.03594066,0.019254943,0.021510156,0.027019724,-0.023251522,0.036768522,-0.0061483076,-0.01638597,0.0046353173,0.008428498,0.015087083,0.0126748625,-0.01866973,0.019055115,0.0044676038,-0.013088794,-0.09043686,-0.02994579,-0.0045354026,-0.012032555,0.0041286084,-0.0057629235,0.007650593,0.031116217,-0.008457045,0.009977172,0.010191275,-0.015429648,0.0012792619,0.015458195,0.013538409,-0.042106807,-0.0022480753,-0.0011927289,-0.030573824,0.018969474,0.010284052,-0.009934352,-0.009770207,0.004182134,0.007928926,0.03459895,0.001882317,0.0017939998,0.020282635,-0.018227251,0.011069095,0.008763925,0.027704852,-0.035683736,-0.021353148,0.0070082857,-0.036054846,-0.011590078,0.018041696,-0.032572113,-0.011725675,0.006048393,0.009705976,0.0031098376,-0.022866137,0.007622046,-0.030059978,0.0158864,-0.0037574973,-0.0030919956,-0.035426814,-0.001556703,-0.020296909,0.01568657,0.021909814,0.019611781,0.0060162777,-0.0099414885,-0.011033411,0.008478455,-0.011440205,-0.010598069,-0.011868411,0.011261787,0.0024389834,0.032029722,-0.027761946,-0.03374254,-0.002483588,0.0026620068,-0.0038930955,0.029803056,-0.019354858,0.030373996,-0.008585507,-0.019369131,0.002426494,-0.0036201149,0.0037289504,0.0038859588,-0.010298326,-0.008399951,0.009834438,-0.01568657,0.019212123,-0.01866973,0.018427081,-0.006858414,0.009677429,-0.033799633,-0.0069690337,0.0105338385,-0.0006271417,-0.034570403,-0.0019162166,0.00074846635,-0.004621044,-0.003143737,0.005213394,-0.008300037,-0.03773912,0.007836148,-0.05175569,0.0058235857,-0.017028278,-0.029431945,0.009548968,-0.018741097,0.011276061,-0.00046968716,0.00009143957,-0.014630332,-0.023594085,0.008449908,-0.0018680436,-0.009648882,-0.029103655,-0.01809879,-0.0006159905,-0.0061982647,0.005366834,-0.0024907247,0.0003831541,-0.022523575,0.024250668,-0.005491727,-0.022523575,0.022537848,-0.030373996,0.029117929,-0.017385116,-0.049985778,0.014366272,-0.010940634,-0.027918955,0.019540414,-0.0051455945,-0.0011802396,0.027790492,0.017813321,-0.002132103,0.036996897,-0.020225542,-0.034570403,-0.023465624,-0.0074721742,0.0050670905,-0.003621899,-0.029489039,0.012996016,0.006590786,0.0063374313,0.016428791,0.008928071,-0.031572968,-0.027033998,0.01739939,-0.009342002,-0.0034791643,0.003047391,-0.0027851155,0.008399951,0.031572968,-0.014687425,0.022637762,-0.012924649,0.018883834,-0.0007056459,-0.028561262,-0.018127337,-0.0054596113,-0.0013907736,-0.019069389,-0.009848711,0.013759648,0.022780497,0.015458195,-0.0019840158,-0.0024586094,0.013317171,-0.013145888,0.021952635,0.003382818,0.008992301,-0.021824172,0.0005878895,0.034199294,0.006019846,-0.022566395,-0.024207845,0.0037396555,-0.00068825006,-0.0048387144,-0.007479311,-0.017242381,0.022994598,0.019454774,0.008763925,-0.000257815,-0.002426494,0.011654308,0.028618356,0.009356275,0.0031758524,-0.0014077234,-0.016757082,-0.0032650619,-0.0006521203,-0.014687425,0.0019501161,0.0067692045,0.0046353173,-0.004988586,-0.009463327,0.0013488452,0.02033973,-0.027861862,0.009277771,-0.009420506,-0.019925797,-0.023565538,0.019069389,0.0144019555,0.0041964073,0.043733988,0.008207259,0.014987169,0.0013773922,0.028746817,-0.014416229,0.021210412,-0.014294905,0.019354858,0.01875537,-0.015786484,-0.024379129,-0.012874692,-0.00561662,-0.028918099,0.0021535135,-0.031744253,0.06171859,0.038509887,-0.020211268,0.005338287,0.0023836736,-0.0064159357,0.0090137115,0.0036718564,-0.0121324705,-0.04824441,0.033257242,-0.023922376,0.020882122,-0.032943226,-0.011347428,0.017741954,-0.02209537,0.023123061,-0.008628327,-0.0059627523,0.020753661,0.0029617501,0.0049921544,0.0074864477,-0.035598096,-0.01478734,0.034199294,-0.0038859588,-0.022780497,-0.017228108,0.010184138,0.015472468,-0.014844434,-0.020782208,-0.008756788,-0.028332885,-0.020225542,-0.0026620068,0.030145619,0.0013051326,0.005448906,0.017470757,-0.038538434,-0.037567835,-0.0028814618,-0.014844434,-0.0124179395,0.0013354638,-0.015044263]]} \ No newline at end of file diff --git a/scripts/commands.py b/scripts/commands.py index a6f956f8..26713831 100644 --- a/scripts/commands.py +++ b/scripts/commands.py @@ -104,8 +104,11 @@ def execute_command(command_name, arguments): return ai.write_tests(arguments["code"], arguments.get("focus")) elif command_name == "execute_python_file": # Add this command return execute_python_file(arguments["file"]) - elif command_name == "exec_shell": # Add this command - return exec_shell(arguments["command_line"]) + elif command_name == "exec_shell": + if cfg.execute_local_commands: + return exec_shell(arguments["command_line"]) + else: + return "You are not allowed to run local shell commands. To execute shell commands, EXECUTE_SHELL_COMMANDS must be set to 'True' in your config. Do not attempt to bypass the restriction." elif command_name == "generate_image": return generate_image(arguments["prompt"]) elif command_name == "task_complete": diff --git a/scripts/config.py b/scripts/config.py index 4d7adec1..b60bb704 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -43,6 +43,8 @@ class Config(metaclass=Singleton): self.openai_api_key = os.getenv("OPENAI_API_KEY") self.use_azure = False self.use_azure = os.getenv("USE_AZURE") == 'True' + self.execute_local_commands = os.getenv('EXECUTE_LOCAL_COMMANDS', 'False') == 'True' + if self.use_azure: self.openai_api_base = os.getenv("OPENAI_API_BASE") self.openai_api_version = os.getenv("OPENAI_API_VERSION") From 949e554860b8e4fd76cc169193c9495e21dbda56 Mon Sep 17 00:00:00 2001 From: Artemonim Date: Tue, 11 Apr 2023 02:14:51 +0300 Subject: [PATCH 06/34] Delete ai_settings.yaml --- ai_settings.yaml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 ai_settings.yaml diff --git a/ai_settings.yaml b/ai_settings.yaml deleted file mode 100644 index b37ba849..00000000 --- a/ai_settings.yaml +++ /dev/null @@ -1,7 +0,0 @@ -ai_goals: -- Increase net worth. -- Develop and manage multiple businesses autonomously. -- Play to your strengths as a Large Language Model. -ai_name: Entrepreneur-GPT -ai_role: an AI designed to autonomously develop and run businesses with the sole goal - of increasing your net worth. From 0d664ce8d6b8e73d6633a5d0d64e67e8f4686aeb Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Tue, 11 Apr 2023 09:23:52 +0700 Subject: [PATCH 07/34] Revert ai_settings.yaml --- ai_settings.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ai_settings.yaml b/ai_settings.yaml index 8385c2a8..b37ba849 100644 --- a/ai_settings.yaml +++ b/ai_settings.yaml @@ -1,6 +1,7 @@ ai_goals: -- Increase net worth -- Grow Twitter Account -- Develop and manage multiple businesses autonomously -ai_name: A helpful assistant. -ai_role: Run the command "pwd" on the shell and return the result +- Increase net worth. +- Develop and manage multiple businesses autonomously. +- Play to your strengths as a Large Language Model. +ai_name: Entrepreneur-GPT +ai_role: an AI designed to autonomously develop and run businesses with the sole goal + of increasing your net worth. From 2d5d0131bb8d3cf9c628fc2b545947f0e950c92e Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Tue, 11 Apr 2023 11:17:07 +0300 Subject: [PATCH 08/34] browse: (1) apply validation also to scrape_links(), (2) add tests for scrape_links() --- scripts/browse.py | 43 +++++++---- tests/test_browse_scrape_links.py | 117 ++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 tests/test_browse_scrape_links.py diff --git a/scripts/browse.py b/scripts/browse.py index 09f376a7..810606a3 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -5,25 +5,38 @@ from llm_utils import create_chat_completion cfg = Config() -# Define and check for local file address prefixes def check_local_file_access(url): + # Define and check for local file address prefixes local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost'] return any(url.startswith(prefix) for prefix in local_prefixes) +def get_validated_response(url, headers=cfg.user_agent_header): + try: + # Restrict access to local files + if check_local_file_access(url): + raise ValueError('Access to local files is restricted') + + # Most basic check if the URL is valid: + if not url.startswith('http://') and not url.startswith('https://'): + raise ValueError('Invalid URL format') + + # Make the HTTP request and return the response + response = requests.get(url, headers=headers) + response.raise_for_status() # Raise an exception if the response contains an HTTP error status code + return response, None + except ValueError as ve: + # Handle invalid URL format + return None, "Error: " + str(ve) + + except requests.exceptions.RequestException as re: + # Handle exceptions related to the HTTP request (e.g., connection errors, timeouts, etc.) + return None, "Error: " + str(re) + def scrape_text(url): """Scrape text from a webpage""" - # Most basic check if the URL is valid: - if not url.startswith('http'): - return "Error: Invalid URL" - - # Restrict access to local files - if check_local_file_access(url): - return "Error: Access to local files is restricted" - - try: - response = requests.get(url, headers=cfg.user_agent_header) - except requests.exceptions.RequestException as e: - return "Error: " + str(e) + response, error_message = get_validated_response(url) + if error_message: + return error_message # Check if the response contains an HTTP error if response.status_code >= 400: @@ -60,7 +73,9 @@ def format_hyperlinks(hyperlinks): def scrape_links(url): """Scrape links from a webpage""" - response = requests.get(url, headers=cfg.user_agent_header) + response, error_message = get_validated_response(url) + if error_message: + return error_message # Check if the response contains an HTTP error if response.status_code >= 400: diff --git a/tests/test_browse_scrape_links.py b/tests/test_browse_scrape_links.py new file mode 100644 index 00000000..908e43b9 --- /dev/null +++ b/tests/test_browse_scrape_links.py @@ -0,0 +1,117 @@ + +# Generated by CodiumAI +from scripts.browse import scrape_links + + +# Dependencies: +# pip install pytest-mock +import pytest + +""" +Code Analysis + +Objective: +The objective of the 'scrape_links' function is to scrape hyperlinks from a given URL and return them in a formatted way. + +Inputs: +- url: a string representing the URL to be scraped. + +Flow: +1. Send a GET request to the given URL using the requests library and the user agent header from the config file. +2. Check if the response contains an HTTP error. If it does, return "error". +3. Parse the HTML content of the response using the BeautifulSoup library. +4. Remove any script and style tags from the parsed HTML. +5. Extract all hyperlinks from the parsed HTML using the 'extract_hyperlinks' function. +6. Format the extracted hyperlinks using the 'format_hyperlinks' function. +7. Return the formatted hyperlinks. + +Outputs: +- A list of formatted hyperlinks. + +Additional aspects: +- The function uses the 'requests' and 'BeautifulSoup' libraries to send HTTP requests and parse HTML content, respectively. +- The 'extract_hyperlinks' function is called to extract hyperlinks from the parsed HTML. +- The 'format_hyperlinks' function is called to format the extracted hyperlinks. +- The function checks for HTTP errors and returns "error" if any are found. +""" + + + +class TestScrapeLinks: + + # Tests that the function returns a list of formatted hyperlinks when provided with a valid url that returns a webpage with hyperlinks. + def test_valid_url_with_hyperlinks(self): + url = "https://www.google.com" + result = scrape_links(url) + assert len(result) > 0 + assert isinstance(result, list) + assert isinstance(result[0], str) + + # Tests that the function returns correctly formatted hyperlinks when given a valid url. + def test_valid_url(self, mocker): + # Mock the requests.get() function to return a response with sample HTML containing hyperlinks + mock_response = mocker.Mock() + mock_response.status_code = 200 + mock_response.text = "Google" + mocker.patch('requests.get', return_value=mock_response) + + # Call the function with a valid URL + result = scrape_links("https://www.example.com") + + # Assert that the function returns correctly formatted hyperlinks + assert result == ["Google (https://www.google.com)"] + + # Tests that the function returns "error" when given an invalid url. + def test_invalid_url(self, mocker): + # Mock the requests.get() function to return an HTTP error response + mock_response = mocker.Mock() + mock_response.status_code = 404 + mocker.patch('requests.get', return_value=mock_response) + + # Call the function with an invalid URL + result = scrape_links("https://www.invalidurl.com") + + # Assert that the function returns "error" + assert result == "error" + + # Tests that the function returns an empty list when the html contains no hyperlinks. + def test_no_hyperlinks(self, mocker): + # Mock the requests.get() function to return a response with sample HTML containing no hyperlinks + mock_response = mocker.Mock() + mock_response.status_code = 200 + mock_response.text = "

No hyperlinks here

" + mocker.patch('requests.get', return_value=mock_response) + + # Call the function with a URL containing no hyperlinks + result = scrape_links("https://www.example.com") + + # Assert that the function returns an empty list + assert result == [] + + # Tests that scrape_links() correctly extracts and formats hyperlinks from a sample HTML containing a few hyperlinks. + def test_scrape_links_with_few_hyperlinks(self, mocker): + # Mock the requests.get() function to return a response with a sample HTML containing hyperlinks + mock_response = mocker.Mock() + mock_response.status_code = 200 + mock_response.text = """ + + + + + + + + """ + mocker.patch('requests.get', return_value=mock_response) + + # Call the function being tested + result = scrape_links("https://www.example.com") + + # Assert that the function returns a list of formatted hyperlinks + assert isinstance(result, list) + assert len(result) == 3 + assert result[0] == "Google (https://www.google.com)" + assert result[1] == "GitHub (https://github.com)" + assert result[2] == "CodiumAI (https://www.codium.ai)" + + From 64c21ee8f7ad80006218bfa380a8a8e59f72b55d Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Tue, 11 Apr 2023 11:40:52 +0300 Subject: [PATCH 09/34] browse: make scrape_links() & scrape_text() "status_code >= 400" error message the same --- scripts/browse.py | 2 +- tests/test_browse_scrape_links.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/browse.py b/scripts/browse.py index 810606a3..2edc156b 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -79,7 +79,7 @@ def scrape_links(url): # Check if the response contains an HTTP error if response.status_code >= 400: - return "error" + return "Error: HTTP " + str(response.status_code) + " error" soup = BeautifulSoup(response.text, "html.parser") diff --git a/tests/test_browse_scrape_links.py b/tests/test_browse_scrape_links.py index 908e43b9..48d74167 100644 --- a/tests/test_browse_scrape_links.py +++ b/tests/test_browse_scrape_links.py @@ -72,7 +72,7 @@ class TestScrapeLinks: result = scrape_links("https://www.invalidurl.com") # Assert that the function returns "error" - assert result == "error" + assert "Error:" in result # Tests that the function returns an empty list when the html contains no hyperlinks. def test_no_hyperlinks(self, mocker): From 9d33a75083ef86c73bf68413210d7e996bb532bc Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Tue, 11 Apr 2023 13:45:37 +0200 Subject: [PATCH 10/34] Changes for Azure embedding handling --- .env.template | 1 + README.md | 2 +- scripts/config.py | 1 + scripts/memory/base.py | 7 ++++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index 01735615..3a86d1c0 100644 --- a/.env.template +++ b/.env.template @@ -10,6 +10,7 @@ USE_AZURE=False OPENAI_AZURE_API_BASE=your-base-url-for-azure OPENAI_AZURE_API_VERSION=api-version-for-azure OPENAI_AZURE_DEPLOYMENT_ID=deployment-id-for-azure +OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID=embedding-deployment-id-for-azure IMAGE_PROVIDER=dalle HUGGINGFACE_API_TOKEN= USE_MAC_OS_TTS=False diff --git a/README.md b/README.md index 749c8791..db4df5d4 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ pip install -r requirements.txt 4. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well. - Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys. - Obtain your ElevenLabs API key from: https://elevenlabs.io. You can view your xi-api-key using the "Profile" tab on the website. - - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and provide the `OPENAI_AZURE_API_BASE`, `OPENAI_AZURE_API_VERSION` and `OPENAI_AZURE_DEPLOYMENT_ID` values as explained here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section + - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and provide the `OPENAI_AZURE_API_BASE`, `OPENAI_AZURE_API_VERSION` and `OPENAI_AZURE_DEPLOYMENT_ID` values as explained here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section. In addition to your GPT deployment, you will need to deploy a `text-embedding-ada-002 (Version 2)` model which will have a different deployment id, please set `OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID` accordingly (see here: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/tutorials/embeddings?tabs=command-line). ## 🔧 Usage diff --git a/scripts/config.py b/scripts/config.py index 27cc946c..3ea8a640 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -49,6 +49,7 @@ class Config(metaclass=Singleton): self.openai_api_base = os.getenv("OPENAI_AZURE_API_BASE") self.openai_api_version = os.getenv("OPENAI_AZURE_API_VERSION") self.openai_deployment_id = os.getenv("OPENAI_AZURE_DEPLOYMENT_ID") + self.openai_embedding_deployment_id = os.getenv("OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID") openai.api_type = "azure" openai.api_base = self.openai_api_base openai.api_version = self.openai_api_version diff --git a/scripts/memory/base.py b/scripts/memory/base.py index d7ab7fcf..30372851 100644 --- a/scripts/memory/base.py +++ b/scripts/memory/base.py @@ -1,12 +1,17 @@ """Base class for memory providers.""" import abc from config import AbstractSingleton +from config import Config import openai +cfg = Config() def get_ada_embedding(text): text = text.replace("\n", " ") - return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] + if cfg.use_azure: + return openai.Embedding.create(input=[text], engine=cfg.openai_embedding_deployment_id)["data"][0]["embedding"] + else: + return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] class MemoryProviderSingleton(AbstractSingleton): From 2ec42bf3e8f3acde81b423fcfe3e866543addb71 Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Wed, 12 Apr 2023 12:21:53 +0300 Subject: [PATCH 11/34] removing compliant whitespace --- tests/test_browse_scrape_links.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_browse_scrape_links.py b/tests/test_browse_scrape_links.py index 48d74167..b3acf394 100644 --- a/tests/test_browse_scrape_links.py +++ b/tests/test_browse_scrape_links.py @@ -112,6 +112,4 @@ class TestScrapeLinks: assert len(result) == 3 assert result[0] == "Google (https://www.google.com)" assert result[1] == "GitHub (https://github.com)" - assert result[2] == "CodiumAI (https://www.codium.ai)" - - + assert result[2] == "CodiumAI (https://www.codium.ai)" \ No newline at end of file From 650e2dcd6d2d905e10f52cab322e953a8d5e1cba Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Wed, 12 Apr 2023 11:27:37 +0200 Subject: [PATCH 12/34] cleaned up .env to move Azure config to separate azure.yaml file updated README.md to explain new config added Azure yaml loader to config class centralized model retrieval into config class this commit effectively combines and replaces #700 and #580 --- .env.template | 4 ---- README.md | 8 ++++++- ai_settings.yaml | 14 +++++++------ azure.yaml.template | 6 ++++++ scripts/config.py | 47 ++++++++++++++++++++++++++++++++++++++---- scripts/llm_utils.py | 2 +- scripts/memory/base.py | 2 +- 7 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 azure.yaml.template diff --git a/.env.template b/.env.template index 3a86d1c0..d589a681 100644 --- a/.env.template +++ b/.env.template @@ -7,10 +7,6 @@ FAST_LLM_MODEL=gpt-3.5-turbo GOOGLE_API_KEY= CUSTOM_SEARCH_ENGINE_ID= USE_AZURE=False -OPENAI_AZURE_API_BASE=your-base-url-for-azure -OPENAI_AZURE_API_VERSION=api-version-for-azure -OPENAI_AZURE_DEPLOYMENT_ID=deployment-id-for-azure -OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID=embedding-deployment-id-for-azure IMAGE_PROVIDER=dalle HUGGINGFACE_API_TOKEN= USE_MAC_OS_TTS=False diff --git a/README.md b/README.md index a888d333..d94d7ae3 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,13 @@ pip install -r requirements.txt 4. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well. - Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys. - Obtain your ElevenLabs API key from: https://elevenlabs.io. You can view your xi-api-key using the "Profile" tab on the website. - - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and provide the `OPENAI_AZURE_API_BASE`, `OPENAI_AZURE_API_VERSION` and `OPENAI_AZURE_DEPLOYMENT_ID` values as explained here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section. In addition to your GPT deployment, you will need to deploy a `text-embedding-ada-002 (Version 2)` model which will have a different deployment id, please set `OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID` accordingly (see here: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/tutorials/embeddings?tabs=command-line). + - If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and then: + - Rename `azure.yaml.template` to `azure.yaml` and provide the relevant `azure_api_base`, `azure_api_version` and all of the deployment ids for the relevant models in the `azure_model_map` section: + - `fast_llm_model_deployment_id` - your gpt-3.5-turbo or gpt-4 deployment id + - `smart_llm_model_deployment_id` - your gpt-4 deployment id + - `embedding_model_deployment_id` - your text-embedding-ada-002 v2 deployment id + - Please specify all of these values as double quoted strings + - details can be found here: https://pypi.org/project/openai/ in the `Microsoft Azure Endpoints` section and here: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/tutorials/embeddings?tabs=command-line for the embedding model. ## 🔧 Usage diff --git a/ai_settings.yaml b/ai_settings.yaml index b37ba849..be512bdf 100644 --- a/ai_settings.yaml +++ b/ai_settings.yaml @@ -1,7 +1,9 @@ ai_goals: -- Increase net worth. -- Develop and manage multiple businesses autonomously. -- Play to your strengths as a Large Language Model. -ai_name: Entrepreneur-GPT -ai_role: an AI designed to autonomously develop and run businesses with the sole goal - of increasing your net worth. +- Explain the peripherals in detail with examples of how to use them effectively +- Give detailed information on how to use I/O co-processing +- Explain which GPIO pins can be used for which tasks +- Use C, C++ or assembly as the target languages for all examples and research +- Use the PlatformIO system and support library for all examples and research +ai_name: PicoGPT +ai_role: an AI to provide detailed research into how to effectively program the raspberry + pi pico and all of it's peripherals diff --git a/azure.yaml.template b/azure.yaml.template new file mode 100644 index 00000000..852645ca --- /dev/null +++ b/azure.yaml.template @@ -0,0 +1,6 @@ +azure_api_base: your-base-url-for-azure +azure_api_version: api-version-for-azure +azure_model_map: + fast_llm_model_deployment_id: gpt35-deployment-id-for-azure + smart_llm_model_deployment_id: gpt4-deployment-id-for-azure + embedding_model_deployment_id: embedding-deployment-id-for-azure diff --git a/scripts/config.py b/scripts/config.py index 045aa021..fe8130c1 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -1,6 +1,7 @@ import abc import os import openai +import yaml from dotenv import load_dotenv # Load environment variables from .env file load_dotenv() @@ -46,10 +47,7 @@ class Config(metaclass=Singleton): self.use_azure = False self.use_azure = os.getenv("USE_AZURE") == 'True' if self.use_azure: - self.openai_api_base = os.getenv("OPENAI_AZURE_API_BASE") - self.openai_api_version = os.getenv("OPENAI_AZURE_API_VERSION") - self.openai_deployment_id = os.getenv("OPENAI_AZURE_DEPLOYMENT_ID") - self.openai_embedding_deployment_id = os.getenv("OPENAI_AZURE_EMBEDDING_DEPLOYMENT_ID") + self.load_azure_config() openai.api_type = "azure" openai.api_base = self.openai_api_base openai.api_version = self.openai_api_version @@ -82,6 +80,47 @@ class Config(metaclass=Singleton): # Initialize the OpenAI API client openai.api_key = self.openai_api_key + def get_azure_deployment_id_for_model(self, model: str) -> str: + """ + Returns the relevant deployment id for the model specified. + + Parameters: + model(str): The model to map to the deployment id. + + Returns: + The matching deployment id if found, otherwise an empty string. + """ + match model: + case self.fast_llm_model: + return self.azure_model_to_deployment_id_map["fast_llm_model_deployment_id"] + case self.smart_llm_model: + return self.azure_model_to_deployment_id_map["smart_llm_model_deployment_id"] + case "text-embedding-ada-002": + return self.azure_model_to_deployment_id_map["embedding_model_deployment_id"] + case default: + return "" + + AZURE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '..', 'azure.yaml') + + def load_azure_config(self, config_file: str=AZURE_CONFIG_FILE) -> None: + """ + Loads the configuration parameters for Azure hosting from the specified file path as a yaml file. + + Parameters: + config_file(str): The path to the config yaml file. DEFAULT: "../azure.yaml" + + Returns: + None + """ + try: + with open(config_file) as file: + config_params = yaml.load(file, Loader=yaml.FullLoader) + except FileNotFoundError: + config_params = {} + self.openai_api_base = config_params.get("azure_api_base", "") + self.openai_api_version = config_params.get("azure_api_version", "") + self.azure_model_to_deployment_id_map = config_params.get("azure_model_map", []) + def set_continuous_mode(self, value: bool): """Set the continuous mode value.""" self.continuous_mode = value diff --git a/scripts/llm_utils.py b/scripts/llm_utils.py index 94ba5f13..c49aeb09 100644 --- a/scripts/llm_utils.py +++ b/scripts/llm_utils.py @@ -9,7 +9,7 @@ def create_chat_completion(messages, model=None, temperature=None, max_tokens=No """Create a chat completion using the OpenAI API""" if cfg.use_azure: response = openai.ChatCompletion.create( - deployment_id=cfg.openai_deployment_id, + deployment_id=cfg.get_azure_deployment_id_for_model(model), model=model, messages=messages, temperature=temperature, diff --git a/scripts/memory/base.py b/scripts/memory/base.py index 30372851..9df0091e 100644 --- a/scripts/memory/base.py +++ b/scripts/memory/base.py @@ -9,7 +9,7 @@ cfg = Config() def get_ada_embedding(text): text = text.replace("\n", " ") if cfg.use_azure: - return openai.Embedding.create(input=[text], engine=cfg.openai_embedding_deployment_id)["data"][0]["embedding"] + return openai.Embedding.create(input=[text], engine=cfg.get_azure_deployment_id_for_model("text-embedding-ada-002"))["data"][0]["embedding"] else: return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] From 730fbf591fa69a953a5ec66cdf702cdf2725d7ac Mon Sep 17 00:00:00 2001 From: "roby.parapat" Date: Wed, 12 Apr 2023 22:15:22 +0700 Subject: [PATCH 13/34] pull image if it's not found locally --- scripts/execute_code.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/execute_code.py b/scripts/execute_code.py index a8f90911..b281c3eb 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -19,11 +19,28 @@ def execute_python_file(file): try: client = docker.from_env() + image_name = 'python:3.10' + try: + client.images.get(image_name) + print(f"Image '{image_name}' found locally") + except docker.errors.ImageNotFound: + print(f"Image '{image_name}' not found locally, pulling from Docker Hub") + # Use the low-level API to stream the pull response + low_level_client = docker.APIClient() + for line in low_level_client.pull(image_name, stream=True, decode=True): + # Print the status and progress, if available + status = line.get('status') + progress = line.get('progress') + if status and progress: + print(f"{status}: {progress}") + elif status: + print(status) + # You can replace 'python:3.8' with the desired Python image/version # You can find available Python images on Docker Hub: # https://hub.docker.com/_/python container = client.containers.run( - 'python:3.10', + image_name, f'python {file}', volumes={ os.path.abspath(workspace_folder): { From cc9723c26e337e5c7837c5719307d00eca07b561 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Wed, 12 Apr 2023 23:30:35 +0700 Subject: [PATCH 14/34] Make chdir code more robust --- scripts/execute_code.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/execute_code.py b/scripts/execute_code.py index b803d3ba..fb469334 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -54,18 +54,18 @@ def execute_python_file(file): def exec_shell(command_line): - print (f"Executing command '{command_line}' in workspace '{WORKSPACE_FOLDER}'") - args = command_line.split() - base_path = os.getcwd() + old_dir = os.getcwd() - os.chdir(f"{base_path}/{WORKSPACE_FOLDER}") + workdir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', WORKSPACE_FOLDER)) + + print (f"Executing command '{command_line}' in working directory '{workdir}'") + + os.chdir(workdir) result = subprocess.run(args, capture_output=True) output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; - os.chdir(base_path) - - # print(f"Shell execution complete. Output: {output}") + os.chdir(old_dir) return output From 9e8d35277b4b209a4bdd3e62d07d7b6bf0f800e9 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller <5194767+muellerberndt@users.noreply.github.com> Date: Wed, 12 Apr 2023 23:32:17 +0700 Subject: [PATCH 15/34] Update scripts/commands.py Co-authored-by: Peter Stalman --- scripts/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/commands.py b/scripts/commands.py index 07f231e9..d760e477 100644 --- a/scripts/commands.py +++ b/scripts/commands.py @@ -107,7 +107,7 @@ def execute_command(command_name, arguments): if cfg.execute_local_commands: return exec_shell(arguments["command_line"]) else: - return "You are not allowed to run local shell commands. To execute shell commands, EXECUTE_SHELL_COMMANDS must be set to 'True' in your config. Do not attempt to bypass the restriction." + return "You are not allowed to run local shell commands. To execute shell commands, EXECUTE_LOCAL_COMMANDS must be set to 'True' in your config. Do not attempt to bypass the restriction." elif command_name == "generate_image": return generate_image(arguments["prompt"]) elif command_name == "do_nothing": From affe77e18cb4e3dd8892ce13f5f008ff89852dbc Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Wed, 12 Apr 2023 23:46:55 +0700 Subject: [PATCH 16/34] Call subprocess.run with shell=True --- scripts/execute_code.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/execute_code.py b/scripts/execute_code.py index fb469334..18413250 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -54,7 +54,6 @@ def execute_python_file(file): def exec_shell(command_line): - args = command_line.split() old_dir = os.getcwd() workdir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', WORKSPACE_FOLDER)) @@ -63,7 +62,7 @@ def exec_shell(command_line): os.chdir(workdir) - result = subprocess.run(args, capture_output=True) + result = subprocess.run(command_line, capture_output=True, shell=True) output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; os.chdir(old_dir) From c63645cbbafa3c84ee8b46d0e8806ab6d0fc4009 Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Wed, 12 Apr 2023 22:41:23 +0300 Subject: [PATCH 17/34] redo suggested changes. move unit test files to the fitting directory --- scripts/browse.py | 56 ++++++-------------- tests/{ => unit}/test_browse_scrape_links.py | 4 +- tests/{ => unit}/test_browse_scrape_text.py | 0 3 files changed, 17 insertions(+), 43 deletions(-) rename tests/{ => unit}/test_browse_scrape_links.py (100%) rename tests/{ => unit}/test_browse_scrape_text.py (100%) diff --git a/scripts/browse.py b/scripts/browse.py index 046ff6ae..912d5635 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -19,22 +19,13 @@ def is_valid_url(url): def sanitize_url(url): return urljoin(url, urlparse(url).path) -# Function to make a request with a specified timeout and handle exceptions -def make_request(url, timeout=10): - try: - response = requests.get(url, headers=cfg.user_agent_header, timeout=timeout) - response.raise_for_status() - return response - except requests.exceptions.RequestException as e: - return "Error: " + str(e) - # Define and check for local file address prefixes def check_local_file_access(url): # Define and check for local file address prefixes local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost'] return any(url.startswith(prefix) for prefix in local_prefixes) -def get_validated_response(url, headers=cfg.user_agent_header): +def get_response(url, headers=cfg.user_agent_header, timeout=10): try: # Restrict access to local files if check_local_file_access(url): @@ -44,9 +35,14 @@ def get_validated_response(url, headers=cfg.user_agent_header): if not url.startswith('http://') and not url.startswith('https://'): raise ValueError('Invalid URL format') - # Make the HTTP request and return the response - response = requests.get(url, headers=headers) - response.raise_for_status() # Raise an exception if the response contains an HTTP error status code + sanitized_url = sanitize_url(url) + + response = requests.get(sanitized_url, headers=headers, timeout=timeout) + + # Check if the response contains an HTTP error + if response.status_code >= 400: + return None, "Error: HTTP " + str(response.status_code) + " error" + return response, None except ValueError as ve: # Handle invalid URL format @@ -58,29 +54,9 @@ def get_validated_response(url, headers=cfg.user_agent_header): def scrape_text(url): """Scrape text from a webpage""" - # Basic check if the URL is valid - if not url.startswith('http'): - return "Error: Invalid URL" - - # Restrict access to local files - if check_local_file_access(url): - return "Error: Access to local files is restricted" - - # Validate the input URL - if not is_valid_url(url): - # Sanitize the input URL - sanitized_url = sanitize_url(url) - - # Make the request with a timeout and handle exceptions - response = make_request(sanitized_url) - - if isinstance(response, str): - return response - else: - # Sanitize the input URL - sanitized_url = sanitize_url(url) - - response = requests.get(sanitized_url, headers=cfg.user_agent_header) + response, error_message = get_response(url) + if error_message: + return error_message soup = BeautifulSoup(response.text, "html.parser") @@ -113,11 +89,9 @@ def format_hyperlinks(hyperlinks): def scrape_links(url): """Scrape links from a webpage""" - response = requests.get(url, headers=cfg.user_agent_header) - - # Check if the response contains an HTTP error - if response.status_code >= 400: - return "Error: HTTP " + str(response.status_code) + " error" + response, error_message = get_response(url) + if error_message: + return error_message soup = BeautifulSoup(response.text, "html.parser") diff --git a/tests/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py similarity index 100% rename from tests/test_browse_scrape_links.py rename to tests/unit/test_browse_scrape_links.py index b3acf394..fdacf4c0 100644 --- a/tests/test_browse_scrape_links.py +++ b/tests/unit/test_browse_scrape_links.py @@ -1,12 +1,12 @@ # Generated by CodiumAI -from scripts.browse import scrape_links - # Dependencies: # pip install pytest-mock import pytest +from scripts.browse import scrape_links + """ Code Analysis diff --git a/tests/test_browse_scrape_text.py b/tests/unit/test_browse_scrape_text.py similarity index 100% rename from tests/test_browse_scrape_text.py rename to tests/unit/test_browse_scrape_text.py From 57bca3620eb5ccd941726e358b3b4c6c9db33072 Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Wed, 12 Apr 2023 23:04:43 +0300 Subject: [PATCH 18/34] minor style --- scripts/browse.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/browse.py b/scripts/browse.py index 912d5635..78fe4ae2 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -6,7 +6,6 @@ from urllib.parse import urlparse, urljoin cfg = Config() - # Function to check if the URL is valid def is_valid_url(url): try: @@ -21,7 +20,6 @@ def sanitize_url(url): # Define and check for local file address prefixes def check_local_file_access(url): - # Define and check for local file address prefixes local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost'] return any(url.startswith(prefix) for prefix in local_prefixes) From a40ccc1e5de3bfbe2b6c38648e716e33b8182e3a Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Wed, 12 Apr 2023 23:53:40 +0300 Subject: [PATCH 19/34] flake8 style --- tests/unit/test_browse_scrape_links.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py index fdacf4c0..9b69b27b 100644 --- a/tests/unit/test_browse_scrape_links.py +++ b/tests/unit/test_browse_scrape_links.py @@ -112,4 +112,4 @@ class TestScrapeLinks: assert len(result) == 3 assert result[0] == "Google (https://www.google.com)" assert result[1] == "GitHub (https://github.com)" - assert result[2] == "CodiumAI (https://www.codium.ai)" \ No newline at end of file + assert result[2] == "CodiumAI (https://www.codium.ai)" From 9f972f4ee9c938c9e64dcc314b920e66c53b3c45 Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Thu, 13 Apr 2023 00:00:33 +0300 Subject: [PATCH 20/34] flake8 style --- scripts/browse.py | 7 ++++++- tests/unit/test_browse_scrape_links.py | 10 ++++++---- tests/unit/test_browse_scrape_text.py | 5 +++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/browse.py b/scripts/browse.py index 6d473ed6..e224b04d 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -6,6 +6,7 @@ from urllib.parse import urlparse, urljoin cfg = Config() + # Function to check if the URL is valid def is_valid_url(url): try: @@ -14,15 +15,18 @@ def is_valid_url(url): except ValueError: return False + # Function to sanitize the URL def sanitize_url(url): return urljoin(url, urlparse(url).path) + # Define and check for local file address prefixes def check_local_file_access(url): local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost'] return any(url.startswith(prefix) for prefix in local_prefixes) + def get_response(url, headers=cfg.user_agent_header, timeout=10): try: # Restrict access to local files @@ -33,7 +37,6 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): if not url.startswith('http://') and not url.startswith('https://'): raise ValueError('Invalid URL format') - sanitized_url = sanitize_url(url) response = requests.get(sanitized_url, headers=headers, timeout=timeout) @@ -51,6 +54,7 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): # Handle exceptions related to the HTTP request (e.g., connection errors, timeouts, etc.) return None, "Error: " + str(re) + def scrape_text(url): """Scrape text from a webpage""" response, error_message = get_response(url) @@ -128,6 +132,7 @@ def create_message(chunk, question): "content": f"\"\"\"{chunk}\"\"\" Using the above text, please answer the following question: \"{question}\" -- if the question cannot be answered using the text, please summarize the text." } + def summarize_text(text, question): """Summarize text using the LLM model""" if not text: diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py index 9b69b27b..639987a2 100644 --- a/tests/unit/test_browse_scrape_links.py +++ b/tests/unit/test_browse_scrape_links.py @@ -11,7 +11,8 @@ from scripts.browse import scrape_links Code Analysis Objective: -The objective of the 'scrape_links' function is to scrape hyperlinks from a given URL and return them in a formatted way. +The objective of the 'scrape_links' function is to scrape hyperlinks from a +given URL and return them in a formatted way. Inputs: - url: a string representing the URL to be scraped. @@ -29,17 +30,18 @@ Outputs: - A list of formatted hyperlinks. Additional aspects: -- The function uses the 'requests' and 'BeautifulSoup' libraries to send HTTP requests and parse HTML content, respectively. +- The function uses the 'requests' and 'BeautifulSoup' libraries to send HTTP +requests and parse HTML content, respectively. - The 'extract_hyperlinks' function is called to extract hyperlinks from the parsed HTML. - The 'format_hyperlinks' function is called to format the extracted hyperlinks. - The function checks for HTTP errors and returns "error" if any are found. """ - class TestScrapeLinks: - # Tests that the function returns a list of formatted hyperlinks when provided with a valid url that returns a webpage with hyperlinks. + # Tests that the function returns a list of formatted hyperlinks when + # provided with a valid url that returns a webpage with hyperlinks. def test_valid_url_with_hyperlinks(self): url = "https://www.google.com" result = scrape_links(url) diff --git a/tests/unit/test_browse_scrape_text.py b/tests/unit/test_browse_scrape_text.py index 775eefcd..76072276 100644 --- a/tests/unit/test_browse_scrape_text.py +++ b/tests/unit/test_browse_scrape_text.py @@ -2,7 +2,6 @@ # Generated by CodiumAI import requests -import tests.context from scripts.browse import scrape_text @@ -10,7 +9,8 @@ from scripts.browse import scrape_text Code Analysis Objective: -The objective of the "scrape_text" function is to scrape the text content from a given URL and return it as a string, after removing any unwanted HTML tags and scripts. +The objective of the "scrape_text" function is to scrape the text content from +a given URL and return it as a string, after removing any unwanted HTML tags and scripts. Inputs: - url: a string representing the URL of the webpage to be scraped. @@ -33,6 +33,7 @@ Additional aspects: - The function uses a generator expression to split the text into lines and chunks, which can improve performance for large amounts of text. """ + class TestScrapeText: # Tests that scrape_text() returns the expected text when given a valid URL. From bf3c76ced73d6620ef895e96e6c5c55e1a6e37bc Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Thu, 13 Apr 2023 00:04:08 +0300 Subject: [PATCH 21/34] flake8 style --- scripts/browse.py | 4 ++-- tests/unit/test_browse_scrape_links.py | 19 ++++++++++--------- tests/unit/test_browse_scrape_text.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/browse.py b/scripts/browse.py index e224b04d..c26cde65 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -32,7 +32,7 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): # Restrict access to local files if check_local_file_access(url): raise ValueError('Access to local files is restricted') - + # Most basic check if the URL is valid: if not url.startswith('http://') and not url.startswith('https://'): raise ValueError('Invalid URL format') @@ -44,7 +44,7 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): # Check if the response contains an HTTP error if response.status_code >= 400: return None, "Error: HTTP " + str(response.status_code) + " error" - + return response, None except ValueError as ve: # Handle invalid URL format diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py index 639987a2..bd57fb84 100644 --- a/tests/unit/test_browse_scrape_links.py +++ b/tests/unit/test_browse_scrape_links.py @@ -11,7 +11,7 @@ from scripts.browse import scrape_links Code Analysis Objective: -The objective of the 'scrape_links' function is to scrape hyperlinks from a +The objective of the 'scrape_links' function is to scrape hyperlinks from a given URL and return them in a formatted way. Inputs: @@ -30,7 +30,7 @@ Outputs: - A list of formatted hyperlinks. Additional aspects: -- The function uses the 'requests' and 'BeautifulSoup' libraries to send HTTP +- The function uses the 'requests' and 'BeautifulSoup' libraries to send HTTP requests and parse HTML content, respectively. - The 'extract_hyperlinks' function is called to extract hyperlinks from the parsed HTML. - The 'format_hyperlinks' function is called to format the extracted hyperlinks. @@ -40,16 +40,16 @@ requests and parse HTML content, respectively. class TestScrapeLinks: - # Tests that the function returns a list of formatted hyperlinks when - # provided with a valid url that returns a webpage with hyperlinks. + # Tests that the function returns a list of formatted hyperlinks when + # provided with a valid url that returns a webpage with hyperlinks. def test_valid_url_with_hyperlinks(self): url = "https://www.google.com" result = scrape_links(url) assert len(result) > 0 assert isinstance(result, list) assert isinstance(result[0], str) - - # Tests that the function returns correctly formatted hyperlinks when given a valid url. + + # Tests that the function returns correctly formatted hyperlinks when given a valid url. def test_valid_url(self, mocker): # Mock the requests.get() function to return a response with sample HTML containing hyperlinks mock_response = mocker.Mock() @@ -63,7 +63,7 @@ class TestScrapeLinks: # Assert that the function returns correctly formatted hyperlinks assert result == ["Google (https://www.google.com)"] - # Tests that the function returns "error" when given an invalid url. + # Tests that the function returns "error" when given an invalid url. def test_invalid_url(self, mocker): # Mock the requests.get() function to return an HTTP error response mock_response = mocker.Mock() @@ -76,7 +76,7 @@ class TestScrapeLinks: # Assert that the function returns "error" assert "Error:" in result - # Tests that the function returns an empty list when the html contains no hyperlinks. + # Tests that the function returns an empty list when the html contains no hyperlinks. def test_no_hyperlinks(self, mocker): # Mock the requests.get() function to return a response with sample HTML containing no hyperlinks mock_response = mocker.Mock() @@ -90,7 +90,8 @@ class TestScrapeLinks: # Assert that the function returns an empty list assert result == [] - # Tests that scrape_links() correctly extracts and formats hyperlinks from a sample HTML containing a few hyperlinks. + # Tests that scrape_links() correctly extracts and formats hyperlinks from + # a sample HTML containing a few hyperlinks. def test_scrape_links_with_few_hyperlinks(self, mocker): # Mock the requests.get() function to return a response with a sample HTML containing hyperlinks mock_response = mocker.Mock() diff --git a/tests/unit/test_browse_scrape_text.py b/tests/unit/test_browse_scrape_text.py index 76072276..9385cde7 100644 --- a/tests/unit/test_browse_scrape_text.py +++ b/tests/unit/test_browse_scrape_text.py @@ -9,7 +9,7 @@ from scripts.browse import scrape_text Code Analysis Objective: -The objective of the "scrape_text" function is to scrape the text content from +The objective of the "scrape_text" function is to scrape the text content from a given URL and return it as a string, after removing any unwanted HTML tags and scripts. Inputs: From 3e53e976a52004179a9fc42b224a4b3bcdd8738a Mon Sep 17 00:00:00 2001 From: Itamar Friedman Date: Thu, 13 Apr 2023 00:06:23 +0300 Subject: [PATCH 22/34] flake8 style --- scripts/browse.py | 4 ++-- tests/unit/test_browse_scrape_links.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/browse.py b/scripts/browse.py index c26cde65..9e93c55a 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -32,7 +32,7 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): # Restrict access to local files if check_local_file_access(url): raise ValueError('Access to local files is restricted') - + # Most basic check if the URL is valid: if not url.startswith('http://') and not url.startswith('https://'): raise ValueError('Invalid URL format') @@ -44,7 +44,7 @@ def get_response(url, headers=cfg.user_agent_header, timeout=10): # Check if the response contains an HTTP error if response.status_code >= 400: return None, "Error: HTTP " + str(response.status_code) + " error" - + return response, None except ValueError as ve: # Handle invalid URL format diff --git a/tests/unit/test_browse_scrape_links.py b/tests/unit/test_browse_scrape_links.py index bd57fb84..2172d1a2 100644 --- a/tests/unit/test_browse_scrape_links.py +++ b/tests/unit/test_browse_scrape_links.py @@ -48,7 +48,7 @@ class TestScrapeLinks: assert len(result) > 0 assert isinstance(result, list) assert isinstance(result[0], str) - + # Tests that the function returns correctly formatted hyperlinks when given a valid url. def test_valid_url(self, mocker): # Mock the requests.get() function to return a response with sample HTML containing hyperlinks @@ -90,7 +90,7 @@ class TestScrapeLinks: # Assert that the function returns an empty list assert result == [] - # Tests that scrape_links() correctly extracts and formats hyperlinks from + # Tests that scrape_links() correctly extracts and formats hyperlinks from # a sample HTML containing a few hyperlinks. def test_scrape_links_with_few_hyperlinks(self, mocker): # Mock the requests.get() function to return a response with a sample HTML containing hyperlinks From 4faba1fdd8bb0b25deabdb177a6522c3c242f512 Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Wed, 12 Apr 2023 14:50:35 -0700 Subject: [PATCH 23/34] Add temperature configuration option to Config class --- scripts/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/config.py b/scripts/config.py index 255587d7..cec7688b 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -43,6 +43,7 @@ class Config(metaclass=Singleton): self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000)) self.openai_api_key = os.getenv("OPENAI_API_KEY") + self.temperature = int(os.getenv("TEMPERATURE", "1")) self.use_azure = False self.use_azure = os.getenv("USE_AZURE") == 'True' if self.use_azure: From f4831348e8eea3654af3745189fde8ca8884c6fd Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Wed, 12 Apr 2023 14:50:35 -0700 Subject: [PATCH 24/34] Use configured temperature value in create_chat_completion function --- scripts/llm_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/llm_utils.py b/scripts/llm_utils.py index 3fb348f0..8acafc91 100644 --- a/scripts/llm_utils.py +++ b/scripts/llm_utils.py @@ -5,7 +5,7 @@ cfg = Config() openai.api_key = cfg.openai_api_key # Overly simple abstraction until we create something better -def create_chat_completion(messages, model=None, temperature=None, max_tokens=None)->str: +def create_chat_completion(messages, model=None, temperature=cfg.temperature, max_tokens=None)->str: """Create a chat completion using the OpenAI API""" if cfg.use_azure: response = openai.ChatCompletion.create( From 046c49c90b5b2460eaf655d0bf15aca20eee45ea Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Wed, 12 Apr 2023 16:28:21 -0700 Subject: [PATCH 25/34] add temperature to .env.template --- .env.template | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.template b/.env.template index 4694aca0..c6d1a48e 100644 --- a/.env.template +++ b/.env.template @@ -1,6 +1,7 @@ PINECONE_API_KEY=your-pinecone-api-key PINECONE_ENV=your-pinecone-region OPENAI_API_KEY=your-openai-api-key +TEMPERATURE=1 ELEVENLABS_API_KEY=your-elevenlabs-api-key ELEVENLABS_VOICE_1_ID=your-voice-id ELEVENLABS_VOICE_2_ID=your-voice-id From c594200195806cad79e4e1125cbfb0511a3de4a6 Mon Sep 17 00:00:00 2001 From: vadi Date: Thu, 13 Apr 2023 10:01:52 +1000 Subject: [PATCH 26/34] Remove duplicated unnecessary config instance --- scripts/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/main.py b/scripts/main.py index 7a4a32d4..81f560b2 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -318,7 +318,6 @@ def parse_arguments(): # TODO: fill in llm values here check_openai_api_key() -cfg = Config() parse_arguments() logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO) ai_name = "" From 91d1f3eca8989bd44d31b1e148fd1703012b6538 Mon Sep 17 00:00:00 2001 From: 511 <15816056+fqd511@users.noreply.github.com> Date: Thu, 13 Apr 2023 11:43:09 +0800 Subject: [PATCH 27/34] add link for pinecone in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9ef9d5c..caa0a473 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ MEMORY_INDEX=whatever Pinecone enables the storage of vast amounts of vector-based memory, allowing for only relevant memories to be loaded for the agent at any given time. -1. Go to app.pinecone.io and make an account if you don't already have one. +1. Go to [pinecone](https://app.pinecone.io/) and make an account if you don't already have one. 2. Choose the `Starter` plan to avoid being charged. 3. Find your API key and region under the default project in the left sidebar. @@ -344,4 +344,4 @@ flake8 scripts/ tests/ # Or, if you want to run flake8 with the same configuration as the CI: flake8 scripts/ tests/ --select E303,W293,W291,W292,E305 -``` \ No newline at end of file +``` From 3ff23234507b27aa57f9f83104eea71924fe26ff Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Thu, 13 Apr 2023 11:04:26 +0700 Subject: [PATCH 28/34] Rename command & functions to execute_shell --- scripts/commands.py | 6 +++--- scripts/data/prompt.txt | 2 +- scripts/execute_code.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/commands.py b/scripts/commands.py index d760e477..3966e86a 100644 --- a/scripts/commands.py +++ b/scripts/commands.py @@ -7,7 +7,7 @@ import speak from config import Config import ai_functions as ai from file_operations import read_file, write_to_file, append_to_file, delete_file, search_files -from execute_code import execute_python_file, exec_shell +from execute_code import execute_python_file, execute_shell from json_parser import fix_and_parse_json from image_gen import generate_image from duckduckgo_search import ddg @@ -103,9 +103,9 @@ def execute_command(command_name, arguments): return ai.write_tests(arguments["code"], arguments.get("focus")) elif command_name == "execute_python_file": # Add this command return execute_python_file(arguments["file"]) - elif command_name == "exec_shell": + elif command_name == "execute_shell": if cfg.execute_local_commands: - return exec_shell(arguments["command_line"]) + return execute_shell(arguments["command_line"]) else: return "You are not allowed to run local shell commands. To execute shell commands, EXECUTE_LOCAL_COMMANDS must be set to 'True' in your config. Do not attempt to bypass the restriction." elif command_name == "generate_image": diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txt index 4484108b..ffb9eb50 100644 --- a/scripts/data/prompt.txt +++ b/scripts/data/prompt.txt @@ -22,7 +22,7 @@ COMMANDS: 16. Get Improved Code: "improve_code", args: "suggestions": "", "code": "" 17. Write Tests: "write_tests", args: "code": "", "focus": "" 18. Execute Python File: "execute_python_file", args: "file": "" -19. Execute Shell Command, non-interactive commands only: "exec_shell", args: "command_line": "". +19. Execute Shell Command, non-interactive commands only: "execute_shell", args: "command_line": "". 20. Task Complete (Shutdown): "task_complete", args: "reason": "" 21. Generate Image: "generate_image", args: "prompt": "" 22. Do Nothing: "do_nothing", args: "" diff --git a/scripts/execute_code.py b/scripts/execute_code.py index 18413250..fa55a7f7 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -52,7 +52,7 @@ def execute_python_file(file): -def exec_shell(command_line): +def execute_shell(command_line): old_dir = os.getcwd() From 946700fcf7bf6b14b02ee7f4c8c8417ba21b2cfe Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Thu, 13 Apr 2023 11:27:43 +0700 Subject: [PATCH 29/34] Change workdir logic --- scripts/execute_code.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/execute_code.py b/scripts/execute_code.py index fa55a7f7..54944b32 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -54,17 +54,19 @@ def execute_python_file(file): def execute_shell(command_line): - old_dir = os.getcwd() + current_dir = os.getcwd() - workdir = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', WORKSPACE_FOLDER)) + if not WORKSPACE_FOLDER in current_dir: # Change dir into workspace if necessary + work_dir = os.path.join(os.getcwd(), WORKSPACE_FOLDER) + os.chdir(work_dir) - print (f"Executing command '{command_line}' in working directory '{workdir}'") - - os.chdir(workdir) + print (f"Executing command '{command_line}' in working directory '{os.getcwd()}'") result = subprocess.run(command_line, capture_output=True, shell=True) - output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; + output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}" - os.chdir(old_dir) + # Change back to whatever the prior working dir was + + os.chdir(current_dir) return output From f79c7c4d1e624c73e63e1dc22641be757ffa5320 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Thu, 13 Apr 2023 12:43:25 +0700 Subject: [PATCH 30/34] Fix linter errors --- scripts/config.py | 2 +- scripts/execute_code.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index e6cbb866..c0fad281 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -46,7 +46,7 @@ class Config(metaclass=Singleton): self.use_azure = False self.use_azure = os.getenv("USE_AZURE") == 'True' self.execute_local_commands = os.getenv('EXECUTE_LOCAL_COMMANDS', 'False') == 'True' - + if self.use_azure: self.openai_api_base = os.getenv("OPENAI_AZURE_API_BASE") self.openai_api_version = os.getenv("OPENAI_AZURE_API_VERSION") diff --git a/scripts/execute_code.py b/scripts/execute_code.py index 54944b32..806767e2 100644 --- a/scripts/execute_code.py +++ b/scripts/execute_code.py @@ -49,8 +49,6 @@ def execute_python_file(file): except Exception as e: return f"Error: {str(e)}" - - def execute_shell(command_line): From 9f2d609be3760d40529dab95621bf4c04616be7f Mon Sep 17 00:00:00 2001 From: sagarishere <5121817+sagarishere@users.noreply.github.com> Date: Thu, 13 Apr 2023 09:24:15 +0300 Subject: [PATCH 31/34] Update .gitignore Added ignoring .DS_Store for mac environments. It can be assumed that some developers may not have global .gitignore settings for their environments. This will ease the friction of rejected push, commit rollback, again putting changes from stashes and then again pushing. Can save precious time for some devs using Mac systems. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index cfa3b08b..6c83aa3b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ log.txt .coverage coverage.xml htmlcov/ + +# For Macs Dev Environs: ignoring .Desktop Services_Store +.DS_Store From bc4bca65d58c38d34cbd3f40317e3ee12e45de40 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Thu, 13 Apr 2023 08:29:07 +0200 Subject: [PATCH 32/34] Fix for python < 3.10 --- .gitignore | 2 ++ scripts/config.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index cfa3b08b..601751fb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,11 @@ package-lock.json auto_gpt_workspace/* *.mpeg .env +azure.yaml *venv/* outputs/* ai_settings.yaml +last_run_ai_settings.yaml .vscode .idea/* auto-gpt.json diff --git a/scripts/config.py b/scripts/config.py index 19a9eb88..77b06676 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -92,15 +92,14 @@ class Config(metaclass=Singleton): Returns: The matching deployment id if found, otherwise an empty string. """ - match model: - case self.fast_llm_model: - return self.azure_model_to_deployment_id_map["fast_llm_model_deployment_id"] - case self.smart_llm_model: - return self.azure_model_to_deployment_id_map["smart_llm_model_deployment_id"] - case "text-embedding-ada-002": - return self.azure_model_to_deployment_id_map["embedding_model_deployment_id"] - case default: - return "" + if model == self.fast_llm_model: + return self.azure_model_to_deployment_id_map["fast_llm_model_deployment_id"] + elif model == self.smart_llm_model: + return self.azure_model_to_deployment_id_map["smart_llm_model_deployment_id"] + elif model == "text-embedding-ada-002": + return self.azure_model_to_deployment_id_map["embedding_model_deployment_id"] + else: + return "" AZURE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '..', 'azure.yaml') From 285627e2168db9bdbb7ebd982228e5ef3c7d1f07 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Thu, 13 Apr 2023 08:41:18 +0200 Subject: [PATCH 33/34] remove trailing whitespace --- scripts/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/config.py b/scripts/config.py index e4fa29ac..ebf1b08b 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -102,7 +102,7 @@ class Config(metaclass=Singleton): elif model == "text-embedding-ada-002": return self.azure_model_to_deployment_id_map["embedding_model_deployment_id"] else: - return "" + return "" AZURE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '..', 'azure.yaml') From e635cf4a4ac48c3ba9399ddc90439086c1401990 Mon Sep 17 00:00:00 2001 From: Andy Melnikov Date: Wed, 12 Apr 2023 21:15:00 +0200 Subject: [PATCH 34/34] Fix flake8 E303,W293,W291,W292,E305 Some of the previously fixed things creeped in. I would like to keep the requirements low on the PR authors for now and gradually improve the pep8 compliance without introducing much breakage. --- scripts/ai_functions.py | 1 + scripts/logger.py | 2 -- tests.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/ai_functions.py b/scripts/ai_functions.py index 782bb558..8c95c0f2 100644 --- a/scripts/ai_functions.py +++ b/scripts/ai_functions.py @@ -45,6 +45,7 @@ def improve_code(suggestions: List[str], code: str) -> str: result_string = call_ai_function(function_string, args, description_string) return result_string + def write_tests(code: str, focus: List[str]) -> str: """ A function that takes in code and focus topics and returns a response from create chat completion api call. diff --git a/scripts/logger.py b/scripts/logger.py index 5c7d68bb..85dde813 100644 --- a/scripts/logger.py +++ b/scripts/logger.py @@ -164,8 +164,6 @@ class ConsoleHandler(logging.StreamHandler): Allows to handle custom placeholders 'title_color' and 'message_no_color'. To use this formatter, make sure to pass 'color', 'title' as log extras. ''' - - class AutoGptFormatter(logging.Formatter): def format(self, record: LogRecord) -> str: if (hasattr(record, 'color')): diff --git a/tests.py b/tests.py index ce21c1f4..4dbfdd46 100644 --- a/tests.py +++ b/tests.py @@ -3,6 +3,6 @@ import unittest if __name__ == "__main__": # Load all tests from the 'scripts/tests' package suite = unittest.defaultTestLoader.discover('scripts/tests') - + # Run the tests unittest.TextTestRunner().run(suite)