updated names of bots

This commit is contained in:
2024-08-19 10:27:20 -05:00
parent acba08bbc2
commit 847d5ccd10
2 changed files with 22 additions and 19 deletions
@@ -9,13 +9,15 @@ from telegram.ext import Application, CommandHandler, MessageHandler, filters, C
from dotenv import load_dotenv
from tools.base_tool import BaseTool
from tools.metrics_tool import MetricsTool
import openai
from openai import OpenAI
# Load environment variables
load_dotenv()
openai.api_key = os.environ.get("OPENAI_API_KEY")
openai.api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1")
openai_client = OpenAI(
api_key=os.environ.get("GLHF_CHAT_API_KEY"),
base_url=os.environ.get("GLHF_CHAT_API_BASE", "https://api.openai.com/v1")
)
# Set up logging to console and file
logging.basicConfig(level=logging.WARNING, handlers=[
@@ -55,7 +57,7 @@ for tool in tools:
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
logging.info("Bot started")
await update.message.reply_text(
"Hello! I'm your AI assistant. How can I help you today? You can send me images and then ask questions about them."
"Hello! I'm your AI assistant. How can I help you today?"
)
async def clear(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
@@ -65,8 +67,8 @@ async def clear(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
for tool in tools:
tool.clear()
logging.info(f"Cleared conversation history and image for user {user_id}")
await update.message.reply_text("Conversation history and image cleared. Let's start fresh!")
logging.info(f"Cleared conversation history for user {user_id}")
await update.message.reply_text("Conversation history cleared. Let's start fresh!")
async def update_status_message(context: ContextTypes.DEFAULT_TYPE, chat_id: int, message_id: int, status: str):
keyboard = [
@@ -99,9 +101,13 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
messages = conversation_history[user_id]
response = get_chat_response(messages)
tool_calls = response.get('tool_calls', [])
assistant_message = response.get('content', '')
messages.append({"role": "assistant", "content": assistant_message})
tool_calls = []
for choice in response.choices:
if choice.finish_reason == "tool_calls":
tool_calls.append(choice)
else:
assistant_message = choice.message.content
messages.append({"role": "assistant", "content": assistant_message})
toolUseCount = 0
previous_function_name = ""
@@ -153,22 +159,19 @@ def call_tool(function_call):
return tool.execute(function_name, **function_args)
def get_chat_response(messages):
return get_openai_response(messages)
def get_openai_response(messages):
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # You can change this to your desired model
response = openai_client.chat.completions.create(
model="hf:meta-llama/Meta-Llama-3.1-405B-Instruct", # You can change this to your desired model
messages=[{"role": "system", "content": system_prompt}] + messages,
max_tokens=1000,
temperature=0.7,
max_tokens=4096,
temperature=0.6,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
functions=functions,
function_call="auto"
tools=functions
#tool_choice={ }
)
return response['choices'][0]['message']
return response
except Exception as e:
logging.error(f"An error occurred: {str(e)}")
return None