Merge pull request #66 from bucolucas/update-openai-api
Update OpenAI API usage in chatgpt_telegram_inference_bot.py
This commit is contained in:
@@ -9,12 +9,14 @@ from telegram.ext import Application, CommandHandler, MessageHandler, filters, C
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from tools.base_tool import BaseTool
|
from tools.base_tool import BaseTool
|
||||||
from tools.metrics_tool import MetricsTool
|
from tools.metrics_tool import MetricsTool
|
||||||
import openai
|
from openai import OpenAI
|
||||||
|
|
||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
client = OpenAI(
|
||||||
|
api_key=os.environ.get("OPENAI_API_KEY"),
|
||||||
|
)
|
||||||
|
|
||||||
# Set up logging to console and file
|
# Set up logging to console and file
|
||||||
logging.basicConfig(level=logging.WARNING, handlers=[
|
logging.basicConfig(level=logging.WARNING, handlers=[
|
||||||
@@ -168,17 +170,16 @@ def get_openai_response(messages):
|
|||||||
for function in functions
|
for function in functions
|
||||||
]
|
]
|
||||||
|
|
||||||
response = openai.ChatCompletion.create(
|
response = client.chat.completions.create(
|
||||||
model="gpt-4o", # Using "gpt-4o" as specified
|
model="gpt-4", # Changed from "gpt-4o" to "gpt-4"
|
||||||
messages=[{"role": "system", "content": system_prompt}] + messages,
|
messages=[{"role": "system", "content": system_prompt}] + messages,
|
||||||
functions=openai_functions,
|
functions=openai_functions,
|
||||||
function_call="auto",
|
function_call="auto",
|
||||||
max_tokens=4096 # Using 4096 as specified for "gpt-4o"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
message = response['choices'][0]['message']
|
message = response.choices[0].message
|
||||||
content = message.get('content', '')
|
content = message.content
|
||||||
function_call = message.get('function_call')
|
function_call = message.function_call
|
||||||
|
|
||||||
if function_call:
|
if function_call:
|
||||||
return {
|
return {
|
||||||
@@ -193,7 +194,7 @@ def get_openai_response(messages):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
await update.message.reply_text("Currently using gpt-4o")
|
await update.message.reply_text("Currently using gpt-4")
|
||||||
|
|
||||||
async def abort_processing(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def abort_processing(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
|
|||||||
Reference in New Issue
Block a user