NeonBohdan commited on
Commit
a3e95e6
1 Parent(s): f66fb6a

Use Client

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -4,28 +4,30 @@ from typing import List, Tuple
4
  from collections import OrderedDict
5
 
6
  import gradio as gr
7
- from openai import OpenAI
 
8
 
9
 
10
  config = json.loads(os.environ['CONFIG'])
11
 
12
 
13
  model_names = list(config.keys())
14
- personas = list(OrderedDict.fromkeys(persona for name in config for persona in config[name]["personas"]))
15
-
16
-
17
- info = "\n".join([f"{model} ({config[model]['name']}): {list(config[model]['personas'].keys())}" for model in model_names])
18
 
19
 
20
  clients = {}
21
  for name in config:
22
- client = OpenAI(
23
- base_url=f"{os.environ[config[name]['api_url']]}/v1",
 
24
  api_key=os.environ[config[name]['api_key']],
 
25
  )
26
  clients[name] = client
27
 
28
 
 
 
 
29
 
30
  def respond(
31
  message,
@@ -36,12 +38,14 @@ def respond(
36
  conversational,
37
  max_tokens,
38
  ):
 
 
39
  messages = []
40
 
41
  try:
42
- system_prompt = config[model]["personas"][persona]
43
  except KeyError:
44
- supported_personas = list(config[model]["personas"].keys())
45
  raise gr.Error(f"Model '{model}' does not support persona '{persona}', only {supported_personas}")
46
  if system_prompt is not None:
47
  messages.append({"role": "system", "content": system_prompt})
@@ -55,8 +59,8 @@ def respond(
55
 
56
  messages.append({"role": "user", "content": message})
57
 
58
- completion = clients[model].chat.completions.create(
59
- model="neongeckocom/NeonLLM",
60
  messages=messages,
61
  max_tokens=max_tokens,
62
  temperature=0,
 
4
  from collections import OrderedDict
5
 
6
  import gradio as gr
7
+
8
+ from shared import Client
9
 
10
 
11
  config = json.loads(os.environ['CONFIG'])
12
 
13
 
14
  model_names = list(config.keys())
 
 
 
 
15
 
16
 
17
  clients = {}
18
  for name in config:
19
+ model_personas = config[name].get("personas", {})
20
+ client = Client(
21
+ api_url=os.environ[config[name]['api_url']],
22
  api_key=os.environ[config[name]['api_key']],
23
+ personas=model_personas
24
  )
25
  clients[name] = client
26
 
27
 
28
+ personas = list(OrderedDict.fromkeys(persona for name in model_names for persona in clients[name].personas))
29
+ info = "\n".join([f"{model} ({config[model]['name']}): {list(clients[model].personas.keys())}" for model in model_names])
30
+
31
 
32
  def respond(
33
  message,
 
38
  conversational,
39
  max_tokens,
40
  ):
41
+ client = clients[model]
42
+
43
  messages = []
44
 
45
  try:
46
+ system_prompt = client.personas[persona]
47
  except KeyError:
48
+ supported_personas = list(client.personas.keys())
49
  raise gr.Error(f"Model '{model}' does not support persona '{persona}', only {supported_personas}")
50
  if system_prompt is not None:
51
  messages.append({"role": "system", "content": system_prompt})
 
59
 
60
  messages.append({"role": "user", "content": message})
61
 
62
+ completion = client.client.chat.completions.create(
63
+ model=client.vllm_model_name,
64
  messages=messages,
65
  max_tokens=max_tokens,
66
  temperature=0,