You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Token usage normalization: Workers AI responses might include either `{ usage: { prompt_tokens, completion_tokens, total_tokens } }` or `{ usage: { input_tokens, output_tokens, total_tokens } }`. The SDK maps both to `{ input, output, total }`.
177
-
178
-
## Supported Models
179
-
180
-
Use full Workers AI model IDs in your LaunchDarkly AI configurations, for example:
181
-
182
-
-`@cf/meta/llama-3.3-70b-instruct-fp8-fast`
183
-
-`@cf/openai/gpt-oss-120b`
184
-
-`@cf/mistralai/mistral-7b-instruct-v0.1`
84
+
Notes:
85
+
- Templates use Mustache. Variables you pass plus the LD context via `{{ldctx.*}}` are available.
86
+
- Parameter names are normalized when mapping to Workers AI (e.g., `maxTokens`/`maxtokens` → `max_tokens`, `topP`/`topp` → `top_p`, `topK`/`topk` → `top_k`).
185
87
186
-
See the Workers AI model catalog for more options: [Cloudflare Workers AI Models](https://developers.cloudflare.com/workers-ai/models/).
187
-
188
-
## Roles and messages
189
-
190
-
Supported roles in `messages` are `system`, `user`, and `assistant`. Example:
const research =awaitaiClient.agent('research_agent', ctx, { enabled: true, instructions: 'You are a research assistant for {{topic}}.' }, { topic: 'climate change' });
207
-
208
-
if (research.enabled) {
209
-
const wc =research.toWorkersAI(env.AI);
210
-
const res =awaitenv.AI.run(wc.model, wc);
211
-
research.tracker.trackSuccess();
212
-
}
213
-
214
-
const agents =awaitaiClient.agents([
215
-
{ key: 'research_agent', defaultValue: { enabled: true, instructions: 'You are a research assistant.' }, variables: { topic: 'climate change' } },
216
-
{ key: 'writing_agent', defaultValue: { enabled: true, instructions: 'You are a writing assistant.' }, variables: { style: 'academic' } },
1.**Initialize Clients**: Creates LaunchDarkly and AI clients
193
191
2.**Get AI Config**: Retrieves `joke-ai-config` from LaunchDarkly with variables `{ joke_type, topic_section }`
194
192
3.**Variable Interpolation**: Fills `{{joke_type}}` and `{{topic_section}}` in messages
195
-
4.**Call AI Model**: Uses `env.AI.run(wc.model, wc)` to run the model
193
+
4.**Call AI Model**: Map to Workers AI via `config.toWorkersAI(env.AI)` and run with metrics using `await config.tracker.trackWorkersAIMetrics(() => env.AI.run(wc.model, wc))`
0 commit comments