Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure colab to use Azure OpenAI API #1705

Open
quartermaine opened this issue Feb 20, 2025 · 3 comments
Open

How to configure colab to use Azure OpenAI API #1705

quartermaine opened this issue Feb 20, 2025 · 3 comments

Comments

@quartermaine
Copy link

I am trying to run the colab found on the documentation.
How to set the env variables to use Azure OpenAI API?
I can't find the

~/.metagpt/config2.yaml

to update with Azure OpenAI API env variables.

@seehi
Copy link
Contributor

seehi commented Feb 20, 2025

可参考:#1690

@quartermaine
Copy link
Author

Hello @seehi,

Thanks for the quick response. I used the following to set the env variables

metagpt.const.API_KEY = userdata.get('OPENAI_API_KEY')
metagpt.const.MODEL = userdata.get('MODEL_NAME')
metagpt.const.API_TYPE = userdata.get('OPENAI_API_TYPE')
metagpt.const.API_VERSION = userdata.get('OPENAI_API_VERSION')
metagpt.const.BASE_URL = userdata.get('AZURE_OPENAI_ENDPOINT')

But when I run the cell

import asyncio

from metagpt.roles import (
    Architect,
    Engineer,
    ProductManager,
    ProjectManager,
)
from metagpt.team import Team

I am getting error

RecursionError                            Traceback (most recent call last)
[<ipython-input-5-46a1bd52cacd>](https://localhost:8080/#) in <cell line: 0>()
      1 import asyncio
      2 
----> 3 from metagpt.roles import (
      4     Architect,
      5     Engineer,

11 frames
... last 2 frames repeated, from the frame below ...

[/usr/local/lib/python3.11/dist-packages/metagpt/config.py](https://localhost:8080/#) in get_default_llm_provider_enum(self)
    112         if provider is LLMProviderEnum.GEMINI and not require_python_version(req_version=(3, 10)):
    113             warnings.warn("Use Gemini requires Python >= 3.10")
--> 114         model_name = self.get_model_name(provider=provider)
    115         if model_name:
    116             logger.info(f"{provider} Model: {model_name}")

RecursionError: maximum recursion depth exceeded while calling a Python object

@seehi
Copy link
Contributor

seehi commented Feb 20, 2025

Such as:

from pathlib import Path

import metagpt.const

# 1. Change CONFIG_ROOT
metagpt.const.CONFIG_ROOT = Path.cwd()

# 2. Create config2.yaml
content = '''llm:
  api_type: "openai"  # or azure / ollama / open_llm etc. Check LLMType for more options
  model: "gpt-4-turbo-preview"  # or gpt-3.5-turbo-1106 / gpt-4-1106-preview
  base_url: "https://api.openai.com/v1"  # or forward url / other llm url
  api_key: "xxx"'''

with open('config2.yaml', 'w') as f:
    f.write(content)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants