gpt4free icon indicating copy to clipboard operation
gpt4free copied to clipboard

unit test for api status

Open repollo opened this issue 1 year ago • 2 comments

Hello all, I've been thinking about this and was wondering if there is any discussion on the standards for testing the methods and getting a live api status of each endpoint. Do we want to use unittest like below or is there another option?

import unittest
import ora, phind, quora, t3nsor, writesonic, sqlchat


class TestAPIs(unittest.TestCase):
    
    def test_ora_api(self):
        prompt = "What is the capital of France?"
        response = ora.Completion.create(prompt=prompt)

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)
        
    def test_phind_api(self):
        # set cf_clearance cookie
        phind.cf_clearance = 'heguhSRBB9d0sjLvGbQECS8b80m2BQ31xEmk9ChshKI-1682268995-0-160'
        phind.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
        prompt = "What is the capital of France?"
        response = phind.Completion.create(
            model  = 'gpt-4',
            prompt = prompt,
            results     = phind.Search.create(prompt, actualSearch = False), # create search (set actualSearch to False to disable internet)
            creative    = False,
            detailed    = False,
            codeContext = '') 

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)
        
    def test_quora_api(self):
        prompt = "What is the capital of France?"
        response = quora.Completion.create(prompt=prompt)

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)
        
    
    def test_t3nsor_api(self):
        prompt = "What is the capital of France?"
        response = t3nsor.Completion.create(prompt=prompt)

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)

    def test_writesonic_api(self):
        prompt = "What is the capital of France?"
        response = writesonic.Completion.create(prompt=prompt)

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)
    
    def test_sqlchat_api(self):
        prompt = "What is the capital of France?"
        response = sqlchat.Completion.create(prompt=prompt)

        self.assertIsNotNone(response)
        self.assertIsNotNone(response.completion.choices)
        self.assertGreater(len(response.completion.choices[0].text), 0)


if __name__ == '__main__':
    unittest.main()

Or should it be a general testing class which provides a boolean of each endpoint and/or provides a json of which methods of each endpoint are up or down? What are your thoughts?

repollo avatar Apr 24 '23 21:04 repollo

yes this looks good, and I think we should rather look for a general exact response of the api and not compare response values as it may be random

xtekky avatar Apr 24 '23 22:04 xtekky

you can always do a PR

xtekky avatar Apr 25 '23 09:04 xtekky