microsoft / lida

Automatic Generation of Visualizations and Infographics using Large Language Models
https://microsoft.github.io/lida/
MIT License
2.6k stars 266 forks source link

Bugfix: azure llm manager #55

Closed bx-h closed 9 months ago

bx-h commented 9 months ago

Environment

Problem

I'm an Azure OpenAI user and encountered an error when using the code snippet provided in the tutorial:

text_gen = llm(provider="openai", api_type="azure", api_base=os.environ["AZURE_OPENAI_BASE"], api_key=os.environ["AZURE_OPENAI_API_KEY"],    api_version="2023-07-01-preview") # for azure openai
lida = Manager(llm=text_gen)

Error: Manager.init() got an unexpected keyword argument 'llm'

When I change it to

lida = Manager(text_gen=text_gen)

Error: openai.error.InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.chat_completion.ChatCompletion'>

Suggested Changes

Consider updating the snippet to (which works well for me):

from llmx.generators.text.openai_textgen import OpenAITextGenerator
from llmx.generators.text.textgen import sanitize_provider

provider = sanitize_provider("azureopenai")
models = {}

text_gen = OpenAITextGenerator(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    api_base=os.environ["AZURE_OPENAI_BASE"],
    provider=provider,
    models=models
)
lida = Manager(text_gen=text_gen)
victordibia commented 9 months ago

Thanks for catching this.