Spaces:
Runtime error
Runtime error
Removed system
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from http import HTTPStatus
|
|
4 |
import openai
|
5 |
from typing import Generator, List, Optional, Tuple, Dict
|
6 |
from urllib.error import HTTPError
|
7 |
-
default_system = 'You are a helpful assistant.'
|
8 |
|
9 |
API_URL = os.getenv('API_URL')
|
10 |
API_KEY = os.getenv('API_KEY')
|
@@ -16,12 +15,7 @@ Messages = List[Dict[str, str]]
|
|
16 |
def clear_session() -> History:
|
17 |
return '', []
|
18 |
|
19 |
-
def
|
20 |
-
if system is None or len(system) == 0:
|
21 |
-
system = default_system
|
22 |
-
return system, system, []
|
23 |
-
|
24 |
-
def history_to_messages(history: History, system: str) -> Messages:
|
25 |
messages = []
|
26 |
for h in history:
|
27 |
messages.append({'role': 'user', 'content': h[0]})
|
@@ -29,18 +23,17 @@ def history_to_messages(history: History, system: str) -> Messages:
|
|
29 |
return messages
|
30 |
|
31 |
def messages_to_history(messages: Messages) -> Tuple[str, History]:
|
32 |
-
system = messages[0]['content']
|
33 |
history = []
|
34 |
-
for q, r in zip(messages[
|
35 |
history.append([q['content'], r['content']])
|
36 |
-
return
|
37 |
|
38 |
-
def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tuple[str,
|
39 |
if query is None:
|
40 |
query = ''
|
41 |
if history is None:
|
42 |
history = []
|
43 |
-
messages = history_to_messages(history
|
44 |
messages.append({'role': 'user', 'content': query})
|
45 |
gen = oai_client.chat.completions.create(
|
46 |
model='dicta-il/dictalm2.0-instruct',
|
@@ -54,8 +47,8 @@ def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tu
|
|
54 |
for completion in gen:
|
55 |
text = completion.choices[0].text
|
56 |
messages[-1]['content'] += text
|
57 |
-
|
58 |
-
yield '', history
|
59 |
|
60 |
with gr.Blocks() as demo:
|
61 |
gr.Markdown("""<center><font size=8>DictaLM2.0-Instruct Chat Demo</center>""")
|
|
|
4 |
import openai
|
5 |
from typing import Generator, List, Optional, Tuple, Dict
|
6 |
from urllib.error import HTTPError
|
|
|
7 |
|
8 |
API_URL = os.getenv('API_URL')
|
9 |
API_KEY = os.getenv('API_KEY')
|
|
|
15 |
def clear_session() -> History:
|
16 |
return '', []
|
17 |
|
18 |
+
def history_to_messages(history: History) -> Messages:
|
|
|
|
|
|
|
|
|
|
|
19 |
messages = []
|
20 |
for h in history:
|
21 |
messages.append({'role': 'user', 'content': h[0]})
|
|
|
23 |
return messages
|
24 |
|
25 |
def messages_to_history(messages: Messages) -> Tuple[str, History]:
|
|
|
26 |
history = []
|
27 |
+
for q, r in zip(messages[0::2], messages[1::2]):
|
28 |
history.append([q['content'], r['content']])
|
29 |
+
return history
|
30 |
|
31 |
+
def model_chat(query: Optional[str], history: Optional[History]) -> Generator[Tuple[str, History], None, None]:
|
32 |
if query is None:
|
33 |
query = ''
|
34 |
if history is None:
|
35 |
history = []
|
36 |
+
messages = history_to_messages(history)
|
37 |
messages.append({'role': 'user', 'content': query})
|
38 |
gen = oai_client.chat.completions.create(
|
39 |
model='dicta-il/dictalm2.0-instruct',
|
|
|
47 |
for completion in gen:
|
48 |
text = completion.choices[0].text
|
49 |
messages[-1]['content'] += text
|
50 |
+
history = messages_to_history(messages)
|
51 |
+
yield '', history
|
52 |
|
53 |
with gr.Blocks() as demo:
|
54 |
gr.Markdown("""<center><font size=8>DictaLM2.0-Instruct Chat Demo</center>""")
|