File size: 849 Bytes
38492d8
 
 
 
3ef7bfa
 
 
38492d8
 
 
 
 
cfba01d
38492d8
8850463
38492d8
e4c3071
8850463
cfba01d
38492d8
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import json
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)