leavoigt commited on
Commit
f93aadf
·
verified ·
1 Parent(s): 9410c95

fix bug in summary generation

Browse files
Files changed (1) hide show
  1. appStore/rag.py +32 -18
appStore/rag.py CHANGED
@@ -58,26 +58,40 @@ def run_query(context, label, model_sel_name):
58
  # Initialize the client, pointing it to one of the available models
59
  client = InferenceClient(model_sel_name, token=hf_token)
60
 
61
- # Instantiate ChatCompletion as a generator object (stream is set to True)
62
- chat_completion = client.chat.completions.create(
63
- messages=messages,
64
- stream=True
65
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- # Create an object to store the full chat completion
68
  completion_result = ChatCompletionResult()
69
  res_box = st.empty()
70
 
71
- # Iterate through the streamed output
72
- for chunk in chat_completion:
73
- # Extract the object containing the text
74
- if chunk.choices is not None:
75
- chunk_message = chunk.choices[0].delta
76
- if 'content' in chunk_message:
77
- completion_result.add_content(chunk_message['content']) # Store the message
78
- # Add the latest text and merge it with all previous
79
- result = completion_result.get_full_content()
80
- res_box.success(result) # Output to response text box
81
-
82
- # Return the stored chat completion object for later use
83
  return completion_result
 
 
 
 
58
  # Initialize the client, pointing it to one of the available models
59
  client = InferenceClient(model_sel_name, token=hf_token)
60
 
61
+ # # Instantiate ChatCompletion as a generator object (stream is set to True)
62
+ # chat_completion = client.chat.completions.create(
63
+ # messages=messages,
64
+ # stream=True
65
+ # )
66
+
67
+ # # Create an object to store the full chat completion
68
+ # completion_result = ChatCompletionResult()
69
+ # res_box = st.empty()
70
+
71
+ # # Iterate through the streamed output
72
+ # for chunk in chat_completion:
73
+ # # Extract the object containing the text
74
+ # if chunk.choices is not None:
75
+ # chunk_message = chunk.choices[0].delta
76
+ # if 'content' in chunk_message:
77
+ # completion_result.add_content(chunk_message['content']) # Store the message
78
+ # # Add the latest text and merge it with all previous
79
+ # result = completion_result.get_full_content()
80
+ # res_box.success(result) # Output to response text box
81
+
82
+
83
+ # Use streaming text generation
84
+ response_stream = client.text_generation(prompt, stream=True, max_new_tokens=512)
85
 
 
86
  completion_result = ChatCompletionResult()
87
  res_box = st.empty()
88
 
89
+ for chunk in response_stream:
90
+ completion_result.add_content(chunk)
91
+ result = completion_result.get_full_content()
92
+ res_box.success(result)
93
+
 
 
 
 
 
 
 
94
  return completion_result
95
+
96
+ # # Return the stored chat completion object for later use
97
+ # return completion_result