Tonic commited on
Commit
f5bbb7d
β€’
1 Parent(s): ccbd989

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -5
app.py CHANGED
@@ -20,10 +20,8 @@ from panel.chat import ChatInterface
20
  from panel.widgets import Button, CodeEditor, PasswordInput, Switch, TextInput
21
 
22
  pn.extension("codeeditor")
23
-
24
  template = pn.template.BootstrapTemplate(title=TITLE)
25
 
26
-
27
  def get_description_text():
28
  return f"""
29
  # {TITLE}
@@ -32,6 +30,30 @@ def get_description_text():
32
 
33
  #### [[AutoGen](https://github.com/microsoft/autogen)] [[Discord](https://discord.gg/pAbnFJrkgZ)] [[Paper](https://arxiv.org/abs/2308.08155)] [[SourceCode](https://github.com/thinkall/autogen-demos)]
34
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  template.main.append(
@@ -65,12 +87,17 @@ pwd_aoai_url = PasswordInput(
65
  sizing_mode="stretch_width",
66
  )
67
  file_cfg = pn.widgets.FileInput(filename="OAI_CONFIG_LIST", sizing_mode="stretch_width")
68
- template.main.append(
69
- pn.Row(
70
- txt_model, pwd_openai_key, pwd_openai_url, pwd_aoai_key, pwd_aoai_url, file_cfg
 
 
71
  )
72
  )
73
 
 
 
 
74
 
75
  def get_config(tmpfilename="OAI_CONFIG_LIST"):
76
  os.makedirs(".chromadb", exist_ok=True)
@@ -85,6 +112,14 @@ def get_config(tmpfilename="OAI_CONFIG_LIST"):
85
  cfg_fpath,
86
  file_location=".",
87
  )
 
 
 
 
 
 
 
 
88
  if not config_list:
89
  os.environ["MODEL"] = txt_model.value
90
  os.environ["OPENAI_API_KEY"] = pwd_openai_key.value
 
20
  from panel.widgets import Button, CodeEditor, PasswordInput, Switch, TextInput
21
 
22
  pn.extension("codeeditor")
 
23
  template = pn.template.BootstrapTemplate(title=TITLE)
24
 
 
25
  def get_description_text():
26
  return f"""
27
  # {TITLE}
 
30
 
31
  #### [[AutoGen](https://github.com/microsoft/autogen)] [[Discord](https://discord.gg/pAbnFJrkgZ)] [[Paper](https://arxiv.org/abs/2308.08155)] [[SourceCode](https://github.com/thinkall/autogen-demos)]
32
  """
33
+
34
+ client = Client("https://tonic1-tulu.hf.space/--replicas/xh5ff/")
35
+
36
+ async def send_messages_with_tulua_pi(recipient,messages,sender):
37
+ response_content =""
38
+
39
+ if len(messages) >0:
40
+ message_text= messages[-1]['content']
41
+ result await client.predict(message_text)
42
+
43
+ if 'message' in result :
44
+ reponse_content=result['message']
45
+
46
+ chatiface.send(reponse_content,user=sender.name,resend=False)
47
+
48
+ # Define a panel Row for OpenAI settings.
49
+ openai_row = pn.Row(txt_model, pwd_openai_key, pwd_openai_url)
50
+
51
+ def check_yi_mode(event):
52
+ # Make openai_row invisible when local YI Mode is enabled and vice versa.
53
+ openai_row.visible = not event.new
54
+
55
+ # Add an observer to watch changes in yi_mode value (True/False)
56
+ YI_MODE.param.watch(check_yi_mode, 'value')
57
 
58
 
59
  template.main.append(
 
87
  sizing_mode="stretch_width",
88
  )
89
  file_cfg = pn.widgets.FileInput(filename="OAI_CONFIG_LIST", sizing_mode="stretch_width")
90
+ template.main.append(
91
+ pn.Column(
92
+ openai_row,
93
+ [pn.pane.Markdown("### Local YI Mode: "),Yi_Mode],
94
+ [pn.pane.Markdown("### Yi Endpoint: "), yi_endpoint]
95
  )
96
  )
97
 
98
+ # Add YI Mode Checkbox and Endpoint Input.
99
+ YI_MODE = pn.widgets.Checkbox(name='Local Y.I. Mode', value=True)
100
+ YI_ENDPOINT = pn.widgets.TextInput(name='Yi Endpoint', placeholder="Enter your YI endpoint here...")
101
 
102
  def get_config(tmpfilename="OAI_CONFIG_LIST"):
103
  os.makedirs(".chromadb", exist_ok=True)
 
112
  cfg_fpath,
113
  file_location=".",
114
  )
115
+ if YI_MODE == "local":
116
+ config_list = [
117
+ {
118
+ "model": "EasyYI",
119
+ "api_key": "None",
120
+ "base_url": "https://huggingface.co/spaces/teamtonic/easyyi"
121
+ }
122
+ ]
123
  if not config_list:
124
  os.environ["MODEL"] = txt_model.value
125
  os.environ["OPENAI_API_KEY"] = pwd_openai_key.value