TxGpt / gptcall.py
Nitish Raghav
Create gptcall.py
38492d8 verified
raw
history blame
741 Bytes
import requests
import json
import openai
import configparser
# Load configuration
config = configparser.ConfigParser()
config.read('test.env')
API_KEY = config.get('API', 'OPEN_AI_KEY')
API_URL = config.get('API', 'OPEN_AI_URL')
# Set the OpenAI API key
openai.api_key = API_KEY
def generate(prompt):
try:
response = openai.ChatCompletion.create(
model="gpt-4-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
max_tokens=2000,
temperature=0.9
)
return response['choices'][0]['message']['content']
except Exception as e:
return str(e)