22import asyncio
33from enum import Enum
44
5- from coagent .agents import ChatAgent , confirm , RunContext , tool
5+ from coagent .agents import ChatAgent , confirm , tool
66from coagent .agents .messages import ChatMessage
77from coagent .core import idle_loop , new , set_stderr_logger
88from coagent .runtimes import NATSRuntime
@@ -19,15 +19,6 @@ class Language(str, Enum):
1919 de = "de"
2020
2121
22- class Task (str , Enum ):
23- unknown = ""
24- text_generation = "text-generation"
25- text_to_image = "text-to-image"
26- image_to_image = "image-to-image"
27- text_to_speech = "text-to-speech"
28- conversational = "conversational"
29-
30-
3122class CSGHub (ChatAgent ):
3223 """An agent that help users deal with tasks related to models."""
3324
@@ -37,41 +28,33 @@ class CSGHub(ChatAgent):
3728 @confirm ("About to search model {name}, are you sure?" )
3829 async def search_model (
3930 self ,
40- ctx : RunContext ,
4131 name : str = Field (description = "The name of the model" ),
4232 language : Language = Field (description = "The language that the model supports" ),
43- task : Task = Field (description = "The task that the model supports" ),
33+ limit : int = Field (
34+ default = 10 , description = "The maximum number of models to return"
35+ ),
4436 ) -> str | ChatMessage :
4537 """Search models by the given name and language."""
46- print (f"RunContext: { ctx } " )
47-
4838 params = dict ()
4939 if name :
5040 params ["search" ] = name
5141 if language :
5242 params ["language" ] = language
53- if task :
54- params ["task " ] = task
43+ if limit :
44+ params ["per " ] = limit
5545
5646 async with httpx .AsyncClient () as client :
5747 resp = await client .get (
58- "https://hub.opencsg-stg .com/api/v1/models" ,
48+ "https://hub.opencsg.com/api/v1/models" ,
5949 params = params ,
6050 )
51+ if resp .status_code != 200 :
52+ return f"Error: { resp .text } "
6153 models = resp .json ()["data" ]
6254 if not models :
6355 return "Sorry, no models found."
6456 return ", " .join ([m ["name" ] for m in models ])
6557
66- @tool
67- async def upload_model (
68- self ,
69- name : str = Field (description = "The name of the model" ),
70- addr : str = Field (description = "The address to upload the model" ),
71- ) -> str :
72- """Upload the model to the given address."""
73- return "Success"
74-
7558
7659async def main (name : str ):
7760 async with NATSRuntime .from_servers () as runtime :
0 commit comments