Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,32 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def chat_with_solar(message, history):
|
| 10 |
"""Solar Pro2μ λννλ ν¨μ"""
|
|
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
|
| 5 |
+
# pip install openai
|
| 6 |
+
|
| 7 |
+
from openai import OpenAI # openai==1.52.2
|
| 8 |
+
|
| 9 |
+
client = OpenAI(
|
| 10 |
+
api_key="up_S7cDxYLLt07RZDzCHBvGQnV0zqv4b",
|
| 11 |
+
base_url="https://api.upstage.ai/v1"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
stream = client.chat.completions.create(
|
| 15 |
+
model="solar-pro2",
|
| 16 |
+
messages=[
|
| 17 |
+
{
|
| 18 |
+
"role": "user",
|
| 19 |
+
"content": "Hi, how are you?"
|
| 20 |
+
}
|
| 21 |
+
],
|
| 22 |
+
stream=True,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
for chunk in stream:
|
| 26 |
+
if chunk.choices[0].delta.content is not None:
|
| 27 |
+
print(chunk.choices[0].delta.content, end="")
|
| 28 |
+
|
| 29 |
+
# Use with stream=False
|
| 30 |
+
# print(stream.choices[0].message.content)
|
| 31 |
|
| 32 |
def chat_with_solar(message, history):
|
| 33 |
"""Solar Pro2μ λννλ ν¨μ"""
|