TxGpt / gptcall.py
TestingXperts's picture
Update gptcall.py
f6146d0 verified
raw
history blame contribute delete
858 Bytes
import requests
import json
from aaa
import openai
import configparser
from dotenv import load_dotenv
load_dotenv()
import os
# 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')
# print(API_URL,API_KEY)
# Set the OpenAI API key
openai.api_key = API_KEY
def generate(prompt):
# print(API_URL,API_KEY)
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)