Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ client = InferenceClient(
|
|
| 23 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 24 |
)
|
| 25 |
history = []
|
|
|
|
| 26 |
|
| 27 |
def format_prompt(message, history):
|
| 28 |
prompt = "<s>"
|
|
@@ -32,12 +33,29 @@ def format_prompt(message, history):
|
|
| 32 |
prompt += f"[INST] {message} [/INST]"
|
| 33 |
return prompt
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
def run_gpt(
|
| 38 |
-
in_prompt
|
| 39 |
-
|
| 40 |
-
):
|
| 41 |
print(f'history :: {history}')
|
| 42 |
prompt=format_prompt(in_prompt,history)
|
| 43 |
seed = random.randint(1,1111111111111111)
|
|
@@ -50,15 +68,8 @@ def run_gpt(
|
|
| 50 |
do_sample=True,
|
| 51 |
seed=seed,
|
| 52 |
)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
content = agent.GENERATE_PROMPT + prompt
|
| 56 |
-
|
| 57 |
print(content)
|
| 58 |
-
|
| 59 |
-
#formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
| 60 |
-
#formatted_prompt = format_prompt(f'{content}', history)
|
| 61 |
-
|
| 62 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 63 |
resp = ""
|
| 64 |
for response in stream:
|
|
|
|
| 23 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 24 |
)
|
| 25 |
history = []
|
| 26 |
+
max_history=1000
|
| 27 |
|
| 28 |
def format_prompt(message, history):
|
| 29 |
prompt = "<s>"
|
|
|
|
| 33 |
prompt += f"[INST] {message} [/INST]"
|
| 34 |
return prompt
|
| 35 |
|
| 36 |
+
def condense(in_prompt):
|
| 37 |
+
seed = random.randint(1,1111111111111111)
|
| 38 |
+
print (seed)
|
| 39 |
+
generate_kwargs = dict(
|
| 40 |
+
temperature=1.0,
|
| 41 |
+
max_new_tokens=512,
|
| 42 |
+
top_p=0.99,
|
| 43 |
+
repetition_penalty=1.0,
|
| 44 |
+
do_sample=True,
|
| 45 |
+
seed=seed,
|
| 46 |
+
)
|
| 47 |
+
content = agent.CONDENSE_PROMPT + prompt
|
| 48 |
+
print(f'CONDENSED:: {content}')
|
| 49 |
|
| 50 |
+
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 51 |
+
resp = ""
|
| 52 |
+
for response in stream:
|
| 53 |
+
resp += response.token.text
|
| 54 |
+
return resp
|
| 55 |
|
| 56 |
+
def run_gpt(in_prompt,history,):
|
| 57 |
+
if len(in_prompt)>max_prompt:
|
| 58 |
+
in_prompt = condense(in_prompt)
|
|
|
|
| 59 |
print(f'history :: {history}')
|
| 60 |
prompt=format_prompt(in_prompt,history)
|
| 61 |
seed = random.randint(1,1111111111111111)
|
|
|
|
| 68 |
do_sample=True,
|
| 69 |
seed=seed,
|
| 70 |
)
|
|
|
|
|
|
|
| 71 |
content = agent.GENERATE_PROMPT + prompt
|
|
|
|
| 72 |
print(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 74 |
resp = ""
|
| 75 |
for response in stream:
|