AttributeError: объект «NoneType» не имеет атрибута «get» в запросе от AI Tools.Python

Программы на Python
Ответить
Anonymous
 AttributeError: объект «NoneType» не имеет атрибута «get» в запросе от AI Tools.

Сообщение Anonymous »

Я пытаюсь разработать инструмент, который агент (CodeAgent) будет вызывать при вводе пользователем данных (подсказка) в Gradio.
Этот инструмент будет внутренне вызывать REST API для получения результатов.
Я получаю сообщение об ошибке:
AttributeError: 'NoneType' object has no attribute 'get'

Код:
import gradio as gr
import requests
from smolagents import tool
from smolagents import CodeAgent, InferenceClientModel, tool

@tool
def getHelloName(input:str)-> str:
"""
This tool returns the hello name

Args:
input: A search term
"""

url = f"http://localhost:9100/v3/rest/helloWorld/{input}"

# case when there is a response from the API
try:

response = requests.get(url)
if response.status_code == 200: # excpected, okay status code
# parsing status code
helloName = response.json()['message']
return helloName
else:
# in case of an unfavorable status code
return "Name could not be fetched"
except requests.exceptions.RequestException as e:
return "Exception...Name could not be fetched"

def getHelloNameFn(message, history)-> str:
agent = CodeAgent(tools=[getHelloName], model=InferenceClientModel())
result = agent.run(message)
print(result)

gr.ChatInterface(
fn=getHelloNameFn,
type="messages" #Always set type="messages" in gr.ChatInterface.
).launch()



Подробнее здесь: https://stackoverflow.com/questions/798 ... om-ai-tool
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»