My Docker container is not connecting with open ai when I run python code

I am trying to create an agent in OPEN AI, that would authenticate with VS code server based on user input. The VS code server is running in docker container docker-vscode-1. I ran following code in docker container:

import os
import requests
import logging
from requests.exceptions import RequestException
from dotenv import load_dotenv
from langchain_community.llms import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents.agent_types import AgentType
import warnings

warnings.simplefilter("ignore")
load_dotenv()

# Configuration
CODE_SERVER_URL = os.getenv("CODE_SERVER_URL", "http://172.20.0.2:8080")
PASSWORD = os.getenv("CODE_SERVER_PASSWORD", "yourpassword")
LOGIN_URL = f"{CODE_SERVER_URL}/login"
SESSION = requests.Session()
DEBUG = os.getenv("DEBUG", "False").lower() == "true"
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

# Set up logging
logging.basicConfig(
    level=logging.DEBUG if DEBUG else logging.INFO,
    format="%(asctime)s [%(levelname)s]: %(message)s"
)


def authenticate():
    """Authenticates with the code-server."""
    if not PASSWORD:
        logging.error("Password not set. Please set the 'CODE_SERVER_PASSWORD' environment variable.")
        return "Password not set."

    try:
        # Get the login page to retrieve CSRF token if needed (optional for code-server)
        response = SESSION.get(LOGIN_URL)
        response.raise_for_status()

        # Post the login credentials
        payload = {"password": PASSWORD}
        auth_response = SESSION.post(LOGIN_URL, data=payload)
        auth_response.raise_for_status()

        # Check if login was successful
        if auth_response.status_code == 200 and "code-server" in auth_response.text:
            logging.info("Authentication successful!")
            return "Authentication successful!"
        else:
            logging.warning("Authentication failed. Check your password or URL.")
            return "Authentication failed. Check your password or URL."

    except Exception as e:
        error_message = f"An unexpected error occurred: {e}"
        logging.error(error_message)
        return error_message


# Define the LangChain agent tools
tools = [
    Tool(
        name="Authenticate with Code-Server",
        func=authenticate,
        description="Authenticate with the VS code-server. 
            This is a one-time action and does not require further input. 
            This action completes immediately."
    )
]

# Initialize the LangChain agent with OpenAI's LLM
def main():
    retry_count = 0
    max_retries = 3

    
    llm = OpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)

    agent = initialize_agent(
        tools,
        llm,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True
    )

    # Agent loop to take user input
    print("Simple AI Agent is ready! Type 'exit' to quit.")
    while True:
        user_input = input("nEnter your instruction (type 'exit' to quit): ")
        if user_input.lower() in ["exit", "quit"]:
            print("Goodbye!")
            break

        try:
            # Get the agent's response for a single action
            response = agent.run(user_input)
            # Ensure that no further actions are taken after a single response
            if "Action:" in response:
                print("The AI has finished processing your request.")
            else:
                print(response)
    
        except Exception as e:
            logging.error(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

I received following error:

Traceback (most recent call last):
  File "/home/coder/project/temp/aiagent-vscode-using-openaiTODO.py", line 113, in <module>
    main()
  File "/home/coder/project/temp/aiagent-vscode-using-openaiTODO.py", line 83, in main
    llm = OpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/_api/deprecation.py", line 216, in warn_if_direct_instance
    return wrapped(self, *args, **kwargs)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/load/serializable.py", line 125, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/_internal/_decorators_v1.py", line 148, in _wrapper1
    return validator(values)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/utils/pydantic.py", line 219, in wrapper
    return func(cls, values)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_community/llms/openai.py", line 322, in validate_environment
    values["client"] = openai.OpenAI(**client_params).completions
  File "/usr/local/lib/python3.9/dist-packages/openai/_client.py", line 123, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/openai/_base_client.py", line 844, in __init__
    self._client = http_client or SyncHttpxClientWrapper(
  File "/usr/local/lib/python3.9/dist-packages/openai/_base_client.py", line 742, in __init__
    super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'proxies'

My operating system is windows. Any suggestions on how can I fix this ?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

My Docker container is not connecting with open ai when I run python code

I am trying to create an agent in OPEN AI, that would authenticate with VS code server based on user input. The VS code server is running in docker container docker-vscode-1. I ran following code in docker container:

import os
import requests
import logging
from requests.exceptions import RequestException
from dotenv import load_dotenv
from langchain_community.llms import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents.agent_types import AgentType
import warnings

warnings.simplefilter("ignore")
load_dotenv()

# Configuration
CODE_SERVER_URL = os.getenv("CODE_SERVER_URL", "http://172.20.0.2:8080")
PASSWORD = os.getenv("CODE_SERVER_PASSWORD", "yourpassword")
LOGIN_URL = f"{CODE_SERVER_URL}/login"
SESSION = requests.Session()
DEBUG = os.getenv("DEBUG", "False").lower() == "true"
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

# Set up logging
logging.basicConfig(
    level=logging.DEBUG if DEBUG else logging.INFO,
    format="%(asctime)s [%(levelname)s]: %(message)s"
)


def authenticate():
    """Authenticates with the code-server."""
    if not PASSWORD:
        logging.error("Password not set. Please set the 'CODE_SERVER_PASSWORD' environment variable.")
        return "Password not set."

    try:
        # Get the login page to retrieve CSRF token if needed (optional for code-server)
        response = SESSION.get(LOGIN_URL)
        response.raise_for_status()

        # Post the login credentials
        payload = {"password": PASSWORD}
        auth_response = SESSION.post(LOGIN_URL, data=payload)
        auth_response.raise_for_status()

        # Check if login was successful
        if auth_response.status_code == 200 and "code-server" in auth_response.text:
            logging.info("Authentication successful!")
            return "Authentication successful!"
        else:
            logging.warning("Authentication failed. Check your password or URL.")
            return "Authentication failed. Check your password or URL."

    except Exception as e:
        error_message = f"An unexpected error occurred: {e}"
        logging.error(error_message)
        return error_message


# Define the LangChain agent tools
tools = [
    Tool(
        name="Authenticate with Code-Server",
        func=authenticate,
        description="Authenticate with the VS code-server. 
            This is a one-time action and does not require further input. 
            This action completes immediately."
    )
]

# Initialize the LangChain agent with OpenAI's LLM
def main():
    retry_count = 0
    max_retries = 3

    
    llm = OpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)

    agent = initialize_agent(
        tools,
        llm,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True
    )

    # Agent loop to take user input
    print("Simple AI Agent is ready! Type 'exit' to quit.")
    while True:
        user_input = input("nEnter your instruction (type 'exit' to quit): ")
        if user_input.lower() in ["exit", "quit"]:
            print("Goodbye!")
            break

        try:
            # Get the agent's response for a single action
            response = agent.run(user_input)
            # Ensure that no further actions are taken after a single response
            if "Action:" in response:
                print("The AI has finished processing your request.")
            else:
                print(response)
    
        except Exception as e:
            logging.error(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

I received following error:

Traceback (most recent call last):
  File "/home/coder/project/temp/aiagent-vscode-using-openaiTODO.py", line 113, in <module>
    main()
  File "/home/coder/project/temp/aiagent-vscode-using-openaiTODO.py", line 83, in main
    llm = OpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/_api/deprecation.py", line 216, in warn_if_direct_instance
    return wrapped(self, *args, **kwargs)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/load/serializable.py", line 125, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/_internal/_decorators_v1.py", line 148, in _wrapper1
    return validator(values)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_core/utils/pydantic.py", line 219, in wrapper
    return func(cls, values)
  File "/home/coder/.local/lib/python3.9/site-packages/langchain_community/llms/openai.py", line 322, in validate_environment
    values["client"] = openai.OpenAI(**client_params).completions
  File "/usr/local/lib/python3.9/dist-packages/openai/_client.py", line 123, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/openai/_base_client.py", line 844, in __init__
    self._client = http_client or SyncHttpxClientWrapper(
  File "/usr/local/lib/python3.9/dist-packages/openai/_base_client.py", line 742, in __init__
    super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'proxies'

My operating system is windows. Any suggestions on how can I fix this ?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật