Spaces:
Build error
Build error
Upload 3 files
Browse files
20230311180758895/20230311180758895/01 chatgpt simple.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
|
| 3 |
+
openai.api_key = "####"
|
| 4 |
+
|
| 5 |
+
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Give me 3 ideas for apps I could build with openai apis "}])
|
| 6 |
+
print(completion.choices[0].message.content)
|
20230311180758895/20230311180758895/02 chatgpt chat assistant copy.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
|
| 3 |
+
openai.api_key = "####"
|
| 4 |
+
|
| 5 |
+
messages = []
|
| 6 |
+
system_msg = input("What type of chatbot would you like to create?\n")
|
| 7 |
+
messages.append({"role": "system", "content": system_msg})
|
| 8 |
+
|
| 9 |
+
print("Your new assistant is ready!")
|
| 10 |
+
while input != "quit()":
|
| 11 |
+
message = input()
|
| 12 |
+
messages.append({"role": "user", "content": message})
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model="gpt-3.5-turbo",
|
| 15 |
+
messages=messages)
|
| 16 |
+
reply = response["choices"][0]["message"]["content"]
|
| 17 |
+
messages.append({"role": "assistant", "content": reply})
|
| 18 |
+
print("\n" + reply + "\n")
|
20230311180758895/20230311180758895/03 chatgpt chat assistant website.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio
|
| 3 |
+
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
+
|
| 6 |
+
messages = [{"role": "system", "content": "You are a financial experts that specializes in real estate investment and negotiation"}]
|
| 7 |
+
|
| 8 |
+
def CustomChatGPT(user_input):
|
| 9 |
+
messages.append({"role": "user", "content": user_input})
|
| 10 |
+
response = openai.ChatCompletion.create(
|
| 11 |
+
model = "gpt-3.5-turbo",
|
| 12 |
+
messages = messages
|
| 13 |
+
)
|
| 14 |
+
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
| 15 |
+
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
| 16 |
+
return ChatGPT_reply
|
| 17 |
+
|
| 18 |
+
demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "chagpt测试网站")
|
| 19 |
+
|
| 20 |
+
demo.launch(share=True)
|