Spaces:
Runtime error
Runtime error
Aleksandr Maiorov
commited on
Commit
·
7ba9eb3
1
Parent(s):
c2f54d4
v 0.1
Browse files- правка формата ответа
app.py
CHANGED
@@ -40,9 +40,9 @@ llm = LlamaCPP(
|
|
40 |
# optionally, you can set the path to a pre-downloaded model instead of model_url
|
41 |
model_path=None,
|
42 |
temperature=0.1,
|
43 |
-
max_new_tokens=
|
44 |
# llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
|
45 |
-
context_window=
|
46 |
# kwargs to pass to __call__()
|
47 |
generate_kwargs={},
|
48 |
# kwargs to pass to __init__()
|
@@ -54,6 +54,24 @@ llm = LlamaCPP(
|
|
54 |
verbose=True,
|
55 |
)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
@app.get("/")
|
58 |
def greet_json():
|
59 |
return {"Hello": "World!"}
|
@@ -69,4 +87,5 @@ async def predict(text: str):
|
|
69 |
# Генерация ответа с помощью модели
|
70 |
logger.info('post/predict')
|
71 |
response = llm.complete(text)
|
72 |
-
|
|
|
|
40 |
# optionally, you can set the path to a pre-downloaded model instead of model_url
|
41 |
model_path=None,
|
42 |
temperature=0.1,
|
43 |
+
max_new_tokens=256,
|
44 |
# llama2 has a context window of 4096 tokens, but we set it lower to allow for some wiggle room
|
45 |
+
context_window=16384,
|
46 |
# kwargs to pass to __call__()
|
47 |
generate_kwargs={},
|
48 |
# kwargs to pass to __init__()
|
|
|
54 |
verbose=True,
|
55 |
)
|
56 |
|
57 |
+
def generate_response(text):
|
58 |
+
try:
|
59 |
+
# Обработка текстового сообщения
|
60 |
+
logger.info('Output:')
|
61 |
+
logger.info(text)
|
62 |
+
|
63 |
+
response = text['choices'][0]['text']
|
64 |
+
|
65 |
+
# Отправка ответа
|
66 |
+
if response:
|
67 |
+
return response
|
68 |
+
|
69 |
+
return 'Произошла ошибка при обработке запроса'
|
70 |
+
|
71 |
+
except Exception as e:
|
72 |
+
logger.error(f"Ошибка обработки сообщения: {str(e)}")
|
73 |
+
|
74 |
+
|
75 |
@app.get("/")
|
76 |
def greet_json():
|
77 |
return {"Hello": "World!"}
|
|
|
87 |
# Генерация ответа с помощью модели
|
88 |
logger.info('post/predict')
|
89 |
response = llm.complete(text)
|
90 |
+
text = generate_response(response)
|
91 |
+
return {"response": text}
|