from langchain.agents import load_tools
from langchain.tools import AIPluginTool
from parse import *
from langchain.chat_models.base import BaseChatModel
from langchain.chat_models import ChatOpenAI, AzureChatOpenAI

import utils


def create_plugins_static():
    plugins = [
        AIPluginTool.from_plugin_url(
            "https://www.klarna.com/.well-known/ai-plugin.json"
        )
    ]
    plugins += load_tools(["requests_all"])
    return plugins


def create_chat_model(openai_config: utils.OpenAIConfig) -> BaseChatModel:
    if openai_config.is_azure_openai():
        return AzureChatOpenAI(
            temperature=0,
            openai_api_base=openai_config.AZURE_OPENAI_API_ENDPOINT,
            openai_api_version=openai_config.AZURE_OPENAI_API_VERSION
            if openai_config.AZURE_OPENAI_API_VERSION
            else "2023-03-15-preview",
            deployment_name=openai_config.AZURE_OPENAI_API_DEPLOYMENT_NAME,
            openai_api_key=openai_config.OPENAI_API_KEY,
            openai_api_type=openai_config.OPENAI_API_TYPE,
        )
    else:
        return ChatOpenAI(
            temperature=0,
            openai_api_key=openai_config.OPENAI_API_KEY,
            openai_organization=openai_config.OPENAI_ORG_ID,
            model_name=openai_config.OPENAI_MODEL_ID,
        )

langchain.tools.AIPluginTool.from_plugin_url langchain.chat_models.AzureChatOpenAI langchain.agents.load_tools langchain.chat_models.ChatOpenAI
[((410, 438), 'langchain.agents.load_tools', 'load_tools', (["['requests_all']"], {}), "(['requests_all'])\n", (420, 438), False, 'from langchain.agents import load_tools\n'), ((285, 371), 'langchain.tools.AIPluginTool.from_plugin_url', 'AIPluginTool.from_plugin_url', (['"""https://www.klarna.com/.well-known/ai-plugin.json"""'], {}), "(\n    'https://www.klarna.com/.well-known/ai-plugin.json')\n", (313, 371), False, 'from langchain.tools import AIPluginTool\n'), ((590, 984), 'langchain.chat_models.AzureChatOpenAI', 'AzureChatOpenAI', ([], {'temperature': '(0)', 'openai_api_base': 'openai_config.AZURE_OPENAI_API_ENDPOINT', 'openai_api_version': "(openai_config.AZURE_OPENAI_API_VERSION if openai_config.\n    AZURE_OPENAI_API_VERSION else '2023-03-15-preview')", 'deployment_name': 'openai_config.AZURE_OPENAI_API_DEPLOYMENT_NAME', 'openai_api_key': 'openai_config.OPENAI_API_KEY', 'openai_api_type': 'openai_config.OPENAI_API_TYPE'}), "(temperature=0, openai_api_base=openai_config.\n    AZURE_OPENAI_API_ENDPOINT, openai_api_version=openai_config.\n    AZURE_OPENAI_API_VERSION if openai_config.AZURE_OPENAI_API_VERSION else\n    '2023-03-15-preview', deployment_name=openai_config.\n    AZURE_OPENAI_API_DEPLOYMENT_NAME, openai_api_key=openai_config.\n    OPENAI_API_KEY, openai_api_type=openai_config.OPENAI_API_TYPE)\n", (605, 984), False, 'from langchain.chat_models import ChatOpenAI, AzureChatOpenAI\n'), ((1093, 1263), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0)', 'openai_api_key': 'openai_config.OPENAI_API_KEY', 'openai_organization': 'openai_config.OPENAI_ORG_ID', 'model_name': 'openai_config.OPENAI_MODEL_ID'}), '(temperature=0, openai_api_key=openai_config.OPENAI_API_KEY,\n    openai_organization=openai_config.OPENAI_ORG_ID, model_name=\n    openai_config.OPENAI_MODEL_ID)\n', (1103, 1263), False, 'from langchain.chat_models import ChatOpenAI, AzureChatOpenAI\n')]