AMDF commited on
Commit
01e94dc
Β·
verified Β·
1 Parent(s): f4b92fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -2,9 +2,32 @@ import gradio as gr
2
  import requests
3
  import json
4
 
5
- # Solar Pro2 API μ„€μ •
6
- API_KEY = "up_S7cDxYLLt07RZDzCHBvGQnV0zqv4b"
7
- API_URL = "https://api.upstage.ai/v1"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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와 λŒ€ν™”ν•˜λŠ” ν•¨μˆ˜"""