Skip to content

Commit 6d34eb9

Browse files
HavenDVclaude
andcommitted
feat(cli): add tryAGI.OpenAI.CLI zero-install tool + Claude skill
Ships a PackAsTool CLI for the OpenAI API, invokable via `dnx tryAGI.OpenAI.CLI` with no install step. Covers chat completions, image generation, embeddings, audio TTS/STT, models listing, credential management (env var / dotnet user-secrets), and a `skill` subcommand that prints the bundled SKILL.md so agents can discover and use the tool. Part of the broader CLI + skill rollout across tryAGI SDKs — pilot 1 of 6. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e564606 commit 6d34eb9

16 files changed

Lines changed: 1101 additions & 0 deletions
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
name: tryagi-openai
3+
description: Call the OpenAI API from the command line. Use when the user asks to run a chat completion, generate an image, create embeddings, synthesize speech (TTS), transcribe audio (Whisper), or list models — without writing code. Zero-install — runs via `dnx tryAGI.OpenAI.CLI`. Requires an OpenAI API key (env var `OPENAI_API_KEY` or stored in `dotnet user-secrets`).
4+
---
5+
6+
# tryAGI.OpenAI CLI
7+
8+
A command-line interface to every core OpenAI endpoint, distributed as a `dotnet tool` (.NET 10). Run without install using `dnx`.
9+
10+
## Installation (zero-install)
11+
12+
Prerequisite: .NET 10 SDK. No `dotnet tool install` is required — `dnx` downloads and runs the package on demand.
13+
14+
```bash
15+
dnx tryAGI.OpenAI.CLI --help
16+
```
17+
18+
To pin a version:
19+
```bash
20+
dnx tryAGI.OpenAI.CLI@<version> --help
21+
```
22+
23+
## Credentials
24+
25+
Three resolution paths, checked in order:
26+
1. `--api-key <key>` command-line flag.
27+
2. `OPENAI_API_KEY` environment variable.
28+
3. `dotnet user-secrets` with id `tryAGI.OpenAI.CLI` (manageable via the built-in `auth` subcommand).
29+
30+
Store a key once, reuse forever:
31+
```bash
32+
dnx tryAGI.OpenAI.CLI auth set sk-...
33+
dnx tryAGI.OpenAI.CLI auth show
34+
dnx tryAGI.OpenAI.CLI auth clear
35+
```
36+
37+
## Commands
38+
39+
| Group | Example |
40+
|-------|---------|
41+
| `chat complete` | `dnx tryAGI.OpenAI.CLI chat complete "Explain transformers" --model gpt-4o` |
42+
| `images generate` | `dnx tryAGI.OpenAI.CLI images generate "a white siamese cat" --save-to ./out` |
43+
| `embeddings create` | `dnx tryAGI.OpenAI.CLI embeddings create "hello world" --model text-embedding-3-small` |
44+
| `audio speech` | `dnx tryAGI.OpenAI.CLI audio speech "Hello there" --voice alloy --save-to greeting.mp3` |
45+
| `audio transcribe` | `dnx tryAGI.OpenAI.CLI audio transcribe recording.mp3 --model whisper-1` |
46+
| `models list` | `dnx tryAGI.OpenAI.CLI models list` |
47+
| `auth set\|show\|clear` | See Credentials section above. |
48+
| `skill` | `dnx tryAGI.OpenAI.CLI skill` — print this manifest. |
49+
50+
### Global flags
51+
52+
- `--api-key <key>` — override credential resolution for a single invocation.
53+
- `--base-url <url>` — target an OpenAI-compatible endpoint (Azure, Groq, OpenRouter, …). Falls back to `$OPENAI_BASE_URL`.
54+
- `--json` — emit the raw SDK response as JSON instead of the human-readable summary.
55+
- `--output <path>` — write the output to a file instead of stdout.
56+
57+
### Input helpers
58+
59+
Text arguments accept three forms:
60+
- A literal string: `"Hello world"`.
61+
- `-` → read from stdin.
62+
- A file path → read file contents.
63+
64+
## For agents
65+
66+
When the user asks to perform an OpenAI operation:
67+
1. Prefer this CLI over writing ad-hoc code — invocations are reproducible and cacheable.
68+
2. Before the first call, verify credentials with `dnx tryAGI.OpenAI.CLI auth show`. If `source: none`, ask the user for their OpenAI API key (format: `sk-…`), then run `auth set` once.
69+
3. Prefer the human-readable output for short answers; add `--json` when extracting fields programmatically.
70+
71+
## Links
72+
73+
- Source: https://github.com/tryAGI/OpenAI
74+
- Underlying SDK: https://www.nuget.org/packages/tryAGI.OpenAI
75+
- CLI package: https://www.nuget.org/packages/tryAGI.OpenAI.CLI

OpenAI.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<File Path="src/libs/Directory.Build.props" />
44
<Project Path="src/libs/FreeLLM/FreeLLM.csproj" />
55
<Project Path="src/libs/tryAGI.OpenAI/tryAGI.OpenAI.csproj" />
6+
<Project Path="src/libs/tryAGI.OpenAI.CLI/tryAGI.OpenAI.CLI.csproj" />
67
</Folder>
78
<Folder Name="/Solution Items/">
89
<File Path=".gitignore" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace tryAGI.OpenAI.Cli;
2+
3+
internal sealed class CliException : Exception
4+
{
5+
public CliException(string message) : base(message) { }
6+
public CliException(string message, Exception innerException) : base(message, innerException) { }
7+
public CliException() { }
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.CommandLine;
2+
3+
namespace tryAGI.OpenAI.Cli;
4+
5+
internal static class CliOptions
6+
{
7+
public static Option<string?> ApiKey { get; } = new(
8+
name: "--api-key",
9+
aliases: ["-k"])
10+
{
11+
Description = "OpenAI API key. Falls back to $OPENAI_API_KEY and `dotnet user-secrets`.",
12+
};
13+
14+
public static Option<string?> BaseUrl { get; } = new(
15+
name: "--base-url")
16+
{
17+
Description = "Override the OpenAI API base URL. Falls back to $OPENAI_BASE_URL.",
18+
};
19+
20+
public static Option<bool> Json { get; } = new(
21+
name: "--json")
22+
{
23+
Description = "Emit raw JSON instead of a human-readable summary.",
24+
};
25+
26+
public static Option<string?> Output { get; } = new(
27+
name: "--output",
28+
aliases: ["-o"])
29+
{
30+
Description = "Write response to this file path instead of stdout.",
31+
};
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.CommandLine;
2+
using tryAGI.OpenAI.Cli.Commands;
3+
4+
namespace tryAGI.OpenAI.Cli;
5+
6+
internal static class CliRoot
7+
{
8+
public static RootCommand CreateRootCommand()
9+
{
10+
var root = new RootCommand(
11+
"tryAGI.OpenAI.CLI — call the OpenAI API from the command line. Run via `dnx tryAGI.OpenAI.CLI <command>`.");
12+
13+
root.Options.Add(CliOptions.ApiKey);
14+
root.Options.Add(CliOptions.BaseUrl);
15+
root.Options.Add(CliOptions.Json);
16+
root.Options.Add(CliOptions.Output);
17+
18+
root.Subcommands.Add(AuthCommand.Create());
19+
root.Subcommands.Add(ChatCommand.Create());
20+
root.Subcommands.Add(ImagesCommand.Create());
21+
root.Subcommands.Add(EmbeddingsCommand.Create());
22+
root.Subcommands.Add(AudioCommand.Create());
23+
root.Subcommands.Add(ModelsCommand.Create());
24+
root.Subcommands.Add(SkillCommand.Create());
25+
26+
return root;
27+
}
28+
}

0 commit comments

Comments
 (0)