Last active
October 8, 2024 03:14
-
-
Save se7enack/5f48355d8166956487b19169c0ebd17b to your computer and use it in GitHub Desktop.
ai webapp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
from pywebio import start_server | |
from pywebio.output import put_table | |
from pywebio.input import input | |
openai.api_key = '' | |
def openai_response(name, question): | |
response = openai.ChatCompletion.create( | |
model="gpt-4", | |
messages=[ | |
{"role": "system", "content": "My name is " + name + " and you are 'Hal' a helpful assistant."}, | |
{"role": "user", "content": question} | |
], | |
max_tokens=150 | |
) | |
resp = response['choices'][0]['message']['content'] | |
print(resp) | |
return resp | |
def main(): | |
name = input('What is your name?') | |
while True: | |
question = input('Ask Hal something') | |
k = openai_response(name, question) | |
put_table([ | |
['Q:', question], | |
['A:', k] | |
]) | |
if __name__ == '__main__': | |
start_server(main, port=8080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment