RamV commited on
Commit
d13d3d0
·
1 Parent(s): 33de086

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+
3
+ # Set up OpenAI API credentials
4
+ openai.api_key = "YOUR_API_KEY"
5
+
6
+ # Define a function to generate a response to user input
7
+ def generate_response(user_input):
8
+ # Check if user input contains the phrase "who created you"
9
+ if "who created you" in user_input.lower():
10
+ # Generate a response that includes your name
11
+ chat_response = f"I was created by {RamV}!"
12
+ else:
13
+ # Construct the prompt with the user input
14
+ prompt = f"You said: {user_input}"
15
+
16
+ # Generate a response using the OpenAI API
17
+ response = openai.Completion.create(
18
+ engine="text-davinci-002",
19
+ prompt=prompt,
20
+ temperature=0.7,
21
+ max_tokens=1024,
22
+ n=1,
23
+ stop=None,
24
+ frequency_penalty=0,
25
+ presence_penalty=0
26
+ )
27
+
28
+ # Extract the response from the API output
29
+ chat_response = response.choices[0].text.strip()
30
+
31
+ return chat_response
32
+
33
+ # Test the chatbot
34
+ while True:
35
+ user_input = input("You: ")
36
+ response = generate_response(user_input)
37
+ print("Chatbot:", response)