acecalisto3 commited on
Commit
df3940d
·
verified ·
1 Parent(s): 703bf32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -478,13 +478,38 @@ def project_explorer(path):
478
  tree = get_file_tree(path)
479
  display_file_tree(tree)
480
 
481
- def chat_app_logic(message, history, purpose, agent_name, sys_prompt, temperature, max_new_tokens, top_p, repetition_penalty):
482
- """
483
- Handles the chat app logic, including running the model and displaying the output.
484
- """
485
- if message:
486
- # Run the model and get the response (convert generator to string)
 
 
487
  response = ''.join(generate(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  prompt=message,
489
  history=history,
490
  agent_name=agent_name,
 
478
  tree = get_file_tree(path)
479
  display_file_tree(tree)
480
 
481
+ I understand you're encountering an error when trying to join the output of the `generate()` function. The error message suggests that the `generate()` function is not returning an iterable object as expected. Let's modify the code to handle this issue:
482
+
483
+ ```python
484
+ def chat_app_logic(message, history):
485
+ # Your existing code here
486
+
487
+ try:
488
+ # Attempt to join the generator output
489
  response = ''.join(generate(
490
+ model=model,
491
+ messages=messages,
492
+ stream=True,
493
+ temperature=0.7,
494
+ max_tokens=1500
495
+ ))
496
+ except TypeError:
497
+ # If joining fails, collect the output in a list
498
+ response_parts = []
499
+ for part in generate(
500
+ model=model,
501
+ messages=messages,
502
+ stream=True,
503
+ temperature=0.7,
504
+ max_tokens=1500
505
+ ):
506
+ if isinstance(part, str):
507
+ response_parts.append(part)
508
+ elif isinstance(part, dict) and 'content' in part:
509
+ response_parts.append(part['content'])
510
+
511
+ response = ''.join(response_parts
512
+ # Run the model and get the response (convert generator to string)
513
  prompt=message,
514
  history=history,
515
  agent_name=agent_name,