mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
fx and upgd
This commit is contained in:
+10
-19
@@ -54,7 +54,7 @@ async def _openai_call(messages, model, temperature=0.2):
|
|||||||
input=messages,
|
input=messages,
|
||||||
)
|
)
|
||||||
# SDK zapewnia output_text dla zwykłych odpowiedzi
|
# SDK zapewnia output_text dla zwykłych odpowiedzi
|
||||||
return (getattr(resp, "output_text", None) or "").strip() or str(resp)
|
return (getattr(resp.output_text, "output_text", None) or "").strip() or str(resp.output_text)
|
||||||
|
|
||||||
|
|
||||||
def create_vector_store():
|
def create_vector_store():
|
||||||
@@ -248,15 +248,11 @@ async def handle_response(
|
|||||||
# ...przygotowanie messages/system prompt/itp. jak masz...
|
# ...przygotowanie messages/system prompt/itp. jak masz...
|
||||||
# retry/backoff + deadline (zachowuje Twoją semantykę logowania)
|
# retry/backoff + deadline (zachowuje Twoją semantykę logowania)
|
||||||
timeout_sec = 120
|
timeout_sec = 120
|
||||||
max_retries = 3
|
|
||||||
deadline = time.time() + timeout_sec
|
deadline = time.time() + timeout_sec
|
||||||
for _ in range(max_retries):
|
response = await asyncio.wait_for(
|
||||||
if time.time() > deadline:
|
_openai_call(messages=history, model=algorithm),
|
||||||
break
|
timeout=max(0.1, deadline - time.time())
|
||||||
response = await asyncio.wait_for(
|
)
|
||||||
_openai_call(messages=history, model=algorithm),
|
|
||||||
timeout=max(0.1, deadline - time.time())
|
|
||||||
)
|
|
||||||
|
|
||||||
except openai.APITimeoutError as e:
|
except openai.APITimeoutError as e:
|
||||||
# Handle timeout error, e.g. retry or log
|
# Handle timeout error, e.g. retry or log
|
||||||
@@ -302,12 +298,7 @@ async def handle_response(
|
|||||||
logger.info("Historia wysłana:")
|
logger.info("Historia wysłana:")
|
||||||
logger.info(history)
|
logger.info(history)
|
||||||
await asyncio.sleep(15)
|
await asyncio.sleep(15)
|
||||||
result = ""
|
temp = {"role": "assistant", "content": response}
|
||||||
logger.debug("Odpowiedzi")
|
|
||||||
logger.info(response)
|
|
||||||
logger.info("Sformatowane odpowiedzi")
|
|
||||||
logger.info(result)
|
|
||||||
temp = {"role": "assistant", "content": result}
|
|
||||||
history.append(temp)
|
history.append(temp)
|
||||||
if request_type == "MUSIC":
|
if request_type == "MUSIC":
|
||||||
with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file_music_memory:
|
with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file_music_memory:
|
||||||
@@ -318,7 +309,7 @@ async def handle_response(
|
|||||||
file_music_memory.seek(0)
|
file_music_memory.seek(0)
|
||||||
# convert back to json.
|
# convert back to json.
|
||||||
json.dump(file_data, file_music_memory, indent=4)
|
json.dump(file_data, file_music_memory, indent=4)
|
||||||
return result, MESSAGE_TABLE_MUZYKA
|
return response, MESSAGE_TABLE_MUZYKA
|
||||||
elif request_type == "RANDOM":
|
elif request_type == "RANDOM":
|
||||||
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory:
|
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory:
|
||||||
# First we load existing data into a dict.
|
# First we load existing data into a dict.
|
||||||
@@ -328,7 +319,7 @@ async def handle_response(
|
|||||||
file_memory.seek(0)
|
file_memory.seek(0)
|
||||||
# convert back to json.
|
# convert back to json.
|
||||||
json.dump(file_data, file_memory, indent=4)
|
json.dump(file_data, file_memory, indent=4)
|
||||||
return result, MESSAGE_TABLE
|
return response, MESSAGE_TABLE
|
||||||
elif request_type == "GENERAL":
|
elif request_type == "GENERAL":
|
||||||
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory:
|
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory:
|
||||||
# First we load existing data into a dict.
|
# First we load existing data into a dict.
|
||||||
@@ -338,9 +329,9 @@ async def handle_response(
|
|||||||
file_memory.seek(0)
|
file_memory.seek(0)
|
||||||
# convert back to json.
|
# convert back to json.
|
||||||
json.dump(file_data, file_memory, indent=4)
|
json.dump(file_data, file_memory, indent=4)
|
||||||
return result, MESSAGE_TABLE
|
return response, MESSAGE_TABLE
|
||||||
else:
|
else:
|
||||||
return result, []
|
return response, []
|
||||||
|
|
||||||
async def get_random_cyclic_message(client):
|
async def get_random_cyclic_message(client):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user