* Modificati caricamento e chiamata di openai (aggiornati al nuovo SDK)

This commit is contained in:
trojanhorse47
2025-09-19 11:46:54 +02:00
parent 95559551a3
commit 6729a66d50

View File

@@ -2,11 +2,11 @@ import json
import os import os
from typing import Any from typing import Any
import requests
import openai
import anthropic import anthropic
from google.genai import Client import requests
from dotenv import load_dotenv from dotenv import load_dotenv
from google.genai import Client
from openai import OpenAI
load_dotenv() load_dotenv()
@@ -20,8 +20,12 @@ class PredictorAgent:
# OpenAI # OpenAI
openai_key = os.getenv("OPENAI_API_KEY") openai_key = os.getenv("OPENAI_API_KEY")
if openai_key: if openai_key:
openai.api_key = openai_key client = OpenAI(api_key=openai_key)
self.providers["openai"] = {"type": "openai", "client": openai, "model": "gpt-4o-mini"} self.providers["openai"] = {
"type": "openai",
"client": client,
"model": "gpt-4o-mini"
}
# Anthropic # Anthropic
anthropic_key = os.getenv("ANTHROPIC_API_KEY") anthropic_key = os.getenv("ANTHROPIC_API_KEY")
@@ -97,7 +101,7 @@ class PredictorAgent:
@staticmethod @staticmethod
def _predict_openai(prompt, client, model): def _predict_openai(prompt, client, model):
resp = client.ChatCompletion.create( resp = client.chat.completions.create(
model=model, model=model,
messages=[ messages=[
{"role": "system", "content": "Sei un consulente finanziario crypto."}, {"role": "system", "content": "Sei un consulente finanziario crypto."},
@@ -106,7 +110,7 @@ class PredictorAgent:
max_tokens=300, max_tokens=300,
temperature=0.7 temperature=0.7
) )
return resp["choices"][0]["message"]["content"].strip() return resp.choices[0].message.content.strip()
@staticmethod @staticmethod
def _predict_anthropic(prompt, client, model): def _predict_anthropic(prompt, client, model):