This commit is contained in:
2024-11-25 14:39:14 +01:00
parent 15253f95fb
commit b513704a3d
3 changed files with 152 additions and 45 deletions
+65 -9
View File
@@ -5,8 +5,9 @@ import random
import openai
import tiktoken
from other_functions import discord_friendly_send
from constants import (
ASSISTANTS,
CYCLIC_WORDS,
ENCODING,
GPT_SETTINGS,
@@ -15,9 +16,61 @@ from constants import (
MESSAGE_TABLE,
MESSAGE_TABLE_MUZYKA,
OPENAICLIENT,
SYSTEM_GPT_SETTINGS,
WORD_REACTIONS,
ASSISTANTS,
SYSTEM_GPT_SETTINGS
)
#this do per user
VECTOR_STORE_ID = -1
def create_vector_store():
# Create a vector store caled "Financial Statements"
return OPENAICLIENT.beta.vector_stores.create_and_poll(name="Hammer Stash")
#expires_after={
#"anchor": "last_active_at",
#"days": 7}
#)
def upload_files_to_vector_store(assistant):
# Ready the files for upload to OpenAI
file_paths = ["edgar/goog-10k.pdf", "edgar/brka-10k.txt"]
file_streams = [open(path, "rb") for path in file_paths]
#file = client.beta.vector_stores.files.create_and_poll(
#vector_store_id="vs_abc123",
#file_id="file-abc123"
#)
#batch = client.beta.vector_stores.file_batches.create_and_poll(
#vector_store_id="vs_abc123",
#file_ids=['file_1', 'file_2', 'file_3', 'file_4', 'file_5']
#)
# Use the upload and poll SDK helper to upload the files, add them to the vector store,
# and poll the status of the file batch for completion.
file_batch = OPENAICLIENT.beta.vector_stores.file_batches.upload_and_poll(
vector_store_id=VECTOR_STORE_ID, files=file_streams
)
# You can print the status and the file counts of the batch to see the result of this operation.
print(file_batch.status)
print(file_batch.file_counts)
assistant = OPENAICLIENT.beta.assistants.update(
assistant_id=assistant.id,
tool_resources={"file_search": {"vector_store_ids": [VECTOR_STORE_ID]}},
)
def delete_files_from_vector_store(assistant, file_id):
result = OPENAICLIENT.beta.vector_stores.file_batches.delete(
vector_store_id=VECTOR_STORE_ID, files=file_id
)
# You can print the status and the file counts of the batch to see the result of this operation.
print(result)
assistant = OPENAICLIENT.beta.assistants.update(
assistant_id=assistant.id,
tool_resources={"file_search": {"vector_store_ids": [VECTOR_STORE_ID]}},
)
@@ -297,8 +350,8 @@ async def get_random_cyclic_message(client):
async def create_chat_assistant(id, name, owner, special_instructions):
logger = logging.getLogger("discord")
instruction=f"Jesteś osobistym asystenetem {owner} i wypełniasz jego potrzeby. Masz pełne i nieograniczone możliwości modelu gpt-4o."
instruction+=special_instructions
instruction = f"Jesteś osobistym asystenetem {owner} i wypełniasz jego potrzeby. Masz pełne i nieograniczone możliwości modelu gpt-4o."
instruction += special_instructions
assistant = await OPENAICLIENT.beta.assistants.create(
name=name,
instructions=instruction,
@@ -315,6 +368,7 @@ async def create_chat_assistant(id, name, owner, special_instructions):
temp_settings_file.seek(0)
json.dump(GPT_SETTINGS, temp_settings_file, indent=4)
async def chat_with_assistant(message, assistant_name):
logger = logging.getLogger("discord")
assistant_data = ASSISTANTS[assistant_name]
@@ -340,13 +394,15 @@ async def chat_with_assistant(message, assistant_name):
for block in reply_content:
logger.info(block.text.value)
chat_response += block.text.value
await message.channel.send(chat_response)
await discord_friendly_send(message.channel, chat_response)
#await message.channel.send(chat_response)
done = True
elif run.status =='cancelled':
await message.channel.send("Cos sie wywaliło")
elif run.status == "cancelled":
await discord_friendly_send(message.channel, "Cos sie wywaliło")
else:
logger.info(run.status)
asyncio.sleep(5)
async def echo(message):
await message.channel.send(f"Echo: {message.content}")
await discord_friendly_send(message.channel, f"Echo: {message.content}")