File size: 4,810 Bytes
777015e |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
import random
from typing import List, Optional
from openai import OpenAI
import os
import dotenv
# Load environment variables from .env file
dotenv.load_dotenv()
def sota_model(
history: List[List[Optional[str]]],
temperature: float = 0.6,
top_p: float = 0.7,
max_output_tokens: int = 2048,
):
# client = OpenAI()
client = OpenAI(
api_key=os.environ.get("SOTA_API_KEY"),
base_url=os.environ.get("SOTA_API_BASE")
)
messages = []
for human, ai in history:
if human:
messages.append({"role": "user", "content": human})
if ai:
messages.append({"role": "assistant", "content": ai})
stream = client.chat.completions.create(
model=os.environ.get("SOTA_API_MODEL"),
messages=messages,
stream=True,
temperature=temperature,
top_p=top_p,
max_tokens=max_output_tokens,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
yield chunk.choices[0].delta.content
def model1(
history: List[List[Optional[str]]],
temperature: float = 0.8,
top_p: float = 0.7,
max_output_tokens: int = 2048,
):
# client = OpenAI()
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
base_url=os.environ.get("OPENAI_API_BASE")
)
messages = []
for human, ai in history:
if human:
messages.append({"role": "user", "content": human})
if ai:
messages.append({"role": "assistant", "content": ai})
stream = client.chat.completions.create(
# model="gpt-3.5-turbo",
model=os.environ.get("API_MODEL_1"),
messages=messages,
stream=True,
temperature=temperature,
top_p=top_p,
max_tokens=max_output_tokens,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
yield chunk.choices[0].delta.content
def model2(
history: List[List[Optional[str]]],
temperature: float = 0.8,
top_p: float = 0.7,
max_output_tokens: int = 2048,
):
# client = OpenAI()
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
base_url=os.environ.get("OPENAI_API_BASE")
)
messages = []
for human, ai in history:
if human:
messages.append({"role": "user", "content": human})
if ai:
messages.append({"role": "assistant", "content": ai})
stream = client.chat.completions.create(
# model="gpt-4-turbo",
model=os.environ.get("API_MODEL_2"),
messages=messages,
stream=True,
temperature=temperature,
top_p=top_p,
max_tokens=max_output_tokens,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
yield chunk.choices[0].delta.content
def model3(
history: List[List[Optional[str]]],
temperature: float = 0.8,
top_p: float = 0.7,
max_output_tokens: int = 2048,
):
# client = OpenAI()
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
base_url=os.environ.get("OPENAI_API_BASE")
)
messages = []
for human, ai in history:
if human:
messages.append({"role": "user", "content": human})
if ai:
messages.append({"role": "assistant", "content": ai})
stream = client.chat.completions.create(
# model="gpt-4-turbo",
model=os.environ.get("API_MODEL_3"),
messages=messages,
stream=True,
temperature=temperature,
top_p=top_p,
max_tokens=max_output_tokens,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
yield chunk.choices[0].delta.content
def get_all_models():
return [
{
# "name": os.environ.get("SOTA_API_MODEL"),
"name": 'Cherokee Language Preserve Model V0.4',
"model": sota_model,
},
{
"name":os.environ.get("API_MODEL_1"),
"model": model1,
},
{
"name": os.environ.get("API_MODEL_2"),
"model": model2,
},
{
"name": os.environ.get("API_MODEL_3"),
"model": model3,
},
]
# def get_all_models():
# return [
# {
# # "name": os.environ.get("SOTA_API_MODEL"),
# # "name": 'Cherokee Language Preserve Model V0.4',
# "name": 'Cherokee Model V0.4',
# "model": sota_model,
# },
# {
# "name":os.environ.get("API_MODEL_1"),
# "model": model1,
# }
# ]
def get_random_models(number: int = 4):
return random.sample(get_all_models(), number)
# def get_random_models():
# return get_all_models()
|