Skip to content

Commit 77a57de

Browse files
committed
Update examples
1 parent 17673a2 commit 77a57de

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

examples/opencsg/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export AZURE_API_KEY=<YOUR API KEY>
4040
python examples/opencsg/csghub.py team1.csghub
4141
```
4242

43-
Then search in the client terminal and you will get a professional answer from CSGHub:
43+
Then search in the client terminal, then you will get a professional answer from CSGHub:
4444

4545
```bash
4646
python examples/rich_client.py opencsg

examples/opencsg/csghub.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import asyncio
33
from enum import Enum
44

5-
from coagent.agents import ChatAgent, confirm, RunContext, tool
5+
from coagent.agents import ChatAgent, confirm, tool
66
from coagent.agents.messages import ChatMessage
77
from coagent.core import idle_loop, new, set_stderr_logger
88
from 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-
3122
class 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

7659
async def main(name: str):
7760
async with NATSRuntime.from_servers() as runtime:

examples/opencsg/dataflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ async def search_dataset(
2121
"""Search datasets by the given name."""
2222
async with httpx.AsyncClient() as client:
2323
resp = await client.get(
24-
"https://hub.opencsg-stg.com/api/v1/datasets",
24+
"https://hub.opencsg.com/api/v1/datasets",
2525
params=dict(search=name),
2626
)
27+
if resp.status_code != 200:
28+
return f"Error: {resp.text}"
2729
datasets = resp.json()["data"]
2830
if not datasets:
2931
return "Sorry, no datasets found."

0 commit comments

Comments
 (0)