peterpeter8585 commited on
Commit
e95965f
·
verified ·
1 Parent(s): 043e03d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -34
app.py CHANGED
@@ -123,44 +123,20 @@ def search(term, num_results=1, lang="en", advanced=True, sleep_interval=0, time
123
  return all_results
124
 
125
 
126
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
127
 
128
-
129
- def respond(
130
- message,
131
- history: list[tuple[str, str]],
132
- system_message,
133
- max_tokens,
134
- temperature,
135
- top_p,
136
- ):
137
  web_results = search(message)
138
  web2 = ' '.join([f"Link: {res['link']}\nText: {res['text']}\n\n" for res in web_results])
139
- messages1 = "Your name is Chatchat.Answer as Real OpenGPT 4o, Made by 'peterpeter8585', Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses. The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant.If the user asks with Korean, you must answer with Korean.Or if the user asks with English, you have to answer with English.Do not transelate it.This is the web search result, use it to answer the user's questions:"+web2+"And the instructions:"+system_message
140
- messages = [{"role": "system", "content":messages1}]
141
-
142
- for val in history:
143
- if val[0]:
144
- messages.append({"role": "user", "content": val[0]})
145
- if val[1]:
146
- messages.append({"role": "assistant", "content": val[1]})
147
-
148
- messages.append({"role": "user", "content": message})
149
-
150
-
151
- response = ""
152
-
153
- for message in client.chat_completion(
154
- messages,
155
- max_tokens=max_tokens,
156
- stream=True,
157
- temperature=temperature,
158
- top_p=top_p,
159
- ):
160
- token = message.choices[0].delta.content
161
 
162
- response += token
163
- yield response
164
 
165
  examples = [
166
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
 
123
  return all_results
124
 
125
 
126
+ client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
127
 
128
+ def model(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p):
129
+ system_instructions1 = "<s>[SYSTEM]Your name is Chatchat.Answer as Real OpenGPT 4o, Made by 'peterpeter8585', Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses. The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant.the instructions: "+system_message+"[USER]"
130
+ """Performs a web search, feeds the results to a language model, and returns the answer."""
 
 
 
 
 
 
131
  web_results = search(message)
132
  web2 = ' '.join([f"Link: {res['link']}\nText: {res['text']}\n\n" for res in web_results])
133
+ formatted_prompt = system_instructions1 + message + "[WEB]" + str(web2) + "[OpenGPT 4o]"
134
+ stream = client.text_generation(formatted_prompt, max_new_tokens=max_tokens, stream=True, temperature=temperature, details=True, return_full_text=False, top_p=top_p)
135
+ response = ""
136
+ token = "".join([response.token.text for response in stream if response.token.text != "</s>"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
+ response += token
139
+ yield response
140
 
141
  examples = [
142
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",