Я пытаюсь разработать инструмент, который агент (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
AttributeError: объект «NoneType» не имеет атрибута «get» в запросе от AI Tools. ⇐ Python
Программы на Python
1762358229
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()
Подробнее здесь: [url]https://stackoverflow.com/questions/79810291/attributeerror-nonetype-object-has-no-attribute-get-in-request-from-ai-tool[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия