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