Spaces:
Sleeping
Sleeping
Commit
·
759dc9e
1
Parent(s):
ff65086
Create ChatBot.py
Browse files- ChatBot.py +31 -0
ChatBot.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
|
4 |
+
openai.api_key="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"
|
5 |
+
start="\nAI"
|
6 |
+
End="\Human
|
7 |
+
Prompt="This is AI Chat bot for the Student Consulting"
|
8 |
+
|
9 |
+
|
10 |
+
def OpneaiFun(Prompt):
|
11 |
+
respone=openai.Completion.create(
|
12 |
+
model="text-davinci-003",
|
13 |
+
prompt=Prompt,
|
14 |
+
temperature=0.9,
|
15 |
+
max_tokens=150,
|
16 |
+
top_p=1,
|
17 |
+
frequency_penalty=0,
|
18 |
+
presence_penalty=0.5,
|
19 |
+
stop=["Human:","AI:"]
|
20 |
+
)
|
21 |
+
return respone.choices[0].text
|
22 |
+
|
23 |
+
def chat_clone(input,history):
|
24 |
+
history=history or []
|
25 |
+
s=list(sum(history,()))
|
26 |
+
s.append(input)
|
27 |
+
inp=' '.join(s)
|
28 |
+
output=OpneaiFun(inp)
|
29 |
+
history.append((input,output))
|
30 |
+
return history,history
|
31 |
+
|