mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-02-23 15:49:50 +01:00
Fix to enable regular OpenAI access
This commit is contained in:
@@ -174,33 +174,25 @@ def stream_gpt_completion(data, req_type):
|
|||||||
|
|
||||||
# spinner = spinner_start(colored("Waiting for OpenAI API response...", 'yellow'))
|
# spinner = spinner_start(colored("Waiting for OpenAI API response...", 'yellow'))
|
||||||
# print(colored("Stream response from OpenAI:", 'yellow'))
|
# print(colored("Stream response from OpenAI:", 'yellow'))
|
||||||
api_key = os.getenv("OPENAI_API_KEY")
|
|
||||||
azure_api_key = os.getenv('AZURE_API_KEY')
|
|
||||||
headers = {'Content-Type': 'application/json', 'api-key': azure_api_key}
|
|
||||||
openai_endpoint = 'https://api.openai.com/v1/chat/completions'
|
|
||||||
|
|
||||||
logger.info(f'Request data: {data}')
|
logger.info(f'Request data: {data}')
|
||||||
|
|
||||||
# Check if the ENDPOINT is AZURE
|
# Check if the ENDPOINT is AZURE
|
||||||
if endpoint == 'AZURE':
|
if endpoint == 'AZURE':
|
||||||
# If yes, get the AZURE_ENDPOINT from .ENV file
|
# If yes, get the AZURE_ENDPOINT from .ENV file
|
||||||
azure_endpoint = os.getenv('AZURE_ENDPOINT')
|
endpoint_url = os.getenv('AZURE_ENDPOINT') + '/openai/deployments/' + model + '/chat/completions?api-version=2023-05-15'
|
||||||
|
headers = {'Content-Type': 'application/json', 'api-key': os.getenv('AZURE_API_KEY')}
|
||||||
# Send the request to the Azure endpoint
|
|
||||||
response = requests.post(
|
|
||||||
azure_endpoint + '/openai/deployments/' + model + '/chat/completions?api-version=2023-05-15',
|
|
||||||
headers=headers,
|
|
||||||
json=data,
|
|
||||||
stream=True
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# If not, send the request to the OpenAI endpoint
|
# If not, send the request to the OpenAI endpoint
|
||||||
response = requests.post(
|
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + os.getenv("OPENAI_API_KEY")}
|
||||||
openai_endpoint,
|
endpoint_url = 'https://api.openai.com/v1/chat/completions'
|
||||||
headers=headers,
|
|
||||||
json=data,
|
response = requests.post(
|
||||||
stream=True
|
endpoint_url,
|
||||||
)
|
headers=headers,
|
||||||
|
json=data,
|
||||||
|
stream=True
|
||||||
|
)
|
||||||
|
|
||||||
# Log the response status code and message
|
# Log the response status code and message
|
||||||
logger.info(f'Response status code: {response.status_code}')
|
logger.info(f'Response status code: {response.status_code}')
|
||||||
|
|||||||
Reference in New Issue
Block a user