question

Upvotes
3 1 1 1

Please help to modify the below code to use AzureopenAI, thanks.

Original article: https://developers.lseg.com/en/article-catalog/article/bond-copilot--unleashing-rd-lib-search-api-with-ai-llm-langchain


original code using openAI:

df = bond_copilot("list all the active green bonds")

# Importing necessary modules to facilitate data analysis using natural language processing.

from langchain.llms import OpenAI

from langchain.agents import create_pandas_dataframe_agent,create_csv_agent

# Creating an agent that allows us to perform natural language queries on the dataset.

# The agent uses ChatGPT, OpenAI's language model to understand and process the queries.

bond_analytics = create_pandas_dataframe_agent(OpenAI(temperature=0, openai_api_key='YOUR OPENAI API KEY'), df, verbose=False)

#bond_analytics = create_csv_agent(OpenAI(temperature=0), "green_bond.csv", verbose=False)


My code

from langchain.llms import AzureOpenAI

from langchain_experimental.agent import create_panda_dataframe,create_csv_agent

llm1=AzureOpenAI(temperature=0,azure_deployment="gpt-35-turbo",api_version="2024-02-01",azure_endpoint="xxx",api_key="xxx")

bond_analytics = create_pandas_dataframe_agent(llm1,df,verbose=False)


Error code:

BadRequestError: Error code: 400 - {'message': "Streaming completion is not support yet, please remove 'stream' key value in the request payload."}
python#technologyrefinitiv-data-libraries
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thank you,

AHS


Upvotes
14.2k 30 5 10

Hi @georgelocw ,

I found the solution below suggested in this issue. Could you please try if it works?

Could you make sure that you are providing the correct url for your azure deployment? It should look like this "https://your-endpoint-base.openai.azure.com/openai/deployments/your-azure-model-name/completions?api-version=2022-12-01". And if you provide the right url, then it shouldn't try to stream.
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 1 1 1

Thank raksina.samasiri.

My original path : https://hkust.azure-api.net

I tried a new one: https://hkust.azure-api.net/openai/deployments/gpt-35-turbo/completions?api-version=2024-02-01

Both give the same error code.

But I can run the first part of the code in https://developers.lseg.com/en/article-catalog/article/bond-copilot--unleashing-rd-lib-search-api-with-ai-llm-langchain


By modification of the original code from

from langchain.chat_models import ChatOpenAI

llm = ChatOpenAI(temperature=0, model_name='gpt-3.5-turbo', openai_api_key='YOUR OPENAI API KEY')


to below code

from langchain.chat_models import AzureChatOpenAI

llm = AzureChatOpenAI(temperature=0,azure_deployment="gpt-35-turbo",api_version="2024-02-01",azure_endpoint="https://hkust.azure-api.net", api_key="xxxxxxx")

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.