starsaround commited on
Commit
b7adec7
1 Parent(s): c2119e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -19,36 +19,48 @@ from g4f.Provider import (
19
  )
20
  import os
21
 
22
- from g4f.models import Model
23
- model_provider_dict = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # 遍历Model类中的name属性
26
- for name in vars(Model):
27
- attr_value = getattr(Model, name)
28
- if hasattr(attr_value, 'name'):
29
- model_provider_dict[attr_value.name] = attr_value.best_provider
30
-
31
- # os.environ["no_proxy"] = "localhost,127.0.0.1,:1"
32
 
33
  with gr.Blocks() as demo:
34
-
35
  chatbot = gr.Chatbot([[None, None]], label='AI')
36
  msg = gr.Textbox(value="", label='')
37
  clear = gr.Button("Clear")
38
- model_name = gr.Dropdown(model_provider_dict.keys())
 
 
39
 
40
  def user(user_message, history):
41
  return gr.update(value="", interactive=False), history + [[user_message, None]]
42
 
43
- def bot(history, model_name):
44
  history[-1][1] = ''
45
- bot_msg = g4f.ChatCompletion.create(model=model_name, provider=model_provider_dict[model_name], messages=[{"role": "user", "content": history[-1][0]}], stream=True)
 
 
 
46
  for c in bot_msg:
47
  history[-1][1] += c
48
  yield history
49
 
50
  response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
51
- bot, [chatbot, model_name], chatbot
52
  )
53
  response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
54
  clear.click(lambda: None, None, chatbot, queue=False)
 
19
  )
20
  import os
21
 
22
+ provider_dict = {
23
+ # 'Ails': Ails,
24
+ # 'You': You,
25
+ # 'Bing': Bing,
26
+ # 'Yqcloud': Yqcloud,
27
+ # 'Theb': Theb,
28
+ # 'Aichat': Aichat,
29
+ # 'Bard': Bard,
30
+ # 'Vercel': Vercel,
31
+ # 'Forefront': Forefront,
32
+ # 'Lockchat': Lockchat,
33
+ # 'Liaobots': Liaobots,
34
+ # 'H2o': H2o,
35
+ # 'ChatgptLogin': ChatgptLogin,
36
+ 'DeepAi': DeepAi,
37
+ 'GetGpt': GetGpt
38
+ }
39
 
 
 
 
 
 
 
 
40
 
41
  with gr.Blocks() as demo:
 
42
  chatbot = gr.Chatbot([[None, None]], label='AI')
43
  msg = gr.Textbox(value="", label='')
44
  clear = gr.Button("Clear")
45
+ with gr.Row():
46
+ model_name = gr.Dropdown(['gpt-3.5-turbo', 'gpt-4'], value='gpt-3.5-turbo', label='模型')
47
+ provider_name = gr.Dropdown(provider_dict.keys(), value='GetGpt', label='提供者')
48
 
49
  def user(user_message, history):
50
  return gr.update(value="", interactive=False), history + [[user_message, None]]
51
 
52
+ def bot(history, model_name, provider_name):
53
  history[-1][1] = ''
54
+ bot_msg = g4f.ChatCompletion.create(model=model_name,
55
+ provider=provider_dict[provider_name],
56
+ messages=[{"role": "user", "content": history[-1][0]}],
57
+ stream=True)
58
  for c in bot_msg:
59
  history[-1][1] += c
60
  yield history
61
 
62
  response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
63
+ bot, [chatbot, model_name, provider_name], chatbot
64
  )
65
  response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
66
  clear.click(lambda: None, None, chatbot, queue=False)