Significant-Gravitas / AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
https://agpt.co
MIT License
166.45k stars 44.06k forks source link

Using Azure Open AI return this error on function update_cost #4678

Closed arananet closed 12 months ago

arananet commented 1 year ago

⚠️ Search for existing issues first ⚠️

Which Operating System are you using?

MacOS

Which version of Auto-GPT are you using?

Stable (branch)

Do you use OpenAI GPT-3 or GPT-4?

GPT-4

Which area covers your issue best?

Prompt

Describe your issue.

If you are using Azure OpenAI service with this particular configuration:

.env:

OPENAI_API_KEY=xxxx TEMPERATURE=0.1 USE_AZURE=True

SMART_LLM_MODEL=gpt-4

FAST_LLM_MODEL=gpt-3.5-turbo

azure.yaml:

azure_api_type: azure azure_api_base: https://xxxx.openai.azure.com/ azure_api_version: 2023-03-15-preview azure_model_map: fast_llm_model_deployment_id: ChatGPT smart_llm_model_deployment_id: GPT4 embedding_model_deployment_id: text-embedding-ada-002

You will receive this error:

File "/Auto-GPT-0.4.0/autogpt/llm/api_manager.py", line 85, in update_cost model = model[:-3] if model.endswith("-v2") else model

AttributeError: 'NoneType' object has no attribute 'endswith'

A possible workaround:

def update_cost(self, prompt_tokens, completion_tokens, model: str):
        """
        Update the total cost, prompt tokens, and completion tokens.

        Args:
        prompt_tokens (int): The number of tokens used in the prompt.
        completion_tokens (int): The number of tokens used in the completion.
        model (str): The model used for the API call.
        """
        self.total_prompt_tokens += prompt_tokens
        self.total_completion_tokens += completion_tokens
        prompt_cost = COSTS.get(model, {}).get("prompt", 0)
        completion_cost = COSTS.get(model, {}).get("completion", 0)
        self.total_cost += (
            prompt_tokens * prompt_cost + completion_tokens * completion_cost
        ) / 1000
        logger.debug(f"Total running cost: ${self.total_cost:.3f}")

Hope it helps.

Upload Activity Log Content

No response

Upload Error Log Content

No response

VectorZhao commented 1 year ago

+1

othunderx commented 1 year ago

A quick fix works for me, This is modified from auto-gpt release v0.4.0, Using azure_api_version=2023-03-15-preview.

Fix null model value if give deployment_id, at line 52 autogpt\llm\api_manager.py: image

Add azure model name, at line 2 autogpt\llm\modelsinfo.py: image

github-actions[bot] commented 1 year ago

This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.

github-actions[bot] commented 12 months ago

This issue was closed automatically because it has been stale for 10 days with no activity.