python - How do I fix TypeError from Llama api call - Stack Overflow

I am running below code from: Llama quick startimport jsonfrom llamaapi import LlamaAPI# Initialize t

I am running below code from: Llama quick start

import json
from llamaapi import LlamaAPI

# Initialize the SDK
llama = LlamaAPI("<your_api_token>")

# Build the API request
api_request_json = {
    "model": "llama3.1-70b",
    "messages": [
        {"role": "user", "content": "What is the weather like in Boston?"},
    ],
    "functions": [
        {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    },
                    "days": {
                        "type": "number",
                        "description": "for how many days ahead you wants the forecast",
                    },
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                },
            },
            "required": ["location", "days"],
        }
    ],
    "stream": False,
    "function_call": "get_current_weather",
}

# Execute the Request
response = llama.run(api_request_json)
print(json.dumps(response.json(), indent=2))

it return the following error:

Traceback (most recent call last):
  File "C:\Users\some_user\OneDrive - Ryder\Projects\Tutorials\Pycharm\AI_tests\llama_api.py", line 39, in <module>
    response = llama.run(api_request_json)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\some_user\myenv\Lib\site-packages\llamaapi\llamaapi.py", line 67, in run
    return self.run_sync(api_request_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\some_user\myenv\Lib\site-packages\llamaapi\llamaapi.py", line 53, in run_sync
    raise Exception(f"POST {response.status_code} {response.json()['detail']}")
                                                   ~~~~~~~~~~~~~~~^^^^^^^^^^
TypeError: list indices must be integers or slices, not str

What is the fix here?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745042177a4607875.html

相关推荐

  • python - How do I fix TypeError from Llama api call - Stack Overflow

    I am running below code from: Llama quick startimport jsonfrom llamaapi import LlamaAPI# Initialize t

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信