-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_nlp.py
24 lines (21 loc) · 1.01 KB
/
api_nlp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import openai
openai.api_key = "PUT YOUR OWN API"
def get_answer(question:str, context:str):
prompt = f"question:{question}\ncontext:{context}"
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
temperature=0.4,
max_tokens=256
)
return response
if __name__ == "__main__":
que = "What show that the latter are significantly better predictors of translated sentences than the former?"
con = "We investigate the differences between language models compiled from original target-language\
texts and those compiled from texts manually translated to the target language. Corroborating\
established observations of Translation Studies, we demonstrate that the latter are significantly\
better predictors of translated sentences than the former, and hence fit the reference set better.\
Furthermore, translated texts yield better language models for statistical machine translation\
than original texts."
res = get_answer(que, con)
print(res)