Spaces:
Running
Running
Update app.py
Browse filesmax_tokens 16k for deepseek models and msg if finish_reason == 'length'
app.py
CHANGED
|
@@ -676,6 +676,7 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
|
|
| 676 |
using_groq = False
|
| 677 |
reasoning = False
|
| 678 |
prompt = prompt.strip()
|
|
|
|
| 679 |
if prompt.lower().startswith('dsr1 '):
|
| 680 |
deepseek = True
|
| 681 |
ds_model = 'deepseek-ai/DeepSeek-R1'
|
|
@@ -723,15 +724,20 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
|
|
| 723 |
completion = client.chat.completions.create(
|
| 724 |
temperature=0.6,
|
| 725 |
model= ds_model,
|
| 726 |
-
messages=past
|
|
|
|
| 727 |
reporting_model='deepseek70-groq'
|
| 728 |
else:
|
| 729 |
client = OpenAI(api_key=DEEPSEEK_KEY, base_url='https://api.together.xyz/v1')
|
| 730 |
completion = client.chat.completions.create(
|
| 731 |
temperature=0.6,
|
| 732 |
model= ds_model,
|
| 733 |
-
messages=past
|
|
|
|
|
|
|
| 734 |
reporting_model='deepseek-together-' + ds_model[-3:].replace('.5B','1.5B')
|
|
|
|
|
|
|
| 735 |
else:
|
| 736 |
completion = Client().chat.completions.create(model=gptModel,
|
| 737 |
messages=past)
|
|
@@ -758,9 +764,11 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
|
|
| 758 |
tokens_in = completion.usage.prompt_tokens
|
| 759 |
tokens_out = completion.usage.completion_tokens
|
| 760 |
tokens = completion.usage.total_tokens
|
| 761 |
-
response += md("
|
| 762 |
if isBoss:
|
| 763 |
-
response += md(f"\n{reporting_model}: tokens in/out = {tokens_in}/{tokens_out}\n")
|
|
|
|
|
|
|
| 764 |
if tokens > 40000:
|
| 765 |
response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE RESTART CONVERSATION SOON."
|
| 766 |
past.append({"role":"assistant", "content": final_text})
|
|
@@ -972,8 +980,7 @@ def show_help():
|
|
| 972 |
4. "Speak Dialog" will voice whatever is currently in the Dialog window. You can repeat it and you
|
| 973 |
can edit what's to be spoken. Except: In a chat conversation, spoken dialog will only include
|
| 974 |
the latest prompt/response ("YOU:/GPT:") sequence.'''
|
| 975 |
-
return
|
| 976 |
-
|
| 977 |
def upload_image(prompt, user, password):
|
| 978 |
if not (user in unames and password == pwdList[unames.index(user)]):
|
| 979 |
return [gr.Image(visible=False, interactive=True), "Incorrect user name and/or password"]
|
|
@@ -1165,9 +1172,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 1165 |
speak_output = gr.Button(value="Speak Dialog", visible=True)
|
| 1166 |
submit_button = gr.Button(value="Submit Prompt/Question")
|
| 1167 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
| 1168 |
-
|
| 1169 |
-
output_window = gr.Text(container=True, label='Dialog')
|
| 1170 |
-
|
| 1171 |
with gr.Row():
|
| 1172 |
with gr.Column():
|
| 1173 |
image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze', type='filepath')
|
|
|
|
| 676 |
using_groq = False
|
| 677 |
reasoning = False
|
| 678 |
prompt = prompt.strip()
|
| 679 |
+
finish_reason = 'ok'
|
| 680 |
if prompt.lower().startswith('dsr1 '):
|
| 681 |
deepseek = True
|
| 682 |
ds_model = 'deepseek-ai/DeepSeek-R1'
|
|
|
|
| 724 |
completion = client.chat.completions.create(
|
| 725 |
temperature=0.6,
|
| 726 |
model= ds_model,
|
| 727 |
+
messages=past,
|
| 728 |
+
)
|
| 729 |
reporting_model='deepseek70-groq'
|
| 730 |
else:
|
| 731 |
client = OpenAI(api_key=DEEPSEEK_KEY, base_url='https://api.together.xyz/v1')
|
| 732 |
completion = client.chat.completions.create(
|
| 733 |
temperature=0.6,
|
| 734 |
model= ds_model,
|
| 735 |
+
messages=past,
|
| 736 |
+
max_tokens=16000
|
| 737 |
+
)
|
| 738 |
reporting_model='deepseek-together-' + ds_model[-3:].replace('.5B','1.5B')
|
| 739 |
+
if completion.choices[0].finish_reason == 'length':
|
| 740 |
+
finish_reason = "Truncated due to token limit"
|
| 741 |
else:
|
| 742 |
completion = Client().chat.completions.create(model=gptModel,
|
| 743 |
messages=past)
|
|
|
|
| 764 |
tokens_in = completion.usage.prompt_tokens
|
| 765 |
tokens_out = completion.usage.completion_tokens
|
| 766 |
tokens = completion.usage.total_tokens
|
| 767 |
+
response += md("\n\n***YOU***: " + prompt + "\n\n***GPT***: ") + reply.replace('```','\n\n```\n\n')
|
| 768 |
if isBoss:
|
| 769 |
+
response += md(f"\n\n{reporting_model}: tokens in/out = {tokens_in}/{tokens_out}\n")
|
| 770 |
+
if finish_reason != 'ok':
|
| 771 |
+
response += md(f"\n{finish_reason}\n")
|
| 772 |
if tokens > 40000:
|
| 773 |
response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE RESTART CONVERSATION SOON."
|
| 774 |
past.append({"role":"assistant", "content": final_text})
|
|
|
|
| 980 |
4. "Speak Dialog" will voice whatever is currently in the Dialog window. You can repeat it and you
|
| 981 |
can edit what's to be spoken. Except: In a chat conversation, spoken dialog will only include
|
| 982 |
the latest prompt/response ("YOU:/GPT:") sequence.'''
|
| 983 |
+
return str(txt).replace('```', ' ').replace(' ', ' ').replace(' ', ' ').replace(' ', ' ').replace('\n','<br>')
|
|
|
|
| 984 |
def upload_image(prompt, user, password):
|
| 985 |
if not (user in unames and password == pwdList[unames.index(user)]):
|
| 986 |
return [gr.Image(visible=False, interactive=True), "Incorrect user name and/or password"]
|
|
|
|
| 1172 |
speak_output = gr.Button(value="Speak Dialog", visible=True)
|
| 1173 |
submit_button = gr.Button(value="Submit Prompt/Question")
|
| 1174 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
| 1175 |
+
gr.Markdown('### **Dialog:**')
|
| 1176 |
+
#output_window = gr.Text(container=True, label='Dialog')
|
| 1177 |
+
output_window = gr.Markdown(container=True)
|
| 1178 |
with gr.Row():
|
| 1179 |
with gr.Column():
|
| 1180 |
image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze', type='filepath')
|