davoodwadi commited on
Commit
31b44f7
1 Parent(s): bb1e6f5

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +25 -28
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,14 +1,16 @@
1
  import gradio as gr
2
  import time
3
- from llama_cpp import Llama
4
- from pathlib import Path
5
- from tqdm.auto import tqdm
6
  import re
 
7
 
8
- llm = Llama(model_path="./snorkel-mistral-pairrm-dpo.Q4_K_M.gguf",
9
- chat_format="chatml",
10
- n_gpu_layers=0, # cpu only
11
- n_ctx=6000)
 
 
 
12
  def split_text(text, llm, chunk_size):
13
  text_newline = text.split('\n')
14
  text_newline = [t for t in text_newline if len(t)>0]
@@ -83,17 +85,22 @@ def adverse(message, history):
83
  # response_iter
84
  # response_str = f'writer {len(writer_messages)}' if turn=='writer' else f'editor {len(editor_messages)}'
85
  # response_iter = iter(response_str.split(' '))
86
- response_iter = llm.create_chat_completion(
87
- list_of_messages, # Prompt
88
- max_tokens=-1,
89
- stop=["###"],
90
- stream=True
91
- )
 
 
 
 
 
92
  response=''
93
  for chunk in response_iter:
94
  try:
95
- response+=chunk['choices'][0]['delta']['content']
96
- total_response+=chunk['choices'][0]['delta']['content']
97
  time.sleep(1)
98
  # print(f'chunk: {chunk}')
99
  yield total_response
@@ -130,19 +137,14 @@ max_words = 10_000
130
  print(f'max_words: {max_words}')
131
  # llm = Llama(model_path="E:\\yt\\bookSummary/Snorkel-Mistral-PairRM-DPO/snorkel-mistral-pairrm-dpo.Q4_K_M.gguf", chat_format="chatml", n_gpu_layers=-1, n_ctx=6000)
132
 
133
- setting = 'Scotland in twenty twenty five'
134
- book = 'The Great Gatsby by F. Scott Fitzgerald'
135
- total_summary=''
136
  writer_system_prompt_unformatted = '''You are a writer.
137
- The topic is {topic}.
138
- I am your writing editor. I will give you feedback to guide your response in the right direction. You will obey my feedback adjust your response based on my feedback.'''
139
 
140
- editor_system_prompt_unformatted = '''You are an editor.
141
  The topic is {topic}.
142
  You should reinforce me to adjust my content and improve it.
143
- You should push me to make my response as close as possible to the topic'''
144
 
145
- # print(writer_system_prompt.format(book=book, setting=setting))
146
 
147
  writer_messages = [{'role':'system','content':writer_system_prompt_unformatted}]
148
  editor_messages = [{'role':'system','content':editor_system_prompt_unformatted}]
@@ -161,11 +163,6 @@ with gr.Blocks() as demo:
161
  # Multi Agent LLMs for End-to-End Story Generation
162
  Start typing below to see the output.
163
  """)
164
- # inp_topic = gr.Textbox(placeholder="What is the topic?", label = 'Topic', lines=4)
165
- # # inp_setting = gr.Textbox(placeholder="What is the setting of the book?", label='Setting')
166
- # out_system = gr.Textbox(label='System prompt to use', lines=4)
167
- # button = gr.Button("Set system prompt")
168
- # button.click(set_system_prompts, inputs=inp_topic, outputs=out_system)
169
  gr.Interface(
170
  fn=set_system_prompts,
171
  inputs=gr.Textbox(placeholder="What is the topic?", label = 'Topic', lines=4),
 
1
  import gradio as gr
2
  import time
3
+ from openai import OpenAI
 
 
4
  import re
5
+ import os
6
 
7
+ client = OpenAI(api_key=os.environ.get("openai"))
8
+ model="gpt-3.5-turbo"
9
+
10
+ # llm = Llama(model_path="./snorkel-mistral-pairrm-dpo.Q4_K_M.gguf",
11
+ # chat_format="chatml",
12
+ # n_gpu_layers=0, # cpu only
13
+ # n_ctx=6000)
14
  def split_text(text, llm, chunk_size):
15
  text_newline = text.split('\n')
16
  text_newline = [t for t in text_newline if len(t)>0]
 
85
  # response_iter
86
  # response_str = f'writer {len(writer_messages)}' if turn=='writer' else f'editor {len(editor_messages)}'
87
  # response_iter = iter(response_str.split(' '))
88
+ # response_iter = llm.create_chat_completion(
89
+ # list_of_messages, # Prompt
90
+ # max_tokens=-1,
91
+ # stop=["###"],
92
+ # stream=True
93
+ # )
94
+ response_iter = client.chat.completions.create(
95
+ model=model,
96
+ messages=list_of_messages,
97
+ stream=True,
98
+ )
99
  response=''
100
  for chunk in response_iter:
101
  try:
102
+ response+=chunk.choices[0].delta.content
103
+ total_response+=chunk.choices[0].delta.content
104
  time.sleep(1)
105
  # print(f'chunk: {chunk}')
106
  yield total_response
 
137
  print(f'max_words: {max_words}')
138
  # llm = Llama(model_path="E:\\yt\\bookSummary/Snorkel-Mistral-PairRM-DPO/snorkel-mistral-pairrm-dpo.Q4_K_M.gguf", chat_format="chatml", n_gpu_layers=-1, n_ctx=6000)
139
 
 
 
 
140
  writer_system_prompt_unformatted = '''You are a writer.
141
+ The topic is {topic}.'''
 
142
 
143
+ editor_system_prompt_unformatted = '''You are an editor. You give feedback about my writing.
144
  The topic is {topic}.
145
  You should reinforce me to adjust my content and improve it.
146
+ You should push me to make my response as close as possible to the topic.'''
147
 
 
148
 
149
  writer_messages = [{'role':'system','content':writer_system_prompt_unformatted}]
150
  editor_messages = [{'role':'system','content':editor_system_prompt_unformatted}]
 
163
  # Multi Agent LLMs for End-to-End Story Generation
164
  Start typing below to see the output.
165
  """)
 
 
 
 
 
166
  gr.Interface(
167
  fn=set_system_prompts,
168
  inputs=gr.Textbox(placeholder="What is the topic?", label = 'Topic', lines=4),
requirements.txt CHANGED
@@ -1 +1 @@
1
- llama-cpp-python
 
1
+ openai