File size: 1,191 Bytes
638a596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
from openai import OpenAI
import os
import requests
import json
from dotenv import load_dotenv 
load_dotenv()


gpt_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

def predict_gpt(prompt):
    response = gpt_client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": prompt}])
    text_response = response.choices[0].message.content
    return text_response

def predict_deepseek(prompt):
    try:
        url = "https://api.deepseek.com/v1/chat/completions"

        payload = json.dumps({
        "messages":[{"role": "user", "content": prompt}],
        "model": "deepseek-coder",
        "max_tokens": 1000,
        "temperature": 0.1,
        })
        os.environ.get("DEEPSEEK_API_KEY")
        headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': f'Bearer {os.environ.get("DEEPSEEK_API_KEY")}'
        }

        response = requests.request("POST", url, headers=headers, data=payload).text
        response = json.loads(response)
        return response['choices'][0]['message']['content']

    except Exception as e:
        raise Exception("Error generating: ",e) from e