Spaces:
No application file
No application file
File size: 899 Bytes
5a1b165 |
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 openai
class Gpt3Manager:
def __init__(self, api_key):
openai.api_key = api_key
def get_completion(prompt, max_tokens=128, model="text-davinci-003"):
response = None
try:
response = openai.Completion.create(
model=model,
prompt=prompt,
max_tokens=max_tokens,
)["choices"][0]["text"]
except Exception as err:
print(f"Sorry, There was a problem \n\n {err}")
return response
def get_embedding(text, model="text-similarity-ada-001"):
text = text.replace("\n", " ")
embedding = None
try:
embedding = openai.Embedding.create(input=[text], model=model)["data"][0][
"embedding"
]
except Exception as err:
print(f"Sorry, There was a problem {err}")
return embedding
|