File size: 1,796 Bytes
17d12d8
29e6656
7edc5be
e1b0f65
17d12d8
fd96c74
 
 
 
e1b0f65
2d067ac
088ef38
fd96c74
e1b0f65
088ef38
fd96c74
e1b0f65
088ef38
2d067ac
 
 
e1b0f65
 
 
 
 
 
 
 
 
088ef38
2d067ac
 
 
e1b0f65
 
 
 
 
 
 
 
 
088ef38
2d067ac
 
 
e1b0f65
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import torch
from openai import OpenAI
import os
from transformers import pipeline

# pipes = {
#     'GPT-Neo': pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B"),
#     'Llama 3': pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")
# }

def generate(text, model, api):
    if model == "GPT-Neo":
        response = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")(text)
        return response[0]
    elif model == "Llama 3":
        response = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")(text)
        return response[0] 
    elif model == "OpenAI GPT 3.5":
        client = OpenAI(
            api_key=api,
        )
        message=[{"role": "user", "content": text}]
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages = message,
            temperature=0.2,
            max_tokens=800,
            frequency_penalty=0.0
        )
        return response[0].message.content
    elif model == "OpenAI GPT 4":
        client = OpenAI(
            api_key=api,
        )
        message=[{"role": "user", "content": text}]
        response = client.chat.completions.create(
            model="gpt-4-turbo",
            messages = message,
            temperature=0.2,
            max_tokens=800,
            frequency_penalty=0.0
        )
        return response[0].message.content
    elif model == "OpenAI GPT 4o":
        client = OpenAI(
            api_key=api,
        )
        message=[{"role": "user", "content": text}]
        response = client.chat.completions.create(
            model="gpt-4o",
            messages = message,
            temperature=0.2,
            max_tokens=800,
            frequency_penalty=0.0
        )
        return response[0].message.content