Open dekacypher opened 1 year ago
Taking a look, will add some more docs as well @dekacypher
AttributeError Traceback (most recent call last) [/Users/dekahalane/superagent-py/test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/test.ipynb) Cell 1 line 6 [2](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=1) from superagent.client import Superagent [4](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=3) client = Superagent(token="REMOVED FOR DEBUGGING", base_url="https://api.beta.superagent.sh/") ----> [6](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=5) agent = client.agents.create(request={ [7](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=6) "name": "My Agent", [8](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=7) "description": "My awesome agent", [9](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=8) "isActive": True, [10](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=9) "llmModel": "GPT_4_0613" [11](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=10) }) [13](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=12) output = client.agent.invoke( [14](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=13) agent_id=agent.data.id, [15](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=14) input="Hi there!", [16](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=15) enable_streaming=False, [17](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=16) session_id="123" [18](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=17) ) [20](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=19) print("Received response from superagent", agent.data) AttributeError: 'Superagent' object has no attribute 'agents'
I can't find the documentation to fix this error, I've tried both removing the
agents
fromclient.agents.create
and just thes
as I thought it might be a typo but then it throws anInternalServerError
You should use client.agent.create
instead of client.agents.create
@dekacypher.
Here is an example that's working for me:
import os
from superagent.client import Superagent
client = Superagent(token=os.environ['SUPERAGENT_TOKEN'],
base_url="https://api.beta.superagent.sh")
def run():
agent = client.agent.create(
request={
"name": "test",
"description": "test",
"isActive": True,
"llmModel": "GPT_4_0613",
"prompt": "Answer in german"
})
print(agent)
if __name__ == "__main__":
run()
Response is the following:
success=True data=PrismaModelsAgent(id='8492ce9c-8482-4ee3-883b-e8d7144741b2', name='test', avatar=None, initial_message=None, description='test', is_active=True, created_at=datetime.datetime(2023, 11, 8, 11, 11, 53, 156000, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2023, 11, 8, 11, 11, 53, 156000, tzinfo=datetime.timezone.utc), llms=[], llm_model=<LlmModel.GPT_4_0613: 'GPT_4_0613'>, prompt='Answer in german', api_user_id='80ccb769-91a1-4200-92fd-45549e9c21d7', api_user=None, datasources=[], tools=[], workflow_steps=None)
Hi, thanks for the reply. However I still get the same Internal Server Error
earlier when i tried that:
{
"name": "ApiError",
"message": "status_code: 500, body: Internal Server Error",
"stack": "---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File /opt/homebrew/lib/python3.11/site-packages/superagent/resources/agent/client.py:70, in AgentClient.create(self, request)
69 try:
---> 70 _response_json = _response.json()
71 except JSONDecodeError:
File /opt/homebrew/lib/python3.11/site-packages/httpx/_models.py:761, in Response.json(self, **kwargs)
760 def json(self, **kwargs: typing.Any) -> typing.Any:
--> 761 return jsonlib.loads(self.content, **kwargs)
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 \"\"\"Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 \"\"\"
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError(\"Expecting value\", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
ApiError Traceback (most recent call last)
/Users/dekahalane/superagent-py/test.ipynb Cell 1 line 2
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=17'>18</a> print(agent)
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=20'>21</a> if __name__ == \"__main__\":
---> <a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=21'>22</a> run()
/Users/dekahalane/superagent-py/test.ipynb Cell 1 line 9
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=7'>8</a> def run():
----> <a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=8'>9</a> agent = client.agent.create(
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=9'>10</a> request={
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=10'>11</a> \"name\": \"test\",
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=11'>12</a> \"description\": \"test\",
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=12'>13</a> \"isActive\": True,
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=13'>14</a> \"llmModel\": \"GPT_4_0613\",
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=14'>15</a> \"prompt\": \"Answer in german\"
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=15'>16</a> })
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W0sZmlsZQ%3D%3D?line=17'>18</a> print(agent)
File /opt/homebrew/lib/python3.11/site-packages/superagent/resources/agent/client.py:72, in AgentClient.create(self, request)
70 _response_json = _response.json()
71 except JSONDecodeError:
---> 72 raise ApiError(status_code=_response.status_code, body=_response.text)
73 raise ApiError(status_code=_response.status_code, body=_response_json)
ApiError: status_code: 500, body: Internal Server Error"
}
@dekacypher try this, works for me:
import os
from superagent.client import Superagent
client = Superagent(token=os.environ['SUPERAGENT_TOKEN'],
base_url="https://api.beta.superagent.sh")
def run():
agent = client.agent.create(
request={
"name": "test",
"description": "test",
"isActive": True,
"llmModel": "GPT_4_0613",
"prompt": "Answer in german"
})
print(agent)
if __name__ == "__main__":
run()
What's the difference in this? I tried it and got the same error
?
Please Send me the agent ID you are using
@dekacypher did you get it working? If not, mind sharing your code implementation?
No, i did not get it working. Heres the code, and I only have the token, not the agent-ID:
import os
from superagent.client import Superagent
client = Superagent(token=token,
base_url="https://api.beta.superagent.sh")
def run():
agent = client.agent.create(
request={
"name": "test",
"description": "test",
"isActive": True,
"llmModel": "GPT_4_0613",
"prompt": "Answer in german"
})
print(agent)
if __name__ == "__main__":
run()
@dekacypher I see the issue now. You need to configure the LLM object as well. E.g:
import os
from superagent.client import Superagent
client = Superagent(token=os.environ['SUPERAGENT_TOKEN'],
base_url="https://api.beta.superagent.sh")
def run():
llm = client.llm.create(request={
"provider": "OPENAI",
"apiKey": os.environ["OPENAI_API_KEY"]
})
agent = client.agent.create(
request={
"name": "test",
"description": "test",
"isActive": True,
"llmModel": "GPT_4_0613",
"prompt": "Answer in german"
})
client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id)
print(agent)
if __name__ == "__main__":
run()
When i first tried the code i got a [python/httpx/asyncio: httpx.RemoteProtocolError: Server disconnected without sending a response](https://stackoverflow.com/questions/71138509/python-httpx-asyncio-httpx-remoteprotocolerror-server-disconnected-without-sen)
however i can't find the traceback again as I've ran the code multiple times. However heres the most recent traceback:
{
"name": "ApiError",
"message": "status_code: 500, body: Internal Server Error",
"stack": "---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File ~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:66, in LlmClient.create(self, request)
65 try:
---> 66 _response_json = _response.json()
67 except JSONDecodeError:
File ~/superagent-py/super/lib/python3.11/site-packages/httpx/_models.py:761, in Response.json(self, **kwargs)
760 def json(self, **kwargs: typing.Any) -> typing.Any:
--> 761 return jsonlib.loads(self.content, **kwargs)
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 \"\"\"Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 \"\"\"
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
File /opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError(\"Expecting value\", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
ApiError Traceback (most recent call last)
/Users/dekahalane/superagent-py/test.ipynb Cell 3 line 3
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=27'>28</a> print(agent)
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=30'>31</a> if __name__ == \"__main__\":
---> <a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=31'>32</a> run()
/Users/dekahalane/superagent-py/test.ipynb Cell 3 line 1
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=11'>12</a> def run():
---> <a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=12'>13</a> llm = client.llm.create(request={
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=13'>14</a> \"provider\": \"OPENAI\",
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=14'>15</a> \"apiKey\": os.environ['OPENAI_API_KEY']
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=15'>16</a> })
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=16'>17</a> agent = client.agent.create(
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=17'>18</a> request={
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=18'>19</a> \"name\": \"test\",
(...)
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=22'>23</a> \"prompt\": \"Answer in german\"
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=23'>24</a> })
<a href='vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=25'>26</a> client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id)
File ~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:68, in LlmClient.create(self, request)
66 _response_json = _response.json()
67 except JSONDecodeError:
---> 68 raise ApiError(status_code=_response.status_code, body=_response.text)
69 raise ApiError(status_code=_response.status_code, body=_response_json)
ApiError: status_code: 500, body: Internal Server Error"
}
@dekacypher can you try again using the latest version of the SDK?
Yes, I've just updated it.
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File [~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:66](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:66), in LlmClient.create(self, request)
65 try:
---> 66 _response_json = _response.json()
67 except JSONDecodeError:
File [~/superagent-py/super/lib/python3.11/site-packages/httpx/_models.py:761](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/~/superagent-py/super/lib/python3.11/site-packages/httpx/_models.py:761), in Response.json(self, **kwargs)
760 def json(self, **kwargs: typing.Any) -> typing.Any:
--> 761 return jsonlib.loads(self.content, **kwargs)
File [/opt/homebrew/Cellar/python](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Cellar/python)@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
File [/opt/homebrew/Cellar/python](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Cellar/python)@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 """Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
File [/opt/homebrew/Cellar/python](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Cellar/python)@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
ApiError Traceback (most recent call last)
[/Users/dekahalane/superagent-py/test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/test.ipynb) Cell 3 line 3
[28](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=27) print(agent)
[31](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=30) if __name__ == "__main__":
---> [32](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=31) run()
[/Users/dekahalane/superagent-py/test.ipynb](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/test.ipynb) Cell 3 line 1
[12](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=11) def run():
---> [13](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=12) llm = client.llm.create(request={
[14](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=13) "provider": "OPENAI",
[15](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=14) "apiKey":'HIDDEN'
[16](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=15) })
[17](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=16) agent = client.agent.create(
[18](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=17) request={
[19](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=18) "name": "test",
(...)
[23](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=22) "prompt": "Answer in german"
[24](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=23) })
[26](vscode-notebook-cell:/Users/dekahalane/superagent-py/test.ipynb#W2sZmlsZQ%3D%3D?line=25) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id)
File [~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:68](https://file+.vscode-resource.vscode-cdn.net/Users/dekahalane/superagent-py/~/superagent-py/super/lib/python3.11/site-packages/superagent/resources/llm/client.py:68), in LlmClient.create(self, request)
66 _response_json = _response.json()
67 except JSONDecodeError:
---> 68 raise ApiError(status_code=_response.status_code, body=_response.text)
69 raise ApiError(status_code=_response.status_code, body=_response_json)
ApiError: status_code: 500, body: Internal Server Error
Can you paste the code you are running plz?
It's the same code you gave me
I can't find the documentation to fix this error, I've tried both removing the
agents
fromclient.agents.create
and just thes
as I thought it might be a typo but then it throws anInternalServerError