Update backend/query_llm.py
Browse files- backend/query_llm.py +20 -20
backend/query_llm.py
CHANGED
|
@@ -24,10 +24,10 @@ HF_TOKEN = getenv("HUGGING_FACE_HUB_TOKEN")
|
|
| 24 |
# )
|
| 25 |
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
def format_prompt(message: str, api_kind: str):
|
| 32 |
"""
|
| 33 |
Formats the given message using a chat template.
|
|
@@ -83,24 +83,24 @@ def generate_hf(prompt: str, history: str, temperature: float = 0.5, max_new_tok
|
|
| 83 |
formatted_prompt = format_prompt(prompt, "hf")
|
| 84 |
|
| 85 |
try:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
client_Qwen = Client("Qwen/Qwen1.5-110B-Chat-demo")
|
| 89 |
-
response = client_Qwen.predict(
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
api_output = response[1] if response and len(response) > 1 else "No output received from the API."
|
| 97 |
|
| 98 |
-
|
| 99 |
-
print(response)
|
| 100 |
|
| 101 |
-
# Print the generated code
|
| 102 |
-
print(api_output[0][1])
|
| 103 |
-
stream=api_output[0][1]
|
| 104 |
output = ""
|
| 105 |
for response in stream:
|
| 106 |
output += response.token.text
|
|
|
|
| 24 |
# )
|
| 25 |
|
| 26 |
|
| 27 |
+
hf_client = InferenceClient(
|
| 28 |
+
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 29 |
+
token=HF_TOKEN
|
| 30 |
+
)
|
| 31 |
def format_prompt(message: str, api_kind: str):
|
| 32 |
"""
|
| 33 |
Formats the given message using a chat template.
|
|
|
|
| 83 |
formatted_prompt = format_prompt(prompt, "hf")
|
| 84 |
|
| 85 |
try:
|
| 86 |
+
stream = hf_client.text_generation(formatted_prompt, **generate_kwargs,
|
| 87 |
+
stream=True, details=True, return_full_text=False)
|
| 88 |
+
# client_Qwen = Client("Qwen/Qwen1.5-110B-Chat-demo")
|
| 89 |
+
# response = client_Qwen.predict(
|
| 90 |
+
# query=prompt,
|
| 91 |
+
# history=[],
|
| 92 |
+
# system="You are a helpful assistant.",
|
| 93 |
+
# api_name="/model_chat"
|
| 94 |
+
# )
|
| 95 |
+
# # Extract the API output text
|
| 96 |
+
# api_output = response[1] if response and len(response) > 1 else "No output received from the API."
|
| 97 |
|
| 98 |
+
# #chatbot_responses.append((txt, api_output[0][1]))
|
| 99 |
+
# print(response)
|
| 100 |
|
| 101 |
+
# # Print the generated code
|
| 102 |
+
# print(api_output[0][1])
|
| 103 |
+
# stream=api_output[0][1]
|
| 104 |
output = ""
|
| 105 |
for response in stream:
|
| 106 |
output += response.token.text
|