Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

test

  1. User

    test

  2. Assistant

    This is a test response. Please provide more context or questions so I can give a more accurate response.

  3. User

    how do I use chatgpt in python without an API key with requests

  4. Assistant

    To use ChatGPT in Python without an API key using the requests library, you can make HTTP POST requests to the OpenAI API. Here's an example:

    import requests
    
    def interact_with_chatgpt(prompt):
        # Replace with your ChatGPT model access token
        model_access_token = 'abc123'
    
        # Make a POST request to the OpenAI API
        response = requests.post(
            'https://api.openai.com/v1/chat/completions',
            headers={
                'Authorization': f'Bearer {model_access_token}',
                'Content-Type': 'application/json',
            },
            json={
                'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'},
                             {'role': 'user', 'content': prompt}]
            }
        )
    
        # Get the reply from the API response
        reply = response.json()['choices'][0]['message']['content']
        return reply
    
    # Example usage
    prompt = 'What is the capital of France?'
    reply = interact_with_chatgpt(prompt)
    print(reply)
    

    Make sure to provide your actual ChatGPT model access token in the model_access_token variable. You can find your access token in your OpenAI account. Also, note that the chat conversation history is passed as a list of messages in the json payload.

    Keep in mind that starting March 1st, 2023, usage of ChatGPT via the API will be billed separately. Refer to the OpenAI documentation to learn more about authentication and pricing details.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.