File size: 749 Bytes
a322db1
 
64bb5ac
a322db1
1847228
a322db1
fd5ceb2
a322db1
 
 
 
 
 
 
 
f34a7c8
a322db1
 
fd5ceb2
a322db1
 
 
 
f34a7c8
a322db1
 
 
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
import openai
import gradio as gr

#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

openai.api_key = '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'

def openai_chat(prompt):
    completions = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=2048,
        n=1,
        temperature=0.5,
    )

    message = completions.choices[0].text
    return message.strip()

def chatbot(input, history=[]):
    output = openai_chat(input)
    history.append((input, output))
    return history, history

gr.Interface( title = 'An Alternative to chatGPT - Built by Hrishikesh', fn = chatbot,
             inputs = ["text",'state'],
             outputs = ["chatbot",'state']).launch(debug = True )