-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexerc.py
30 lines (25 loc) · 851 Bytes
/
exerc.py
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
from typing import List
import os
import openai
import secret
openai.api_key=secret.api_key
def chatfunctions(prompts: List[str], temp: float, max_t: int) -> List[str]:
# CODIO SOLUTION BEGIN
responses = []
for prompt in prompts:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
temperature=temp,
max_tokens=max_t
)
responses.append(response['choices'][0]['message']['content'])
return responses
def user_experience(prompt: str, temp: float, max_t: int):
response = chatfunctions([prompt], temp, max_t)
print("User: ", prompt)
print("AI: ", response[0])
# CODIO SOLUTION END