Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,7 @@ from langsmith_config import setup_langsmith_config
|
|
5 |
import base64
|
6 |
import os
|
7 |
|
8 |
-
|
9 |
-
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
10 |
model = "gpt-4-1106-preview"
|
11 |
model_vision = "gpt-4-vision-preview"
|
12 |
setup_langsmith_config()
|
@@ -60,7 +59,7 @@ def handle_vision_call(msg, image_history):
|
|
60 |
|
61 |
@traceable(run_type="llm", name="gpt 3 turbo call")
|
62 |
async def gpt_call(message_history: list = []):
|
63 |
-
client = OpenAI()
|
64 |
|
65 |
stream = client.chat.completions.create(
|
66 |
model=model,
|
@@ -72,7 +71,7 @@ async def gpt_call(message_history: list = []):
|
|
72 |
|
73 |
@traceable(run_type="llm", name="gpt 4 turbo vision call")
|
74 |
def gpt_vision_call(image_history: list = []):
|
75 |
-
client = OpenAI()
|
76 |
|
77 |
stream = client.chat.completions.create(
|
78 |
model=model_vision,
|
@@ -88,9 +87,8 @@ async def wait_for_key():
|
|
88 |
res = await cl.AskUserMessage(content="Send an openai api-key to start", timeout=600).send()
|
89 |
if res:
|
90 |
await cl.Message(content="setting up...", indent=1).send()
|
91 |
-
os.environ["OPENAI_API_KEY"] = res["content"]
|
92 |
# check if the key is valid
|
93 |
-
client = OpenAI(api_key=
|
94 |
try:
|
95 |
stream = client.chat.completions.create(
|
96 |
model=model,
|
@@ -100,6 +98,7 @@ async def wait_for_key():
|
|
100 |
)
|
101 |
if stream:
|
102 |
await cl.Message(content="api-key setted, you can start chatting!", indent=1).send()
|
|
|
103 |
except Exception as e:
|
104 |
await cl.Message(content=f"{e}", indent=1).send()
|
105 |
return await wait_for_key()
|
@@ -114,8 +113,7 @@ async def start_chat():
|
|
114 |
[{"role": "system", "content": "You are a helpful assistant. You are made by GPT-3.5-turbo-1106, the latest version developed by Openai. You do not have the ability to receive images, but if the user uploads an image with the message, GPT-4-vision-preview will be used. So if a user asks you if you have the ability to analyze images, you can tell them that. And tell him that at the bottom left (above the text input) he has a button to upload images, or he can drag it to the chat, or he can just copy paste the input"}],
|
115 |
)
|
116 |
cl.user_session.set("image_history", [{"role": "system", "content": "You are a helpful assistant. You are developed with GPT-4-vision-preview, if the user uploads an image, you have the ability to understand it. For normal messages GPT-3.5-turbo-1106 will be used, and for images you will use it. If the user asks about your capabilities you can tell them that."}])
|
117 |
-
|
118 |
-
await wait_for_key()
|
119 |
|
120 |
|
121 |
@cl.on_message
|
|
|
5 |
import base64
|
6 |
import os
|
7 |
|
8 |
+
|
|
|
9 |
model = "gpt-4-1106-preview"
|
10 |
model_vision = "gpt-4-vision-preview"
|
11 |
setup_langsmith_config()
|
|
|
59 |
|
60 |
@traceable(run_type="llm", name="gpt 3 turbo call")
|
61 |
async def gpt_call(message_history: list = []):
|
62 |
+
client = OpenAI(api_key=cl.user_session.get("api_key"))
|
63 |
|
64 |
stream = client.chat.completions.create(
|
65 |
model=model,
|
|
|
71 |
|
72 |
@traceable(run_type="llm", name="gpt 4 turbo vision call")
|
73 |
def gpt_vision_call(image_history: list = []):
|
74 |
+
client = OpenAI(api_key=cl.user_session.get("api_key"))
|
75 |
|
76 |
stream = client.chat.completions.create(
|
77 |
model=model_vision,
|
|
|
87 |
res = await cl.AskUserMessage(content="Send an openai api-key to start", timeout=600).send()
|
88 |
if res:
|
89 |
await cl.Message(content="setting up...", indent=1).send()
|
|
|
90 |
# check if the key is valid
|
91 |
+
client = OpenAI(api_key=cl.user_session.get("api_key"))
|
92 |
try:
|
93 |
stream = client.chat.completions.create(
|
94 |
model=model,
|
|
|
98 |
)
|
99 |
if stream:
|
100 |
await cl.Message(content="api-key setted, you can start chatting!", indent=1).send()
|
101 |
+
cl.user_session.set("api-key", res["content"])
|
102 |
except Exception as e:
|
103 |
await cl.Message(content=f"{e}", indent=1).send()
|
104 |
return await wait_for_key()
|
|
|
113 |
[{"role": "system", "content": "You are a helpful assistant. You are made by GPT-3.5-turbo-1106, the latest version developed by Openai. You do not have the ability to receive images, but if the user uploads an image with the message, GPT-4-vision-preview will be used. So if a user asks you if you have the ability to analyze images, you can tell them that. And tell him that at the bottom left (above the text input) he has a button to upload images, or he can drag it to the chat, or he can just copy paste the input"}],
|
114 |
)
|
115 |
cl.user_session.set("image_history", [{"role": "system", "content": "You are a helpful assistant. You are developed with GPT-4-vision-preview, if the user uploads an image, you have the ability to understand it. For normal messages GPT-3.5-turbo-1106 will be used, and for images you will use it. If the user asks about your capabilities you can tell them that."}])
|
116 |
+
await wait_for_key()
|
|
|
117 |
|
118 |
|
119 |
@cl.on_message
|