mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
resolved latest conflicts
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
5
tests/context.py
Normal file
5
tests/context.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), '../scripts')))
|
||||
49
tests/integration/memory_tests.py
Normal file
49
tests/integration/memory_tests.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import unittest
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
from pathlib import Path
|
||||
# Add the parent directory of the 'scripts' folder to the Python path
|
||||
sys.path.append(str(Path(__file__).resolve().parent.parent.parent / 'scripts'))
|
||||
from config import Config
|
||||
from memory.local import LocalCache
|
||||
|
||||
class TestLocalCache(unittest.TestCase):
|
||||
|
||||
def random_string(self, length):
|
||||
return ''.join(random.choice(string.ascii_letters) for _ in range(length))
|
||||
|
||||
def setUp(self):
|
||||
cfg = cfg = Config()
|
||||
self.cache = LocalCache(cfg)
|
||||
self.cache.clear()
|
||||
|
||||
# Add example texts to the cache
|
||||
self.example_texts = [
|
||||
'The quick brown fox jumps over the lazy dog',
|
||||
'I love machine learning and natural language processing',
|
||||
'The cake is a lie, but the pie is always true',
|
||||
'ChatGPT is an advanced AI model for conversation'
|
||||
]
|
||||
|
||||
for text in self.example_texts:
|
||||
self.cache.add(text)
|
||||
|
||||
# Add some random strings to test noise
|
||||
for _ in range(5):
|
||||
self.cache.add(self.random_string(10))
|
||||
|
||||
def test_get_relevant(self):
|
||||
query = "I'm interested in artificial intelligence and NLP"
|
||||
k = 3
|
||||
relevant_texts = self.cache.get_relevant(query, k)
|
||||
|
||||
print(f"Top {k} relevant texts for the query '{query}':")
|
||||
for i, text in enumerate(relevant_texts, start=1):
|
||||
print(f"{i}. {text}")
|
||||
|
||||
self.assertEqual(len(relevant_texts), k)
|
||||
self.assertIn(self.example_texts[1], relevant_texts)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,7 +2,7 @@
|
||||
# Generated by CodiumAI
|
||||
|
||||
import requests
|
||||
import pytest
|
||||
import tests.context
|
||||
|
||||
from scripts.browse import scrape_text
|
||||
|
||||
|
||||
58
tests/test_config.py
Normal file
58
tests/test_config.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import unittest
|
||||
from scripts.config import Config
|
||||
|
||||
class TestConfig(unittest.TestCase):
|
||||
|
||||
def test_singleton(self):
|
||||
config1 = Config()
|
||||
config2 = Config()
|
||||
self.assertIs(config1, config2)
|
||||
|
||||
def test_initial_values(self):
|
||||
config = Config()
|
||||
self.assertFalse(config.debug_mode)
|
||||
self.assertFalse(config.continuous_mode)
|
||||
self.assertFalse(config.speak_mode)
|
||||
self.assertEqual(config.fast_llm_model, "gpt-3.5-turbo")
|
||||
self.assertEqual(config.smart_llm_model, "gpt-4")
|
||||
self.assertEqual(config.fast_token_limit, 4000)
|
||||
self.assertEqual(config.smart_token_limit, 8000)
|
||||
|
||||
def test_set_continuous_mode(self):
|
||||
config = Config()
|
||||
config.set_continuous_mode(True)
|
||||
self.assertTrue(config.continuous_mode)
|
||||
|
||||
def test_set_speak_mode(self):
|
||||
config = Config()
|
||||
config.set_speak_mode(True)
|
||||
self.assertTrue(config.speak_mode)
|
||||
|
||||
def test_set_fast_llm_model(self):
|
||||
config = Config()
|
||||
config.set_fast_llm_model("gpt-3.5-turbo-test")
|
||||
self.assertEqual(config.fast_llm_model, "gpt-3.5-turbo-test")
|
||||
|
||||
def test_set_smart_llm_model(self):
|
||||
config = Config()
|
||||
config.set_smart_llm_model("gpt-4-test")
|
||||
self.assertEqual(config.smart_llm_model, "gpt-4-test")
|
||||
|
||||
def test_set_fast_token_limit(self):
|
||||
config = Config()
|
||||
config.set_fast_token_limit(5000)
|
||||
self.assertEqual(config.fast_token_limit, 5000)
|
||||
|
||||
def test_set_smart_token_limit(self):
|
||||
config = Config()
|
||||
config.set_smart_token_limit(9000)
|
||||
self.assertEqual(config.smart_token_limit, 9000)
|
||||
|
||||
def test_set_debug_mode(self):
|
||||
config = Config()
|
||||
config.set_debug_mode(True)
|
||||
self.assertTrue(config.debug_mode)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
113
tests/test_json_parser.py
Normal file
113
tests/test_json_parser.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import unittest
|
||||
import tests.context
|
||||
|
||||
from scripts.json_parser import fix_and_parse_json
|
||||
|
||||
class TestParseJson(unittest.TestCase):
|
||||
def test_valid_json(self):
|
||||
# Test that a valid JSON string is parsed correctly
|
||||
json_str = '{"name": "John", "age": 30, "city": "New York"}'
|
||||
obj = fix_and_parse_json(json_str)
|
||||
self.assertEqual(obj, {"name": "John", "age": 30, "city": "New York"})
|
||||
|
||||
def test_invalid_json_minor(self):
|
||||
# Test that an invalid JSON string can be fixed with gpt
|
||||
json_str = '{"name": "John", "age": 30, "city": "New York",}'
|
||||
self.assertRaises(Exception, fix_and_parse_json, json_str, try_to_fix_with_gpt=False)
|
||||
|
||||
def test_invalid_json_major_with_gpt(self):
|
||||
# Test that an invalid JSON string raises an error when try_to_fix_with_gpt is False
|
||||
json_str = 'BEGIN: "name": "John" - "age": 30 - "city": "New York" :END'
|
||||
self.assertRaises(Exception, fix_and_parse_json, json_str, try_to_fix_with_gpt=False)
|
||||
|
||||
def test_invalid_json_major_without_gpt(self):
|
||||
# Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False
|
||||
json_str = 'BEGIN: "name": "John" - "age": 30 - "city": "New York" :END'
|
||||
# Assert that this raises an exception:
|
||||
with self.assertRaises(Exception):
|
||||
fix_and_parse_json(json_str, try_to_fix_with_gpt=False)
|
||||
|
||||
def test_invalid_json_leading_sentence_with_gpt(self):
|
||||
# Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False
|
||||
json_str = """I suggest we start by browsing the repository to find any issues that we can fix.
|
||||
|
||||
{
|
||||
"command": {
|
||||
"name": "browse_website",
|
||||
"args":{
|
||||
"url": "https://github.com/Torantulino/Auto-GPT"
|
||||
}
|
||||
},
|
||||
"thoughts":
|
||||
{
|
||||
"text": "I suggest we start browsing the repository to find any issues that we can fix.",
|
||||
"reasoning": "Browsing the repository will give us an idea of the current state of the codebase and identify any issues that we can address to improve the repo.",
|
||||
"plan": "- Look through the repository to find any issues.\n- Investigate any issues to determine what needs to be fixed\n- Identify possible solutions to fix the issues\n- Open Pull Requests with fixes",
|
||||
"criticism": "I should be careful while browsing so as not to accidentally introduce any new bugs or issues.",
|
||||
"speak": "I will start browsing the repository to find any issues we can fix."
|
||||
}
|
||||
}"""
|
||||
good_obj = {
|
||||
"command": {
|
||||
"name": "browse_website",
|
||||
"args":{
|
||||
"url": "https://github.com/Torantulino/Auto-GPT"
|
||||
}
|
||||
},
|
||||
"thoughts":
|
||||
{
|
||||
"text": "I suggest we start browsing the repository to find any issues that we can fix.",
|
||||
"reasoning": "Browsing the repository will give us an idea of the current state of the codebase and identify any issues that we can address to improve the repo.",
|
||||
"plan": "- Look through the repository to find any issues.\n- Investigate any issues to determine what needs to be fixed\n- Identify possible solutions to fix the issues\n- Open Pull Requests with fixes",
|
||||
"criticism": "I should be careful while browsing so as not to accidentally introduce any new bugs or issues.",
|
||||
"speak": "I will start browsing the repository to find any issues we can fix."
|
||||
}
|
||||
}
|
||||
# Assert that this raises an exception:
|
||||
self.assertEqual(fix_and_parse_json(json_str, try_to_fix_with_gpt=False), good_obj)
|
||||
|
||||
|
||||
|
||||
def test_invalid_json_leading_sentence_with_gpt(self):
|
||||
# Test that a REALLY invalid JSON string raises an error when try_to_fix_with_gpt is False
|
||||
json_str = """I will first need to browse the repository (https://github.com/Torantulino/Auto-GPT) and identify any potential bugs that need fixing. I will use the "browse_website" command for this.
|
||||
|
||||
{
|
||||
"command": {
|
||||
"name": "browse_website",
|
||||
"args":{
|
||||
"url": "https://github.com/Torantulino/Auto-GPT"
|
||||
}
|
||||
},
|
||||
"thoughts":
|
||||
{
|
||||
"text": "Browsing the repository to identify potential bugs",
|
||||
"reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.",
|
||||
"plan": "- Analyze the repository for potential bugs and areas of improvement",
|
||||
"criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.",
|
||||
"speak": "I am browsing the repository to identify potential bugs."
|
||||
}
|
||||
}"""
|
||||
good_obj = {
|
||||
"command": {
|
||||
"name": "browse_website",
|
||||
"args":{
|
||||
"url": "https://github.com/Torantulino/Auto-GPT"
|
||||
}
|
||||
},
|
||||
"thoughts":
|
||||
{
|
||||
"text": "Browsing the repository to identify potential bugs",
|
||||
"reasoning": "Before fixing bugs, I need to identify what needs fixing. I will use the 'browse_website' command to analyze the repository.",
|
||||
"plan": "- Analyze the repository for potential bugs and areas of improvement",
|
||||
"criticism": "I need to ensure I am thorough and pay attention to detail while browsing the repository.",
|
||||
"speak": "I am browsing the repository to identify potential bugs."
|
||||
}
|
||||
}
|
||||
# Assert that this raises an exception:
|
||||
self.assertEqual(fix_and_parse_json(json_str, try_to_fix_with_gpt=False), good_obj)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user