add-assistant #2

Merged
Ari merged 8 commits from add-assistant into main 2024-08-06 01:14:25 +00:00
1 changed files with 22 additions and 14 deletions
Showing only changes of commit 669c2c2bfa - Show all commits

View File

@ -2,7 +2,7 @@ import os
import logging
import pandas as pd
from openai import OpenAI
import textwrap
class OpenAIResourceManager:
"""
@ -105,15 +105,15 @@ class OpenAIResourceManager:
self.delete_all_vector_stores()
self.delete_all_files()
def truncate_string(self, s, max_length=50):
def wrap_text(self, s, width=30):
"""
Truncate a string to a maximum length with ellipsis.
Wrap text to a specific width.
:param s: The string to truncate.
:param max_length: The maximum length of the string.
:return: The truncated string.
:param s: The string to wrap.
:param width: The maximum width of each line.
:return: The wrapped string.
"""
return (s[:max_length] + "...") if len(s) > max_length else s
return "\n".join(textwrap.wrap(s, width))
def show_all_assistants(self):
"""
@ -122,7 +122,7 @@ class OpenAIResourceManager:
assistants = self.get_all_assistants()
assistant_data = [
{
k: self.truncate_string(str(v), max_length=25)
k: self.wrap_text(str(v))
for k, v in assistant.dict().items()
}
for assistant in assistants
@ -137,7 +137,7 @@ class OpenAIResourceManager:
"""
vector_stores = self.get_all_vector_stores()
vector_store_data = [
{k: self.truncate_string(str(v)) for k, v in vector_store.dict().items()}
{k: self.wrap_text(str(v)) for k, v in vector_store.dict().items()}
for vector_store in vector_stores
]
df = pd.DataFrame(vector_store_data)
@ -150,13 +150,22 @@ class OpenAIResourceManager:
"""
files = self.get_all_files()
file_data = [
{k: self.truncate_string(str(v)) for k, v in file.dict().items()}
{k: self.wrap_text(str(v)) for k, v in file.dict().items()}
for file in files
]
df = pd.DataFrame(file_data)
print("Files:")
print(df.to_markdown(index=False))
def show_all_resources(self):
"""
Display all resources in a table.
"""
self.show_all_assistants()
print("")
self.show_all_vector_stores()
print("")
self.show_all_files()
if __name__ == "__main__":
# Get the OpenAI API key from the environment variables
@ -164,7 +173,6 @@ if __name__ == "__main__":
# Create an instance of the OpenAIResourceManager
manager = OpenAIResourceManager(api_key=api_key)
# Show all resources in tables
manager.show_all_assistants()
manager.show_all_vector_stores()
manager.show_all_files()
# Show or delete all resources in tables
manager.show_all_resources()
# manager.delete_all_resources()